diff --git a/flake.nix b/flake.nix index 6a21c25..3059215 100644 --- a/flake.nix +++ b/flake.nix @@ -24,11 +24,11 @@ playit-cli = pkgs.callPackage ./nix/package.nix { inherit (inputs) playit-agent-source; }; default = config.packages.playit-cli; docs = pkgs.callPackage ./nix/docs.nix { }; - # mock = pkgs.callPackage ./test/mock-playit-cli { }; + # mock = pkgs.callPackage ./test/mock-playit-cli.nix { }; }; checks = { - test-services-playit = pkgs.callPackage ./test/test-services-playit.nix { }; + test-services-playit = import ./test/test-services-playit.nix { inherit pkgs; }; }; }; diff --git a/nix/nixos-module.nix b/nix/nixos-module.nix index 3274a56..f13b4c8 100644 --- a/nix/nixos-module.nix +++ b/nix/nixos-module.nix @@ -10,7 +10,7 @@ in package = lib.mkOption { type = lib.types.package; - description = "playit-cli binary to run"; + description = "playit binary to run"; }; secretPath = lib.mkOption { @@ -54,7 +54,7 @@ in after = [ "network.target" "systemd-resolved.service" ]; script = '' - ${lib.getExe cfg.package} --secret_wait --secret_path ${cfg.secretPath} --stdout start + ${lib.getExe cfg.package} --stdout --secret_wait --secret_path ${cfg.secretPath} start ''; serviceConfig = { diff --git a/nix/package.nix b/nix/package.nix index fcbd5e8..1196254 100644 --- a/nix/package.nix +++ b/nix/package.nix @@ -15,5 +15,6 @@ rustPlatform.buildRustPackage { }; strictDeps = true; + # Requires internet access doCheck = false; } diff --git a/test/mock-playit-cli.nix b/test/mock-playit-cli.nix new file mode 100644 index 0000000..e9f0045 --- /dev/null +++ b/test/mock-playit-cli.nix @@ -0,0 +1,11 @@ +{ runCommandLocal, simple-http-server, lib, ... }: +runCommandLocal "mock-playit-cli" +{ + meta.mainProgram = "playit-cli"; +} '' + mkdir -p $out/bin + bin=$out/bin/playit-cli + + echo "${lib.getExe simple-http-server} --port 9213" >> $bin + chmod +x $bin +'' diff --git a/test/mock-playit-cli/default.nix b/test/mock-playit-cli/default.nix deleted file mode 100644 index d917f4a..0000000 --- a/test/mock-playit-cli/default.nix +++ /dev/null @@ -1,15 +0,0 @@ -{ pkgs }: -with pkgs.python3Packages; -buildPythonPackage { - pname = "mock-playit-cli"; - version = "0.0.1"; - format = "pyproject"; - - src = ./.; - - propagatedBuildInputs = [ setuptools ]; - - meta = { - mainProgram = "mock-playit-cli"; - }; -} diff --git a/test/mock-playit-cli/main.py b/test/mock-playit-cli/main.py deleted file mode 100644 index 1153664..0000000 --- a/test/mock-playit-cli/main.py +++ /dev/null @@ -1,32 +0,0 @@ -import argparse -import json -import re -import signal -import sys -import time - - -def signal_handler(signal, frame): - sys.exit(0) - -signal.signal(signal.SIGINT, signal_handler) - - -def main(): - parser = argparse.ArgumentParser("Mock playit-cli") - parser.add_argument("--secret_wait", action="store_true", required=False) - parser.add_argument("--secret_path", type=str, required=True) - - subparsers = parser.add_subparsers() - run_subparser = subparsers.add_parser("run") - run_subparser.add_argument("mapping_override", type=lambda s: re.split(",", s), nargs='?') - - args = parser.parse_args() - args_dict = vars(args) - - with open("/var/lib/playit/result.json", "w") as file: - json_object = json.dumps(args_dict, indent=4, sort_keys=True) - file.write(json_object) - - while True: - time.sleep(1) diff --git a/test/mock-playit-cli/pyproject.toml b/test/mock-playit-cli/pyproject.toml deleted file mode 100644 index 716e216..0000000 --- a/test/mock-playit-cli/pyproject.toml +++ /dev/null @@ -1,10 +0,0 @@ -[project] -name = "mock-playit-cli" -version = "0.0.1" -requires-python = ">=3.7" - -[project.scripts] -mock-playit-cli = "main:main" - -[build-system] -requires = ["setuptools", "wheel"] \ No newline at end of file diff --git a/test/snapshots/multiple-overrides.json b/test/snapshots/multiple-overrides.json deleted file mode 100644 index dfbb833..0000000 --- a/test/snapshots/multiple-overrides.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "mapping_override": [ - "65dd196c4-5538-4633-98b2-fb26b45787b81=192.168.1.10:8080", - "9bad3ee3-e7b7-49c2-86e7-3ab5558a905a=9000" - ], - "secret_path": "/secret/path", - "secret_wait": true -} \ No newline at end of file diff --git a/test/snapshots/no-overrides.json b/test/snapshots/no-overrides.json deleted file mode 100644 index 9314d24..0000000 --- a/test/snapshots/no-overrides.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "secret_path": "/secret/path", - "secret_wait": true -} \ No newline at end of file diff --git a/test/test-services-playit.nix b/test/test-services-playit.nix index 0fc1ab4..f325c83 100644 --- a/test/test-services-playit.nix +++ b/test/test-services-playit.nix @@ -1,33 +1,21 @@ -{ pkgs, lib, ... }: +{ pkgs, ... }: let - resultFileLocation = "/var/lib/playit/result.json"; - expectedFileLocation = "/var/lib/playit/expected.json"; - - commonConfig = { + commonConfig = { pkgs, ... }: { imports = [ ../nix/nixos-module.nix ]; - services.playit.package = pkgs.callPackage ./mock-playit-cli { }; + services.playit.package = pkgs.callPackage ./mock-playit-cli.nix { }; - environment.systemPackages = [ pkgs.diffutils ]; + environment.systemPackages = [ pkgs.curl ]; }; - withCommonConfig = config: lib.attrsets.recursiveUpdate config commonConfig; + withCommonConfig = config: { + imports = [ commonConfig ]; + inherit config; + }; in pkgs.nixosTest { name = "test-services-playit"; nodes = { machine1 = withCommonConfig { - services.playit = { - enable = true; - secretPath = "/secret/path"; - runOverride = { - "65dd196c4-5538-4633-98b2-fb26b45787b81" = { ip = "192.168.1.10"; port = 8080; }; - "9bad3ee3-e7b7-49c2-86e7-3ab5558a905a".port = 9000; - }; - }; - }; - - - machine2 = withCommonConfig { services.playit = { enable = true; secretPath = "/secret/path"; @@ -38,24 +26,13 @@ pkgs.nixosTest { testScript = '' start_all() - with subtest("multiple-overrides"): - machine1.wait_for_unit("playit.service") - - machine1.wait_for_file("${resultFileLocation}") + with subtest("running"): + machine1.wait_for_unit("network.target") - machine1.copy_from_host("${./snapshots/multiple-overrides.json}", "${expectedFileLocation}") - machine1.succeed("diff ${expectedFileLocation} ${resultFileLocation}") + machine1.wait_for_unit("playit.service") + machine1.wait_for_open_port(9213) + machine1.wait_until_succeeds("curl -I http://localhost:9213 | grep '200 OK'") machine1.shutdown() - - with subtest("no-overrides"): - machine2.wait_for_unit("playit.service") - - machine2.wait_for_file("${resultFileLocation}") - - machine2.copy_from_host("${./snapshots/no-overrides.json}", "${expectedFileLocation}") - machine2.succeed("diff ${expectedFileLocation} ${resultFileLocation}") - - machine2.shutdown() ''; }