add test
This commit is contained in:
21
test/lib.nix
Normal file
21
test/lib.nix
Normal file
@@ -0,0 +1,21 @@
|
||||
# tests/lib.nix
|
||||
# based on 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
|
||||
21
test/test.nix
Normal file
21
test/test.nix
Normal file
@@ -0,0 +1,21 @@
|
||||
# ./tests/hello-world-server.nix
|
||||
(import ./lib.nix) {
|
||||
name = "from-nixos";
|
||||
nodes = {
|
||||
# `self` here is set by using specialArgs in `lib.nix`
|
||||
node1 = { self, pkgs, ... }: {
|
||||
imports = [ self.nixosModules.zineshop ];
|
||||
|
||||
services.zineshop.enable = true;
|
||||
environment.systemPackages = [ pkgs.curl ];
|
||||
};
|
||||
};
|
||||
|
||||
testScript = ''
|
||||
start_all() # wait for our service to start
|
||||
node1.wait_for_unit("zineshop.service")
|
||||
output = node1.succeed("curl localhost:8080")
|
||||
# Check if our webserver returns the expected result
|
||||
assert "Zine Shop" in output, f"'{output}' does not contain 'Zine Shop'"
|
||||
'';
|
||||
}
|
||||
Reference in New Issue
Block a user