tests and xml generation work (for real this guy trust)
Some checks failed
Run tests / run_tests (push) Failing after 3s
Some checks failed
Run tests / run_tests (push) Failing after 3s
This commit is contained in:
parent
b7fdfe57e6
commit
fa91487a1f
|
@ -15,9 +15,9 @@
|
||||||
parseTag = str: depth: xml: (builtins.concatStringsSep "" [
|
parseTag = str: depth: xml: (builtins.concatStringsSep "" [
|
||||||
str
|
str
|
||||||
"${indent depth}<${xml.tag}${
|
"${indent depth}<${xml.tag}${
|
||||||
if (builtins.hasAttr "content" xml) && ((builtins.isString xml.content) || (builtins.isList xml.content) && ((builtins.length xml.content) > 0))
|
if !(builtins.hasAttr "content" xml) || (((builtins.isString xml.content) && xml.content == "") || ((builtins.isList xml.content) && ((builtins.length xml.content) == 0)))
|
||||||
then ">"
|
then ""
|
||||||
else " "
|
else ">"
|
||||||
}"
|
}"
|
||||||
|
|
||||||
(
|
(
|
||||||
|
@ -31,9 +31,9 @@
|
||||||
)
|
)
|
||||||
|
|
||||||
(
|
(
|
||||||
if (builtins.hasAttr "content" xml) && ((builtins.isString xml.content) || (builtins.isList xml.content) && ((builtins.length xml.content) > 0))
|
if !(builtins.hasAttr "content" xml) || (((builtins.isString xml.content) && xml.content == "") || ((builtins.isList xml.content) && ((builtins.length xml.content) == 0)))
|
||||||
then ((toXmlRecursive' "\n" (depth + 1) xml.content) + "</${xml.tag}>")
|
then " />"
|
||||||
else "/>"
|
else ((toXmlRecursive' "\n" (depth + 1) xml.content) + "</${xml.tag}>")
|
||||||
)
|
)
|
||||||
]);
|
]);
|
||||||
in
|
in
|
||||||
|
@ -41,10 +41,12 @@
|
||||||
then "${parseTag str depth xml}\n${indent (depth - 1)}"
|
then "${parseTag str depth xml}\n${indent (depth - 1)}"
|
||||||
else if (builtins.isList xml)
|
else if (builtins.isList xml)
|
||||||
then "\n${(builtins.concatStringsSep "" (builtins.map (x: (toXmlRecursive' "" depth x)) xml))}${indent (depth - 1)}"
|
then "\n${(builtins.concatStringsSep "" (builtins.map (x: (toXmlRecursive' "" depth x)) xml))}${indent (depth - 1)}"
|
||||||
else if ((builtins.isBool xml) || (builtins.isInt xml) || (builtins.isNull xml) || (builtins.isFloat xml))
|
else if ((builtins.isInt xml) || (builtins.isNull xml) || (builtins.isFloat xml))
|
||||||
then (builtins.toString xml)
|
then (builtins.toString xml)
|
||||||
else if (builtins.isString xml)
|
else if (builtins.isString xml)
|
||||||
then xml
|
then xml
|
||||||
|
else if (builtins.isBool xml)then
|
||||||
|
if xml then "true" else "false"
|
||||||
else throw "Cannot convert a ${builtins.typeOf xml} to XML. ${toString (builtins.trace xml xml)}";
|
else throw "Cannot convert a ${builtins.typeOf xml} to XML. ${toString (builtins.trace xml xml)}";
|
||||||
in
|
in
|
||||||
toXMLRecursive;
|
toXMLRecursive;
|
||||||
|
|
|
@ -7,11 +7,11 @@
|
||||||
with lib; let
|
with lib; let
|
||||||
cfg = config.services.declarative-jellyfin;
|
cfg = config.services.declarative-jellyfin;
|
||||||
toXml' = (import ../lib {nixpkgs = pkgs;}).toXMLGeneric;
|
toXml' = (import ../lib {nixpkgs = pkgs;}).toXMLGeneric;
|
||||||
isStrList = x: builtins.all (x: builtins.isString x) x;
|
isStrList = x: all (x: isString x) x;
|
||||||
prepass = x:
|
prepass = x:
|
||||||
if (builtins.isAttrs x)
|
if (isAttrs x)
|
||||||
then
|
then
|
||||||
if !(builtins.hasAttr "tag" x)
|
if !(hasAttr "tag" x)
|
||||||
then
|
then
|
||||||
attrsets.mapAttrsToList
|
attrsets.mapAttrsToList
|
||||||
(tag: value: {
|
(tag: value: {
|
||||||
|
@ -19,23 +19,23 @@ with lib; let
|
||||||
content = prepass value;
|
content = prepass value;
|
||||||
})
|
})
|
||||||
x
|
x
|
||||||
else if (builtins.hasAttr "content" x)
|
else if (hasAttr "content" x)
|
||||||
then {
|
then {
|
||||||
tag = x.tag;
|
tag = x.tag;
|
||||||
content = prepass x.content;
|
content = prepass x.content;
|
||||||
}
|
}
|
||||||
else x
|
else x
|
||||||
else if (builtins.isList x)
|
else if (isList x)
|
||||||
then
|
then
|
||||||
if (isStrList x)
|
if (isStrList x)
|
||||||
then
|
then
|
||||||
(builtins.map
|
(map
|
||||||
(content: {
|
(content: {
|
||||||
tag = "string";
|
tag = "string";
|
||||||
inherit content;
|
inherit content;
|
||||||
})
|
})
|
||||||
x)
|
x)
|
||||||
else builtins.map prepass x
|
else map prepass x
|
||||||
else x;
|
else x;
|
||||||
|
|
||||||
toXml = tag: x: (toXml' {
|
toXml = tag: x: (toXml' {
|
||||||
|
@ -59,8 +59,8 @@ in {
|
||||||
(
|
(
|
||||||
let
|
let
|
||||||
commands =
|
commands =
|
||||||
builtins.concatStringsSep "\n"
|
concatStringsSep "\n"
|
||||||
(builtins.map
|
(map
|
||||||
(x: "cp -s \"${pkgs.writeText x.file (toXml x.name x.content)}\" \"/var/lib/jellyfin/config/${x.file}\"")
|
(x: "cp -s \"${pkgs.writeText x.file (toXml x.name x.content)}\" \"/var/lib/jellyfin/config/${x.file}\"")
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
|
|
165
tests/xml.nix
165
tests/xml.nix
|
@ -1,38 +1,140 @@
|
||||||
{pkgs ? import <nixpkgs> {}, ...}: let
|
{ pkgs ? import <nixpkgs> { }, ... }:
|
||||||
|
let
|
||||||
name = "networking";
|
name = "networking";
|
||||||
in {
|
in
|
||||||
|
{
|
||||||
inherit name;
|
inherit name;
|
||||||
test = pkgs.nixosTest {
|
test = pkgs.nixosTest {
|
||||||
inherit name;
|
inherit name;
|
||||||
nodes = {
|
nodes = {
|
||||||
machine = {
|
machine =
|
||||||
config,
|
{ config
|
||||||
pkgs,
|
, pkgs
|
||||||
...
|
, ...
|
||||||
}: {
|
}: {
|
||||||
imports = [
|
imports = [
|
||||||
../modules/default.nix
|
../modules/default.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
assertions = let
|
# assertions = let
|
||||||
toXml = (import ../lib {nixpkgs = pkgs;}).toXMLGeneric;
|
# toXml = (import ../lib {nixpkgs = pkgs;}).toXMLGeneric;
|
||||||
in [
|
# in [
|
||||||
(
|
# (
|
||||||
|
# let
|
||||||
|
# xml =
|
||||||
|
# toXml {tag = "test";};
|
||||||
|
# expected = ''
|
||||||
|
# <?xml version='1.0' encoding='utf-8'?>
|
||||||
|
# <test />
|
||||||
|
# '';
|
||||||
|
# in {
|
||||||
|
# assertion = xml == expected;
|
||||||
|
# message = "Generated XML is incorrect!\nExpected \n\n${expected}\n\n but got \n\n${xml}\n";
|
||||||
|
# }
|
||||||
|
# )
|
||||||
|
# ];
|
||||||
|
|
||||||
|
assertions =
|
||||||
let
|
let
|
||||||
xml =
|
genTest = name: expected: got: {
|
||||||
toXml {tag = "test";};
|
assertion = expected == got;
|
||||||
expected = ''
|
message = "[Test: ${name}] Generated XML is incorrect!\nExpected \n\n${expected}\n but got \n\n${got}";
|
||||||
|
};
|
||||||
|
toXml = (import ../lib { nixpkgs = pkgs; }).toXMLGeneric;
|
||||||
|
in
|
||||||
|
[
|
||||||
|
(genTest "Single tag"
|
||||||
|
''
|
||||||
<?xml version='1.0' encoding='utf-8'?>
|
<?xml version='1.0' encoding='utf-8'?>
|
||||||
<test />
|
<test />
|
||||||
'';
|
''
|
||||||
in {
|
(toXml { tag = "test"; })
|
||||||
assertion = xml == expected;
|
)
|
||||||
message = "Generated XML is incorrect!\nExpected \n\n${expected}\n\n but got \n\n${xml}\n";
|
(genTest "Single inner tag"
|
||||||
}
|
''
|
||||||
|
<?xml version='1.0' encoding='utf-8'?>
|
||||||
|
<test>
|
||||||
|
<inner />
|
||||||
|
</test>
|
||||||
|
''
|
||||||
|
(toXml {
|
||||||
|
tag = "test";
|
||||||
|
content = { tag = "inner"; };
|
||||||
|
})
|
||||||
|
)
|
||||||
|
(genTest "Tag with string"
|
||||||
|
''
|
||||||
|
<?xml version='1.0' encoding='utf-8'?>
|
||||||
|
<test>stringstringstring</test>
|
||||||
|
''
|
||||||
|
(toXml {
|
||||||
|
tag = "test";
|
||||||
|
content = "stringstringstring";
|
||||||
|
})
|
||||||
|
)
|
||||||
|
(genTest "Empty string"
|
||||||
|
''
|
||||||
|
<?xml version='1.0' encoding='utf-8'?>
|
||||||
|
<test />
|
||||||
|
''
|
||||||
|
(toXml {
|
||||||
|
tag = "test";
|
||||||
|
content = "";
|
||||||
|
})
|
||||||
|
)
|
||||||
|
(genTest "List of tags"
|
||||||
|
''
|
||||||
|
<?xml version='1.0' encoding='utf-8'?>
|
||||||
|
<test>
|
||||||
|
<tag0 />
|
||||||
|
<tag1 />
|
||||||
|
<tag2 />
|
||||||
|
<tag3 />
|
||||||
|
<tag4 />
|
||||||
|
<tag5 />
|
||||||
|
<tag6 />
|
||||||
|
<tag7 />
|
||||||
|
<tag8 />
|
||||||
|
</test>
|
||||||
|
''
|
||||||
|
(toXml {
|
||||||
|
tag = "test";
|
||||||
|
content = builtins.genList (x: { tag = "tag${toString x}"; }) 9;
|
||||||
|
})
|
||||||
|
)
|
||||||
|
(genTest "Empty list"
|
||||||
|
''
|
||||||
|
<?xml version='1.0' encoding='utf-8'?>
|
||||||
|
<test />
|
||||||
|
''
|
||||||
|
(toXml {
|
||||||
|
tag = "test";
|
||||||
|
content = [ ];
|
||||||
|
})
|
||||||
|
)
|
||||||
|
(genTest "bool value true"
|
||||||
|
''
|
||||||
|
<?xml version='1.0' encoding='utf-8'?>
|
||||||
|
<test>true</test>
|
||||||
|
''
|
||||||
|
(toXml {
|
||||||
|
tag = "test";
|
||||||
|
content = true;
|
||||||
|
})
|
||||||
|
)
|
||||||
|
(genTest "bool value false"
|
||||||
|
''
|
||||||
|
<?xml version='1.0' encoding='utf-8'?>
|
||||||
|
<test>false</test>
|
||||||
|
''
|
||||||
|
(toXml {
|
||||||
|
tag = "test";
|
||||||
|
content = false;
|
||||||
|
})
|
||||||
)
|
)
|
||||||
];
|
];
|
||||||
|
|
||||||
virtualisation.memorySize = 1024 * 2;
|
virtualisation.memorySize = 1024;
|
||||||
|
|
||||||
services.declarative-jellyfin = {
|
services.declarative-jellyfin = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
@ -40,6 +142,9 @@ in {
|
||||||
PublishedServerUriBySubnet = [
|
PublishedServerUriBySubnet = [
|
||||||
"all=https://test.test.test"
|
"all=https://test.test.test"
|
||||||
];
|
];
|
||||||
|
EnableHttps = true;
|
||||||
|
RequireHttps = true;
|
||||||
|
CertificatePath = "/path/to/cert";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -50,11 +155,13 @@ in {
|
||||||
|
|
||||||
machine.wait_for_unit("multi-user.target");
|
machine.wait_for_unit("multi-user.target");
|
||||||
|
|
||||||
with subtest("Networking"):
|
with subtest("network.xml"):
|
||||||
# stupid fucking hack because you cant open files in python for some reason
|
# stupid fucking hack because you cant open files in python for some reason
|
||||||
xml = machine.succeed("cat /var/lib/jellyfin/config/network.xml")
|
xml = machine.succeed("cat /var/lib/jellyfin/config/network.xml")
|
||||||
tree = ET.ElementTree(ET.fromstring(xml))
|
tree = ET.ElementTree(ET.fromstring(xml))
|
||||||
root = tree.getroot()
|
root = tree.getroot()
|
||||||
|
|
||||||
|
with subtest("PublishedServerUriBySubnet"):
|
||||||
for child in root:
|
for child in root:
|
||||||
if child.tag == "PublishedServerUriBySubnet":
|
if child.tag == "PublishedServerUriBySubnet":
|
||||||
try:
|
try:
|
||||||
|
@ -65,7 +172,23 @@ in {
|
||||||
print(xml)
|
print(xml)
|
||||||
assert False, "Exception occured, check output above"
|
assert False, "Exception occured, check output above"
|
||||||
else:
|
else:
|
||||||
assert False, "The shit was not found"
|
assert False, "The shit was not found. Full XML: " + xml
|
||||||
|
|
||||||
|
with subtest("EnableHttps"):
|
||||||
|
for child in root:
|
||||||
|
if child.tag == "EnableHttps":
|
||||||
|
if child.text == "true":
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
assert False, "The shit was not found. Full XML: " + xml
|
||||||
|
|
||||||
|
with subtest("RequireHttps"):
|
||||||
|
for child in root:
|
||||||
|
if child.tag == "RequireHttps":
|
||||||
|
if child.text == "true":
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
assert False, "The shit was not found. Full XML: " + xml
|
||||||
|
|
||||||
machine.shutdown()
|
machine.shutdown()
|
||||||
'';
|
'';
|
||||||
|
|
Loading…
Reference in a new issue