-
Notifications
You must be signed in to change notification settings - Fork 36
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
Tests for flake modules #122
Comments
I recently did some work on @roberth Should #79 be closed as duplicate of this? Incidentally, I am unable to comment on #79 because Shane Sveller has me blocked on GitHub. |
For another module project I went with eval tests, not sure if that is best practice though, I wonder if something similar could be used here?: {
pkgs,
lib,
...
}: let
evalSettings = modules: let
eval = lib.evalModules {
specialArgs = {inherit pkgs;};
modules = [./.] ++ (lib.toList modules);
};
in
eval.config.settings;
defaults.rules = [
{
changes = {
compare_to = "refs/heads/main";
paths = [];
};
"if" = "$CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH";
}
{
changes = {
paths = [];
};
"if" = "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH";
}
];
in
lib.pipe {
testJobDefaults = {
expr = evalSettings {
jobs.job-a = {
command = "job-a-cmd";
};
};
expected = {
job-a = {
script = "nix run .#job-a-cmd ";
inherit (defaults) rules;
};
};
};
testJobCommandArgs = {
expr = evalSettings {
jobs.myjob = {
command = "deploy";
commandArgs = ["with" "args"];
settings.environment = "test";
};
};
expected = {
myjob = {
script = "nix run .#deploy 'with' 'args'";
environment = "test";
inherit (defaults) rules;
};
};
};
testJobCustomSettings = {
expr = evalSettings {
jobs.myjob = {
command = "deploy";
settings.environment = "test";
};
};
expected = {
myjob = {
script = "nix run .#deploy ";
environment = "test";
inherit (defaults) rules;
};
};
};
} [
lib.runTests
(lib.generators.toPretty {})
(res: lib.assertMsg (res == "[ ]") res)
] Then in flake-parts integaration I did something like this: config.flake.tests.ci =
withSystem "x86_64-linux" ({pkgs, ...}:
pkgs.callPackage ./test.nix {}); Then I executed via These were purely data tests, so I thought eval was fine. |
Yea. You can go one small step further by supporting |
Has there been any work/discussion regarding tests for flake modules? It would be nice to have a community defined flow for how to create tests for flake modules. Similar like we have tests for nixos modules and home-manager modules.
I think a testing framework or similar for flake-parts could potentially increase the best practices.
Things that could be nice to test:
What do you think?
The text was updated successfully, but these errors were encountered: