Skip to content

Commit

Permalink
fix tests in lib
Browse files Browse the repository at this point in the history
  • Loading branch information
ibizaman committed Oct 24, 2024
1 parent 39c1627 commit 45352eb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
11 changes: 6 additions & 5 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@ rec {
resultPath = newPath;
};

replaceSecretsScript = { file, resultPath, replacements, user ? null, permissions ? "u=r,g=r,o=" }:
genReplacement = secret:
let
templatePath = resultPath + ".template";

t = { transform ? null, ... }: if isNull transform then x: x else transform;
in
lib.attrsets.nameValuePair (secretName secret.name) ((t secret) "$(cat ${toString secret.source})");

genReplacement = secret:
lib.attrsets.nameValuePair (secretName secret.name) ((t secret) "$(cat ${toString secret.source})");
replaceSecretsScript = { file, resultPath, replacements, user ? null, permissions ? "u=r,g=r,o=" }:
let
templatePath = resultPath + ".template";

# We check that the files containing the secrets have the
# correct permissions for us to read them in this separate
Expand Down
22 changes: 12 additions & 10 deletions test/modules/lib.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{ pkgs, lib, ... }:
let
shblib = pkgs.callPackage ../../lib {};

inherit (lib) nameValuePair;
in
{
# Tests that withReplacements can:
Expand Down Expand Up @@ -79,15 +81,15 @@ in
testLibGetReplacements = {
expected =
let
secrets = root: {
"%SECRET_${root}B%" = "$(cat /path/B)";
"%SECRET_${root}C%" = "prefix-$(cat /path/C)-suffix";
};
secrets = root: [
(nameValuePair "%SECRET_${root}B%" "$(cat /path/B)")
(nameValuePair "%SECRET_${root}C%" "prefix-$(cat /path/C)-suffix")
];
in
(secrets "") //
(secrets "NESTEDATTR_") //
(secrets "NESTEDLIST_0_") //
(secrets "DOUBLENESTEDLIST_0_N_");
(secrets "") ++
(secrets "DOUBLENESTEDLIST_0_N_") ++
(secrets "NESTEDATTR_") ++
(secrets "NESTEDLIST_0_");
expr =
let
item = {
Expand All @@ -99,13 +101,13 @@ in
c.other = "other";
};
in
shblib.getReplacements (
map shblib.genReplacement (shblib.getReplacements (
item // {
nestedAttr = item;
nestedList = [ item ];
doubleNestedList = [ { n = item; } ];
}
);
));
};

testParseXML = {
Expand Down

0 comments on commit 45352eb

Please sign in to comment.