Start of tests

release
Matthew Salerno 1 year ago
parent 0fa7a36dcb
commit e8b630b23d

@ -5,9 +5,24 @@
*/ */
{ {
description = "A wireguard network creation tool"; description = "A wireguard network creation tool";
outputs = { self, ... }: outputs = { self, nixpkgs, ... }:
let
forAllSystems = nixpkgs.lib.genAttrs [ "x86_64-linux" "aarch64-linux" ];
in
{ {
wnlib = import ./lib.nix; wnlib = import ./lib.nix;
nixosModules.default = import ./wire.nix; nixosModules.default = import ./wire.nix;
checks = forAllSystems (system:
let
checkArgs = {
# reference to nixpkgs for the current system
pkgs = nixpkgs.legacyPackages.${system};
# this gives us a reference to our flake but also all flake inputs
inherit self;
};
in {
# import our test
null = import ./tests/null.nix checkArgs;
});
}; };
} }

@ -0,0 +1,21 @@
# tests/lib.nix
# see https://blog.thalheim.io/2023/01/08/how-to-use-nixos-testing-framework-with-flakes/
# The first argument to this function is the test module itself
test:
# These arguments are provided by `flake.nix` on import, see checkArgs
{ pkgs, self}:
let
inherit (pkgs) lib;
# this imports the nixos library that contains our testing framework
nixos-lib = import (pkgs.path + "/nixos/lib") {};
in
(nixos-lib.runTest {
hostPkgs = pkgs;
# This speeds up the evaluation by skipping evaluating documentation (optional)
defaults.documentation.enable = lib.mkDefault false;
# This makes `self` available in the NixOS configuration of our virtual machines.
# This is useful for referencing modules or packages from your own flake
# as well as importing from other flakes.
node.specialArgs = { inherit self; };
imports = [ test ];
}).config.result

@ -0,0 +1,22 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
(import ./lib.nix) {
name = "Null test, should always pass";
nodes = {
# `self` here is set by using specialArgs in `lib.nix`
node1 = { self, pkgs, ... }: {
};
};
# This is the test code that will check if our service is running correctly:
testScript = ''
start_all()
# wait for our service to start
node1.wait_for_unit("hello-world-server")
output = node1.succeed("echo Hello world")
# Check if our webserver returns the expected result
assert "Hello world" in output, f"'{output}' does not contain 'Hello world'"
'';
}
Loading…
Cancel
Save