aboutsummaryrefslogtreecommitdiffstats
path: root/tests/by-name/sh
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2026-07-18 22:35:46 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2026-07-18 22:35:46 +0200
commitb84c9c7382dc05d1ff5f3bdaf2bac7ce3c332007 (patch)
tree42b64963341fc7e6251e16c68dfbdb4b3be54aa1 /tests/by-name/sh
parentscripts/update_hosts.sh: Use faster `nix copy` and ping hosts after update (diff)
downloadnixos-server-b84c9c7382dc05d1ff5f3bdaf2bac7ce3c332007.zip
tests: Refactor to unify tests and avoid duplicated code
Diffstat (limited to 'tests/by-name/sh')
-rw-r--r--tests/by-name/sh/sharkey-cpu/test.nix57
-rw-r--r--tests/by-name/sh/sharkey/test.nix87
2 files changed, 37 insertions, 107 deletions
diff --git a/tests/by-name/sh/sharkey-cpu/test.nix b/tests/by-name/sh/sharkey-cpu/test.nix
index 47c16ff..d648429 100644
--- a/tests/by-name/sh/sharkey-cpu/test.nix
+++ b/tests/by-name/sh/sharkey-cpu/test.nix
@@ -1,25 +1,12 @@
{
- nixos-lib,
- pkgsUnstable,
- nixpkgs-unstable,
- vhackPackages,
pkgs,
extraModules,
- nixLib,
+ vhack,
...
}:
-nixos-lib.runTest {
- hostPkgs = pkgs; # the Nixpkgs package set used outside the VMs
-
+vhack.runTest {
name = "sharkey-cpu";
- node = {
- specialArgs = {inherit pkgsUnstable extraModules vhackPackages nixpkgs-unstable nixLib;};
-
- # Use the nixpkgs as constructed by the `nixpkgs.*` options
- pkgs = null;
- };
-
nodes = {
server = {config, ...}: {
imports =
@@ -45,12 +32,22 @@ nixos-lib.runTest {
nodejs = pkgs.lib.getExe pkgs.nodejs;
script = pkgs.writeTextFile {
name = "script.js";
- text = ''
- import * as os from 'node:os';
+ text =
+ # js
+ ''
+ import * as os from 'node:os';
+
+ var cpus = os.cpus()
- console.log(os.cpus()[0].model)
- console.log(os.cpus().length)
- '';
+ if (cpus.length != 0) {
+ console.log(cpus[0].model)
+ } else {
+ // Fail?
+ }
+
+ while (true) {
+ }
+ '';
};
in
pkgs.lib.mkForce "${nodejs} ${script}";
@@ -58,24 +55,16 @@ nixos-lib.runTest {
};
};
- testScript = {nodes, ...}:
- /*
- python
- */
+ services = [
+ {server = "sharkey.service";}
+ ];
+
+ testScript = {...}:
+ # Python
''
from time import sleep
- start_all()
-
# Give the service time to run.
sleep(3)
-
- with subtest("All services running"):
- import json
- def all_services_running(host):
- (status, output) = host.systemctl("list-units --state=failed --plain --no-pager --output=json")
- host_failed = json.loads(output)
- assert len(host_failed) == 0, f"Expected zero failing services, but found: {json.dumps(host_failed, indent=4)}"
- all_services_running(server)
'';
}
diff --git a/tests/by-name/sh/sharkey/test.nix b/tests/by-name/sh/sharkey/test.nix
index 0d79cd2..7b6f537 100644
--- a/tests/by-name/sh/sharkey/test.nix
+++ b/tests/by-name/sh/sharkey/test.nix
@@ -1,66 +1,21 @@
{
- nixos-lib,
- pkgsUnstable,
- nixpkgs-unstable,
- vhackPackages,
- pkgs,
extraModules,
- nixLib,
+ vhack,
...
}:
-nixos-lib.runTest {
- hostPkgs = pkgs; # the Nixpkgs package set used outside the VMs
-
+vhack.runTest {
name = "sharkey";
- node = {
- specialArgs = {inherit pkgsUnstable extraModules vhackPackages nixpkgs-unstable nixLib;};
-
- # Use the nixpkgs as constructed by the `nixpkgs.*` options
- pkgs = null;
- };
+ serverDomains = [
+ {server = "sharkey.server";}
+ ];
nodes = {
- acme = {...}: {
- imports = [
- ../../../common/acme/server.nix
- ../../../common/dns/client.nix
- ];
- };
- name_server = {nodes, ...}: {
- imports =
- extraModules
- ++ [
- ../../../common/acme/client.nix
- ../../../common/dns/server.nix
- ];
-
- vhack.dns.zones = {
- "sharkey.server" = {
- SOA = {
- nameServer = "ns";
- adminEmail = "admin@server.com";
- serial = 2025012301;
- };
- useOrigin = false;
-
- A = [
- nodes.server.networking.primaryIPAddress
- ];
- AAAA = [
- nodes.server.networking.primaryIPv6Address
- ];
- };
- };
- };
-
server = {config, ...}: {
imports =
extraModules
++ [
../../../../modules
- ../../../common/acme/client.nix
- ../../../common/dns/client.nix
];
vhack = {
@@ -73,30 +28,16 @@ nixos-lib.runTest {
};
};
- client = {...}: {
- imports = [
- ../../../common/acme/client.nix
- ../../../common/dns/client.nix
- ];
- };
+ client = {...}: {};
};
- testScript = {nodes, ...}: let
- acme = import ../../../common/acme {inherit pkgs;};
- in
- acme.prepare ["server" "client"]
- # Python
- ''
- server.wait_for_unit("sharkey.service")
-
- with subtest("All services running"):
- import json
- def all_services_running(host):
- (status, output) = host.systemctl("list-units --state=failed --plain --no-pager --output=json")
- host_failed = json.loads(output)
- assert len(host_failed) == 0, f"Expected zero failing services, but found: {json.dumps(host_failed, indent=4)}"
- all_services_running(server)
+ services = [
+ {server = "sharkey.service";}
+ ];
- client.wait_until_succeeds("curl --silent https://sharkey.server | grep 'Thank you for using Sharkey!'")
- '';
+ testScript = {...}:
+ # Python
+ ''
+ client.wait_until_succeeds("curl --verbose https://sharkey.server | grep 'Thank you for using Sharkey!'")
+ '';
}