aboutsummaryrefslogtreecommitdiffstats
path: root/tests/by-name/sh/sharkey-cpu/test.nix
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/sharkey-cpu/test.nix
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/sharkey-cpu/test.nix')
-rw-r--r--tests/by-name/sh/sharkey-cpu/test.nix57
1 files changed, 23 insertions, 34 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)
'';
}