-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from mlabs-haskell/avnik/tests
Prototype of tests
- Loading branch information
Showing
8 changed files
with
213 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
{inputs, ...}: { | ||
imports = [ | ||
./testing.nix | ||
]; | ||
perSystem = { | ||
pkgs, | ||
config, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
{ | ||
writeShellApplication, | ||
lib, | ||
tests, | ||
stdenv, | ||
... | ||
}: | ||
writeShellApplication { | ||
name = "run-test"; | ||
|
||
runtimeInputs = []; | ||
|
||
text = '' | ||
cmd_name=$(basename "$0") | ||
help() { | ||
echo " build and run a test" | ||
echo | ||
echo " usage:" | ||
echo " $cmd_name <name>" | ||
echo " $cmd_name <name> --interactive" | ||
echo " $cmd_name -s <system> <name>" | ||
echo | ||
echo " arguments:" | ||
echo " <name>" | ||
echo | ||
echo " options:" | ||
echo " -h --help show this screen." | ||
echo " -l --list show available tests." | ||
echo " -s --system specify the target platform [default: ${stdenv.system}]." | ||
echo " -i --interactive run the test interactively." | ||
echo | ||
} | ||
list() { | ||
echo " list of available tests:" | ||
echo | ||
echo "${lib.concatMapStrings (s: " - " + s + "\n") (lib.mapAttrsToList (_: test: test.name) tests)}" | ||
} | ||
args=$(getopt -o lihs: --long list,interactive,help,system: -n 'tests' -- "$@") | ||
eval set -- "$args" | ||
system="${stdenv.system}" | ||
driver_args=() | ||
while [ $# -gt 0 ]; do | ||
case "$1" in | ||
-i | --interactive) driver_args+=("--interactive"); shift;; | ||
-s | --system) system="$2"; shift 2;; | ||
-h | --help) help; exit 0;; | ||
-l | --list) list; exit 0;; | ||
-- ) shift; break;; | ||
* ) break;; | ||
esac | ||
done | ||
if [ $# -eq 0 ]; then | ||
help | ||
exit 1 | ||
fi | ||
name="$1" | ||
shift | ||
# build/run the test driver, passing any remaining arguments | ||
nix run ".#checks.$system.testing-$name.driver" -- "''${driver_args[@]}" | ||
''; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
{ | ||
lib, | ||
inputs, | ||
config, | ||
... | ||
}: let | ||
inherit (lib) mkOption types mapAttrs' nameValuePair; | ||
inherit (config.flake) nixosModules; | ||
in { | ||
perSystem = { | ||
config, | ||
lib, | ||
system, | ||
pkgs, | ||
... | ||
}: let | ||
cfg = config.cardanoNix; | ||
in { | ||
options.cardanoNix = { | ||
tests = mkOption { | ||
type = types.lazyAttrsOf (types.submodule ({config, ...}: { | ||
options = { | ||
name = mkOption { | ||
type = types.str; | ||
default = config._module.args.name; | ||
internal = true; | ||
}; | ||
systems = mkOption { | ||
type = types.listOf types.str; | ||
}; | ||
module = mkOption { | ||
type = types.deferredModule; | ||
}; | ||
documentation = mkOption { | ||
type = types.bool; | ||
default = false; | ||
}; | ||
specialArgs = mkOption { | ||
type = types.attrsOf types.anything; | ||
default = {}; | ||
}; | ||
}; | ||
})); | ||
}; | ||
runTestScript = mkOption { | ||
type = types.package; | ||
default = pkgs.callPackage ./run-test.nix {inherit (cfg) tests;}; | ||
description = "A convenience script to run tests"; | ||
}; | ||
_nixosLib = mkOption { | ||
type = types.anything; | ||
default = import (inputs.nixpkgs.outPath + "/nixos/lib") {}; | ||
internal = true; | ||
}; | ||
_mkCheckFromTest = mkOption { | ||
type = types.functionTo types.package; | ||
internal = true; | ||
default = test: | ||
(cfg._nixosLib.runTest { | ||
hostPkgs = pkgs; | ||
|
||
# false by default, it speeds up evaluation by skipping docs generation | ||
defaults.documentation.enable = test.documentation; | ||
|
||
node = { | ||
inherit (test) specialArgs; | ||
}; | ||
|
||
# import all of our flake nixos modules by default | ||
defaults.imports = [ | ||
nixosModules.default | ||
]; | ||
|
||
# import the test module | ||
imports = [test.module]; | ||
}) | ||
.config | ||
.result; | ||
}; | ||
}; | ||
|
||
config = { | ||
checks = | ||
mapAttrs' | ||
(name: test: nameValuePair "testing-${test.name}" (cfg._mkCheckFromTest test)) | ||
(lib.filterAttrs | ||
(_: v: lib.elem system v.systems) | ||
cfg.tests); | ||
|
||
apps.run-test.program = lib.getExe cfg.runTestScript; | ||
|
||
devshells.default.commands = [ | ||
{ | ||
name = "run-test"; | ||
category = "testing"; | ||
help = "Run tests"; | ||
command = "${lib.getExe cfg.runTestScript} $@"; | ||
} | ||
]; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{lib, ...}: let | ||
lib' = import ./functions.nix lib; | ||
in { | ||
flake.lib = lib'; | ||
config.flake.lib = lib'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
{config, ...}: { | ||
imports = [ | ||
]; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
cardanoNix.tests = { | ||
dummy = { | ||
systems = ["x86_64-linux"]; | ||
|
||
module = { | ||
name = "cli-test"; | ||
|
||
nodes = { | ||
machine = { | ||
virtualisation = { | ||
cores = 2; | ||
memorySize = 1024; | ||
writableStore = true; | ||
}; | ||
cardano-ecosystem.cli.enable = true; | ||
}; | ||
}; | ||
|
||
testScript = '' | ||
# FIXME: check for cardano cli, not git | ||
machine.succeed("git --version") | ||
''; | ||
}; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
perSystem = _: { | ||
imports = [ | ||
./cardano-cli.nix | ||
]; | ||
}; | ||
} |