fix tests in lib
This commit is contained in:
parent
a589a9fe00
commit
52fc7e29a9
2 changed files with 18 additions and 15 deletions
|
@ -31,15 +31,16 @@ rec {
|
||||||
resultPath = newPath;
|
resultPath = newPath;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
genReplacement = secret:
|
||||||
|
let
|
||||||
|
t = { transform ? null, ... }: if isNull transform then x: x else transform;
|
||||||
|
in
|
||||||
|
lib.attrsets.nameValuePair (secretName secret.name) ((t secret) "$(cat ${toString secret.source})");
|
||||||
|
|
||||||
replaceSecretsScript = { file, resultPath, replacements, user ? null, permissions ? "u=r,g=r,o=" }:
|
replaceSecretsScript = { file, resultPath, replacements, user ? null, permissions ? "u=r,g=r,o=" }:
|
||||||
let
|
let
|
||||||
templatePath = resultPath + ".template";
|
templatePath = resultPath + ".template";
|
||||||
|
|
||||||
t = { transform ? null, ... }: if isNull transform then x: x else transform;
|
|
||||||
|
|
||||||
genReplacement = secret:
|
|
||||||
lib.attrsets.nameValuePair (secretName secret.name) ((t secret) "$(cat ${toString secret.source})");
|
|
||||||
|
|
||||||
# We check that the files containing the secrets have the
|
# We check that the files containing the secrets have the
|
||||||
# correct permissions for us to read them in this separate
|
# correct permissions for us to read them in this separate
|
||||||
# step. Otherwise, the $(cat ...) commands inside the sed
|
# step. Otherwise, the $(cat ...) commands inside the sed
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
{ pkgs, lib, ... }:
|
{ pkgs, lib, ... }:
|
||||||
let
|
let
|
||||||
shblib = pkgs.callPackage ../../lib {};
|
shblib = pkgs.callPackage ../../lib {};
|
||||||
|
|
||||||
|
inherit (lib) nameValuePair;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
# Tests that withReplacements can:
|
# Tests that withReplacements can:
|
||||||
|
@ -79,15 +81,15 @@ in
|
||||||
testLibGetReplacements = {
|
testLibGetReplacements = {
|
||||||
expected =
|
expected =
|
||||||
let
|
let
|
||||||
secrets = root: {
|
secrets = root: [
|
||||||
"%SECRET_${root}B%" = "$(cat /path/B)";
|
(nameValuePair "%SECRET_${root}B%" "$(cat /path/B)")
|
||||||
"%SECRET_${root}C%" = "prefix-$(cat /path/C)-suffix";
|
(nameValuePair "%SECRET_${root}C%" "prefix-$(cat /path/C)-suffix")
|
||||||
};
|
];
|
||||||
in
|
in
|
||||||
(secrets "") //
|
(secrets "") ++
|
||||||
(secrets "NESTEDATTR_") //
|
(secrets "DOUBLENESTEDLIST_0_N_") ++
|
||||||
(secrets "NESTEDLIST_0_") //
|
(secrets "NESTEDATTR_") ++
|
||||||
(secrets "DOUBLENESTEDLIST_0_N_");
|
(secrets "NESTEDLIST_0_");
|
||||||
expr =
|
expr =
|
||||||
let
|
let
|
||||||
item = {
|
item = {
|
||||||
|
@ -99,13 +101,13 @@ in
|
||||||
c.other = "other";
|
c.other = "other";
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
shblib.getReplacements (
|
map shblib.genReplacement (shblib.getReplacements (
|
||||||
item // {
|
item // {
|
||||||
nestedAttr = item;
|
nestedAttr = item;
|
||||||
nestedList = [ item ];
|
nestedList = [ item ];
|
||||||
doubleNestedList = [ { n = item; } ];
|
doubleNestedList = [ { n = item; } ];
|
||||||
}
|
}
|
||||||
);
|
));
|
||||||
};
|
};
|
||||||
|
|
||||||
testParseXML = {
|
testParseXML = {
|
||||||
|
|
Loading…
Reference in a new issue