44439e2a81
The result of `import tests.nix {}` is now an attrset of tests. This makes it easier and more efficient to evaluate or build multiple tests in one call to `nix build`. Simplify tests.nix by removing the large module args scope in favor of self-contained scenario module definitions. Add CPU core and memory size defaults to the test configuration to enable building tests without `run-tests.sh`. Add the following top-level args to tests.nix: - `extraScenarios` to provide a nix-level way to define extra scenarios. - `pkgs` to allow building tests with custom pkgs or systems.
66 lines
1.5 KiB
Nix
66 lines
1.5 KiB
Nix
pkgs:
|
|
let
|
|
makeVM = import ./make-test-vm.nix pkgs;
|
|
inherit (pkgs) lib;
|
|
in
|
|
|
|
name: testConfig:
|
|
{
|
|
vm = makeVM {
|
|
name = "nix-bitcoin-${name}";
|
|
|
|
machine = {
|
|
imports = [ testConfig ];
|
|
virtualisation = {
|
|
# Needed because duplicity requires 270 MB of free temp space, regardless of backup size
|
|
diskSize = 1024;
|
|
|
|
# Min. 800 MiB needed to avoid 'out of memory' errors
|
|
memorySize = lib.mkDefault 2048;
|
|
|
|
cores = lib.mkDefault 2;
|
|
};
|
|
};
|
|
|
|
testScript = nodes: let
|
|
cfg = nodes.nodes.machine.config;
|
|
data = {
|
|
data = cfg.test.data;
|
|
tests = cfg.tests;
|
|
};
|
|
dataFile = pkgs.writeText "test-data" (builtins.toJSON data);
|
|
initData = ''
|
|
import json
|
|
|
|
with open("${dataFile}") as f:
|
|
data = json.load(f)
|
|
|
|
enabled_tests = set(test for (test, enabled) in data["tests"].items() if enabled)
|
|
test_data = data["data"]
|
|
'';
|
|
in
|
|
builtins.concatStringsSep "\n\n" [
|
|
initData
|
|
(builtins.readFile ./../tests.py)
|
|
# Don't run tests in interactive mode.
|
|
# is_interactive is set in ../run-tests.sh
|
|
''
|
|
if not "is_interactive" in vars():
|
|
run_tests()
|
|
''
|
|
];
|
|
};
|
|
|
|
container = {
|
|
# The container name has a 11 char length limit
|
|
containers.nb-test = { config, ... }: {
|
|
config = {
|
|
extra = config.config.test.container;
|
|
config = testConfig;
|
|
};
|
|
};
|
|
};
|
|
|
|
config = testConfig;
|
|
}
|