Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add nixostests block type #369

Merged
merged 2 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/local/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 75 additions & 0 deletions src/std/fwlib/blockTypes/nixostests.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
root,
super,
}:
/*
Use the NixosTests Blocktype in order to instrucement nixos
vm-based test inside your reporisory.

Available actions:
- run
- run-vm
- audit-script
- run-vm-+
*/
let
inherit (root) mkCommand actions;
inherit (super) addSelectorFunctor;
in
name: {
__functor = addSelectorFunctor;
inherit name;
type = "nixostests";
actions = {
currentSystem,
fragment,
fragmentRelPath,
target,
inputs,
}: let
pkgs = inputs.nixpkgs.${currentSystem};
in [
(mkCommand currentSystem "run" "run tests in headless vm" [] ''
# ${target.driver}
${target.driver}/bin/nixos-test-driver
'' {})
(mkCommand currentSystem "audit-script" "audit the test script" [pkgs.bat] ''
# ${target.driver}
bat --language py ${target.driver}/test-script
'' {})
(mkCommand currentSystem "run-vm" "run tests interactively in vm" [] ''
# ${target.driverInteractive}
${target.driverInteractive}/bin/nixos-test-driver
'' {})
(mkCommand currentSystem "run-vm+" "run tests with state from last run" [] ''
# ${target.driverInteractive}
${target.driverInteractive}/bin/nixos-test-driver --keep-vm-state
'' {})
(mkCommand currentSystem "iptables+" "setup nat redirect 80->8080 & 443->4433" [pkgs.iptables] ''
sudo iptables \
--table nat \
--insert OUTPUT \
--proto tcp \
--destination 127.0.0.1 \
--dport 443 \
--jump REDIRECT \
--to-ports 4433
sudo iptables \
--table nat \
--insert OUTPUT \
--proto tcp \
--destination 127.0.0.1 \
--dport 80 \
--jump REDIRECT \
--to-ports 8080
'' {})
(mkCommand currentSystem "iptables-" "remove nat redirect 80->8080 & 443->4433" [pkgs.iptables] ''
sudo iptables \
--table nat \
--delete OUTPUT -d 127.0.0.1/32 -p tcp -m tcp --dport 443 -j REDIRECT --to-ports 4433
sudo iptables \
--table nat \
--delete OUTPUT -d 127.0.0.1/32 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080
'' {})
];
}
6 changes: 3 additions & 3 deletions src/tests/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions tests/_snapshots/bt-blocktypes
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,42 @@
name = "nixago";
type = "nixago";
};
nixostests = {
actions = [
{
command = <derivation run>;
description = "run tests in headless vm";
name = "run";
}
{
command = <derivation audit-script>;
description = "audit the test script";
name = "audit-script";
}
{
command = <derivation run-vm>;
description = "run tests interactively in vm";
name = "run-vm";
}
{
command = <derivation run-vm+>;
description = "run tests with state from last run";
name = "run-vm+";
}
{
command = <derivation iptables+>;
description = "setup nat redirect 80->8080 & 443->4433";
name = "iptables+";
}
{
command = <derivation iptables->;
description = "remove nat redirect 80->8080 & 443->4433";
name = "iptables-";
}
];
name = "nixostests";
type = "nixostests";
};
nomad = {
actions = [
{
Expand Down
4 changes: 4 additions & 0 deletions tests/bt-blocktypes/expr.nix
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ in
install = "install";
configFile = "path/to/configFile";
};
nixostests = {
driver = "driver";
driverInteractive = "driverInteractive";
};
microvms = {
config.microvm.runner.foo = "42";
config.microvm.hypervisor = "foo";
Expand Down
Loading