Skip to content

Commit

Permalink
Simplify tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pedorich-n committed Nov 7, 2024
1 parent 3512cab commit 1d1a4df
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 109 deletions.
4 changes: 2 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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; };
};
};

Expand Down
4 changes: 2 additions & 2 deletions nix/nixos-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 = {
Expand Down
1 change: 1 addition & 0 deletions nix/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ rustPlatform.buildRustPackage {
};

strictDeps = true;
# Requires internet access
doCheck = false;
}
11 changes: 11 additions & 0 deletions test/mock-playit-cli.nix
Original file line number Diff line number Diff line change
@@ -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
''
15 changes: 0 additions & 15 deletions test/mock-playit-cli/default.nix

This file was deleted.

32 changes: 0 additions & 32 deletions test/mock-playit-cli/main.py

This file was deleted.

10 changes: 0 additions & 10 deletions test/mock-playit-cli/pyproject.toml

This file was deleted.

8 changes: 0 additions & 8 deletions test/snapshots/multiple-overrides.json

This file was deleted.

4 changes: 0 additions & 4 deletions test/snapshots/no-overrides.json

This file was deleted.

49 changes: 13 additions & 36 deletions test/test-services-playit.nix
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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()
'';
}

0 comments on commit 1d1a4df

Please sign in to comment.