fix builder tests
This commit is contained in:
parent
669fccd57e
commit
28f8cfe612
6 changed files with 76 additions and 65 deletions
|
@ -39,8 +39,8 @@
|
||||||
./testing/elems.test.nix
|
./testing/elems.test.nix
|
||||||
./testing/site.test.nix
|
./testing/site.test.nix
|
||||||
./testing/style.test.nix
|
./testing/style.test.nix
|
||||||
|
./testing/builder.test.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
26
nixite/builder.nix
Normal file
26
nixite/builder.nix
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
rec {
|
||||||
|
buildSiteTo = prefix: site:
|
||||||
|
builtins.toString (builtins.attrValues (builtins.mapAttrs (name: content:
|
||||||
|
if builtins.isString content
|
||||||
|
then ''
|
||||||
|
cp ${builtins.toFile name content} ${prefix}/${name}
|
||||||
|
''
|
||||||
|
else if builtins.isPath content
|
||||||
|
then ''
|
||||||
|
cp -r ${content} ${prefix}/${name}
|
||||||
|
''
|
||||||
|
else if builtins.isAttrs content && content ? "__toString"
|
||||||
|
then ''
|
||||||
|
cp ${builtins.toFile name (toString content)} ${prefix}/${name}
|
||||||
|
''
|
||||||
|
else if builtins.isAttrs content
|
||||||
|
then ''
|
||||||
|
mkdir -p ${prefix}/${name}
|
||||||
|
${buildSiteTo "${prefix}/${name}" content}
|
||||||
|
''
|
||||||
|
else
|
||||||
|
throw "Site page must be string, path or attrset, but got ${
|
||||||
|
builtins.typeOf content
|
||||||
|
}: [${toString content}]")
|
||||||
|
site));
|
||||||
|
}
|
|
@ -1,28 +1,5 @@
|
||||||
pkgs: raw: let
|
pkgs: raw: let
|
||||||
buildSiteTo = prefix: site:
|
builder = import ./builder.nix;
|
||||||
builtins.toString (builtins.attrValues (builtins.mapAttrs (name: content:
|
|
||||||
if builtins.isString content
|
|
||||||
then ''
|
|
||||||
cp ${builtins.toFile name content} ${prefix}/${name}
|
|
||||||
''
|
|
||||||
else if builtins.isPath content
|
|
||||||
then ''
|
|
||||||
cp -r ${content} ${prefix}/${name}
|
|
||||||
''
|
|
||||||
else if builtins.isAttrs content && content ? "__toString"
|
|
||||||
then ''
|
|
||||||
cp ${builtins.toFile name (toString content)} ${prefix}/${name}
|
|
||||||
''
|
|
||||||
else if builtins.isAttrs content
|
|
||||||
then ''
|
|
||||||
mkdir -p ${prefix}/${name}
|
|
||||||
${buildSiteTo "${prefix}/${name}" content}
|
|
||||||
''
|
|
||||||
else
|
|
||||||
throw "Site page must be string, path or attrset, but got ${
|
|
||||||
builtins.typeOf content
|
|
||||||
}: [${toString content}]")
|
|
||||||
site));
|
|
||||||
in
|
in
|
||||||
derivation {
|
derivation {
|
||||||
builder = "/bin/sh";
|
builder = "/bin/sh";
|
||||||
|
@ -33,7 +10,7 @@ in
|
||||||
''
|
''
|
||||||
PATH=$PATH:${pkgs.coreutils}/bin
|
PATH=$PATH:${pkgs.coreutils}/bin
|
||||||
mkdir $out
|
mkdir $out
|
||||||
${buildSiteTo "$out" raw}
|
${builder.buildSiteTo "$out" raw}
|
||||||
''
|
''
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,5 +24,4 @@ in
|
||||||
chmod +x $out/bin/nixite-server
|
chmod +x $out/bin/nixite-server
|
||||||
''
|
''
|
||||||
];
|
];
|
||||||
inherit my-site;
|
|
||||||
}
|
}
|
||||||
|
|
47
testing/builder.test.nix
Normal file
47
testing/builder.test.nix
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
{
|
||||||
|
describe,
|
||||||
|
it,
|
||||||
|
...
|
||||||
|
}: let
|
||||||
|
builder = import ../nixite/builder.nix;
|
||||||
|
in
|
||||||
|
with builder; [
|
||||||
|
(describe "buildSiteTo" [
|
||||||
|
(it "copies all the files" {
|
||||||
|
actual = buildSiteTo "." {
|
||||||
|
page = "this is a page";
|
||||||
|
subdir = {
|
||||||
|
page = "this page is in a subdir";
|
||||||
|
link = ./src;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
expected = ''
|
||||||
|
cp /nix/store/crirfz0n6f8dgl1si3x7pwyw7fqm0r8l-page ./page
|
||||||
|
mkdir -p ./subdir
|
||||||
|
cp -r /nix/store/q95cn7ccixzi9w22aic4bl0ykk40ka7v-src ./subdir/link
|
||||||
|
cp /nix/store/ic6fyy8wg8r4338a3m5kinmg11igxsyj-page ./subdir/page
|
||||||
|
|
||||||
|
'';
|
||||||
|
})
|
||||||
|
|
||||||
|
(it "throws with a list for a page" {
|
||||||
|
actual = buildSiteTo "." {page = [];};
|
||||||
|
throws = true;
|
||||||
|
})
|
||||||
|
|
||||||
|
(it "throws with null for a page" {
|
||||||
|
actual = buildSiteTo "." {page = null;};
|
||||||
|
throws = true;
|
||||||
|
})
|
||||||
|
|
||||||
|
(it "throws with a bool for a page" {
|
||||||
|
actual = buildSiteTo "." {page = true;};
|
||||||
|
throws = true;
|
||||||
|
})
|
||||||
|
|
||||||
|
(it "throws with a number for a page" {
|
||||||
|
actual = buildSiteTo "." {page = 5;};
|
||||||
|
throws = true;
|
||||||
|
})
|
||||||
|
])
|
||||||
|
]
|
|
@ -235,44 +235,6 @@ in
|
||||||
};
|
};
|
||||||
}))
|
}))
|
||||||
])
|
])
|
||||||
(describe "copyTo" [
|
|
||||||
(it "copies all the files" {
|
|
||||||
actual = copyTo "." {
|
|
||||||
page = "this is a page";
|
|
||||||
subdir = {
|
|
||||||
page = "this page is in a subdir";
|
|
||||||
link = ./src;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
expected = ''
|
|
||||||
cp /nix/store/crirfz0n6f8dgl1si3x7pwyw7fqm0r8l-page ./page
|
|
||||||
mkdir -p ./subdir
|
|
||||||
cp -r /nix/store/q95cn7ccixzi9w22aic4bl0ykk40ka7v-src ./subdir/link
|
|
||||||
cp /nix/store/ic6fyy8wg8r4338a3m5kinmg11igxsyj-page ./subdir/page
|
|
||||||
|
|
||||||
'';
|
|
||||||
})
|
|
||||||
|
|
||||||
(it "throws with a list for a page" {
|
|
||||||
actual = copyTo "." {page = [];};
|
|
||||||
throws = true;
|
|
||||||
})
|
|
||||||
|
|
||||||
(it "throws with null for a page" {
|
|
||||||
actual = copyTo "." {page = null;};
|
|
||||||
throws = true;
|
|
||||||
})
|
|
||||||
|
|
||||||
(it "throws with a bool for a page" {
|
|
||||||
actual = copyTo "." {page = true;};
|
|
||||||
throws = true;
|
|
||||||
})
|
|
||||||
|
|
||||||
(it "throws with a number for a page" {
|
|
||||||
actual = copyTo "." {page = 5;};
|
|
||||||
throws = true;
|
|
||||||
})
|
|
||||||
])
|
|
||||||
(describe "prepare" [
|
(describe "prepare" [
|
||||||
(it "prepares the site" {
|
(it "prepares the site" {
|
||||||
actual = prepare {favicon = ./src/favicon.png;} my-site;
|
actual = prepare {favicon = ./src/favicon.png;} my-site;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue