Skip to content

Commit

Permalink
add test for all modules using backup contract
Browse files Browse the repository at this point in the history
  • Loading branch information
ibizaman committed Nov 28, 2024
1 parent cf7b25c commit 42287ff
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 63 deletions.
1 change: 1 addition & 0 deletions modules/services/home-assistant.nix
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ in
"f ${config.services.home-assistant.configDir}/automations.yaml 0755 hass hass"
"f ${config.services.home-assistant.configDir}/scenes.yaml 0755 hass hass"
"f ${config.services.home-assistant.configDir}/scripts.yaml 0755 hass hass"
"d /var/lib/hass/backups 0750 hass hass"
];
};
}
47 changes: 42 additions & 5 deletions test/common.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ let
(pkgs.path + "/nixos/modules/profiles/headless.nix")
(pkgs.path + "/nixos/modules/profiles/qemu-guest.nix")
];
in
{
accessScript = {

accessScript = lib.makeOverridable ({
subdomain
, domain
, hasSSL
Expand Down Expand Up @@ -95,9 +94,23 @@ in
lib.optionalString (script != "") ''
with subtest("extraScript"):
${indent 4 script}
'');
''));

backupScript = args: (accessScript args).override {
extraScript = { proto_fqdn, ... }: ''
with subtest("backup"):
server.succeed("systemctl start restic-backups-testinstance_opt_repos_A")
'';
};
in
{
inherit baseImports accessScript;

inherit baseImports;
mkScripts = args:
{
access = accessScript args;
backup = backupScript args;
};

base = pkgs: additionalModules: {
imports =
Expand All @@ -115,6 +128,30 @@ in
networking.firewall.allowedTCPPorts = [ 80 443 ];
};

backup = backupOption: { config, ... }: {
imports = [
../modules/blocks/restic.nix
];
shb.restic.instances."testinstance" = {
request = backupOption.request;
settings = {
enable = true;
passphrase.result = config.shb.hardcodedsecret.backupPassphrase.result;
repository = {
path = "/opt/repos/A";
timerConfig = {
OnCalendar = "00:00:00";
RandomizedDelaySec = "5h";
};
};
};
};
shb.hardcodedsecret.backupPassphrase = {
request = config.shb.restic.instances."testinstance".settings.passphrase.request;
settings.content = "PassPhrase";
};
};

certs = domain: { config, ... }: {
imports = [
../modules/blocks/ssl.nix
Expand Down
26 changes: 21 additions & 5 deletions test/services/forgejo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let

adminPassword = "AdminPassword";

commonTestScript = testLib.accessScript {
commonTestScript = testLib.mkScripts {
inherit subdomain domain;
hasSSL = { node, ... }: !(isNull node.config.shb.forgejo.ssl);
waitForServices = { ... }: [
Expand Down Expand Up @@ -111,7 +111,23 @@ in

nodes.client = {};

testScript = commonTestScript;
testScript = commonTestScript.access;
};

backup = pkgs.testers.runNixOSTest {
name = "forgejo_backup";

nodes.server = { config, ... }: {
imports = [
base
basic
(testLib.backup config.shb.forgejo.backup)
];
};

nodes.client = {};

testScript = commonTestScript.backup;
};

https = pkgs.testers.runNixOSTest {
Expand All @@ -128,7 +144,7 @@ in

nodes.client = {};

testScript = commonTestScript;
testScript = commonTestScript.access;
};

ldap = pkgs.testers.runNixOSTest {
Expand All @@ -145,7 +161,7 @@ in

nodes.client = {};

testScript = commonTestScript;
testScript = commonTestScript.access;
};

sso = pkgs.testers.runNixOSTest {
Expand All @@ -165,6 +181,6 @@ in

nodes.client = {};

testScript = commonTestScript;
testScript = commonTestScript.access;
};
}
26 changes: 21 additions & 5 deletions test/services/home-assistant.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let
subdomain = "ha";
domain = "example.com";

commonTestScript = lib.makeOverridable testLib.accessScript {
commonTestScript = testLib.mkScripts {
inherit subdomain domain;
hasSSL = { node, ... }: !(isNull node.config.shb.home-assistant.ssl);
waitForServices = { ... }: [
Expand Down Expand Up @@ -78,7 +78,23 @@ in

nodes.client = {};

testScript = commonTestScript;
testScript = commonTestScript.access;
};

backup = pkgs.testers.runNixOSTest {
name = "homeassistant_backup";

nodes.server = { config, ... }: {
imports = [
base
basic
(testLib.backup config.shb.home-assistant.backup)
];
};

nodes.client = {};

testScript = commonTestScript.backup;
};

https = pkgs.testers.runNixOSTest {
Expand All @@ -95,7 +111,7 @@ in

nodes.client = {};

testScript = commonTestScript;
testScript = commonTestScript.access;
};

ldap = pkgs.testers.runNixOSTest {
Expand All @@ -112,7 +128,7 @@ in

nodes.client = {};

testScript = commonTestScript;
testScript = commonTestScript.access;
};

# Not yet supported
Expand All @@ -133,6 +149,6 @@ in
#
# nodes.client = {};
#
# testScript = commonTestScript;
# testScript = commonTestScript.access;
# };
}
26 changes: 21 additions & 5 deletions test/services/jellyfin.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let
subdomain = "j";
domain = "example.com";

commonTestScript = testLib.accessScript {
commonTestScript = testLib.mkScripts {
inherit subdomain domain;
hasSSL = { node, ... }: !(isNull node.config.shb.jellyfin.ssl);
waitForServices = { ... }: [
Expand Down Expand Up @@ -87,7 +87,23 @@ in

nodes.client = {};

testScript = commonTestScript;
testScript = commonTestScript.access;
};

backup = pkgs.testers.runNixOSTest {
name = "jellyfin_backup";

nodes.server = { config, ... }: {
imports = [
base
basic
(testLib.backup config.shb.jellyfin.backup)
];
};

nodes.client = {};

testScript = commonTestScript.backup;
};

https = pkgs.testers.runNixOSTest {
Expand All @@ -104,7 +120,7 @@ in

nodes.client = {};

testScript = commonTestScript;
testScript = commonTestScript.access;
};

ldap = pkgs.testers.runNixOSTest {
Expand All @@ -121,7 +137,7 @@ in

nodes.client = {};

testScript = commonTestScript;
testScript = commonTestScript.access;
};

sso = pkgs.testers.runNixOSTest {
Expand All @@ -141,6 +157,6 @@ in

nodes.client = {};

testScript = commonTestScript;
testScript = commonTestScript.access;
};
}
30 changes: 23 additions & 7 deletions test/services/nextcloud.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let

testLib = pkgs.callPackage ../common.nix {};

commonTestScript = lib.makeOverridable testLib.accessScript {
commonTestScript = testLib.mkScripts {
inherit subdomain domain;
hasSSL = { node, ... }: !(isNull node.config.shb.nextcloud.ssl);
waitForServices = { ... }: [
Expand Down Expand Up @@ -227,7 +227,23 @@ in

nodes.client = {};

testScript = commonTestScript;
testScript = commonTestScript.access;
};

backup = pkgs.testers.runNixOSTest {
name = "nextcloud_backup";

nodes.server = { config, ... }: {
imports = [
base
basic
(testLib.backup config.shb.nextcloud.backup)
];
};

nodes.client = {};

testScript = commonTestScript.backup;
};

https = pkgs.testers.runNixOSTest {
Expand All @@ -245,7 +261,7 @@ in
nodes.client = {};

# TODO: Test login
testScript = commonTestScript;
testScript = commonTestScript.access;
};

previewGenerator = pkgs.testers.runNixOSTest {
Expand All @@ -263,7 +279,7 @@ in

nodes.client = {};

testScript = commonTestScript;
testScript = commonTestScript.access;
};

externalStorage = pkgs.testers.runNixOSTest {
Expand All @@ -281,7 +297,7 @@ in

nodes.client = {};

testScript = commonTestScript;
testScript = commonTestScript.access;
};

ldap = pkgs.testers.runNixOSTest {
Expand All @@ -300,7 +316,7 @@ in

nodes.client = {};

testScript = commonTestScript;
testScript = commonTestScript.access;
};

sso = pkgs.testers.runNixOSTest {
Expand All @@ -321,6 +337,6 @@ in

nodes.client = {};

testScript = commonTestScript;
testScript = commonTestScript.access;
};
}
Loading

0 comments on commit 42287ff

Please sign in to comment.