tests: various minor cleanups
This commit is contained in:
parent
19c509a6fa
commit
eec2272999
41 changed files with 680 additions and 747 deletions
|
|
@ -1,116 +1,116 @@
|
|||
{ config, pkgs, ... }:
|
||||
|
||||
let
|
||||
|
||||
boolToString = bool: if bool then "true" else "false";
|
||||
backups = config.programs.borgmatic.backups;
|
||||
|
||||
in {
|
||||
config = {
|
||||
programs.borgmatic = {
|
||||
enable = true;
|
||||
backups = {
|
||||
main = {
|
||||
location = {
|
||||
sourceDirectories = [ "/my-stuff-to-backup" ];
|
||||
repositories = [ "/mnt/disk1" "/mnt/disk2" ];
|
||||
extraConfig = {
|
||||
one_file_system = true;
|
||||
exclude_patterns = [ "*.swp" ];
|
||||
};
|
||||
programs.borgmatic = {
|
||||
enable = true;
|
||||
backups = {
|
||||
main = {
|
||||
location = {
|
||||
sourceDirectories = [ "/my-stuff-to-backup" ];
|
||||
repositories = [ "/mnt/disk1" "/mnt/disk2" ];
|
||||
extraConfig = {
|
||||
one_file_system = true;
|
||||
exclude_patterns = [ "*.swp" ];
|
||||
};
|
||||
};
|
||||
|
||||
storage = {
|
||||
encryptionPasscommand = "fetch-the-password.sh";
|
||||
extraConfig = { checkpoint_interval = 200; };
|
||||
};
|
||||
storage = {
|
||||
encryptionPasscommand = "fetch-the-password.sh";
|
||||
extraConfig = { checkpoint_interval = 200; };
|
||||
};
|
||||
|
||||
retention = {
|
||||
keepWithin = "14d";
|
||||
keepSecondly = 12;
|
||||
extraConfig = { prefix = "hostname"; };
|
||||
};
|
||||
retention = {
|
||||
keepWithin = "14d";
|
||||
keepSecondly = 12;
|
||||
extraConfig = { prefix = "hostname"; };
|
||||
};
|
||||
|
||||
consistency = {
|
||||
checks = [
|
||||
{
|
||||
name = "repository";
|
||||
frequency = "2 weeks";
|
||||
}
|
||||
{
|
||||
name = "archives";
|
||||
frequency = "4 weeks";
|
||||
}
|
||||
];
|
||||
consistency = {
|
||||
checks = [
|
||||
{
|
||||
name = "repository";
|
||||
frequency = "2 weeks";
|
||||
}
|
||||
{
|
||||
name = "archives";
|
||||
frequency = "4 weeks";
|
||||
}
|
||||
];
|
||||
|
||||
extraConfig = { prefix = "hostname"; };
|
||||
};
|
||||
extraConfig = { prefix = "hostname"; };
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
test.stubs.borgmatic = { };
|
||||
|
||||
nmt.script = ''
|
||||
config_file=$TESTED/home-files/.config/borgmatic.d/main.yaml
|
||||
assertFileExists $config_file
|
||||
|
||||
declare -A expectations
|
||||
|
||||
expectations[location.source_directories[0]]="${
|
||||
builtins.elemAt backups.main.location.sourceDirectories 0
|
||||
}"
|
||||
expectations[location.repositories[0]]="${
|
||||
builtins.elemAt backups.main.location.repositories 0
|
||||
}"
|
||||
expectations[location.repositories[1]]="${
|
||||
builtins.elemAt backups.main.location.repositories 1
|
||||
}"
|
||||
expectations[location.one_file_system]="${
|
||||
boolToString backups.main.location.extraConfig.one_file_system
|
||||
}"
|
||||
expectations[location.exclude_patterns[0]]="${
|
||||
builtins.elemAt backups.main.location.extraConfig.exclude_patterns 0
|
||||
}"
|
||||
|
||||
expectations[storage.encryption_passcommand]="${backups.main.storage.encryptionPasscommand}"
|
||||
expectations[storage.checkpoint_interval]="${
|
||||
toString backups.main.storage.extraConfig.checkpoint_interval
|
||||
}"
|
||||
|
||||
expectations[retention.keep_within]="${backups.main.retention.keepWithin}"
|
||||
expectations[retention.keep_secondly]="${
|
||||
toString backups.main.retention.keepSecondly
|
||||
}"
|
||||
expectations[retention.prefix]="${backups.main.retention.extraConfig.prefix}"
|
||||
|
||||
expectations[consistency.checks[0].name]="${
|
||||
(builtins.elemAt backups.main.consistency.checks 0).name
|
||||
}"
|
||||
expectations[consistency.checks[0].frequency]="${
|
||||
(builtins.elemAt backups.main.consistency.checks 0).frequency
|
||||
}"
|
||||
expectations[consistency.checks[1].name]="${
|
||||
(builtins.elemAt backups.main.consistency.checks 1).name
|
||||
}"
|
||||
expectations[consistency.checks[1].frequency]="${
|
||||
(builtins.elemAt backups.main.consistency.checks 1).frequency
|
||||
}"
|
||||
expectations[consistency.prefix]="${backups.main.consistency.extraConfig.prefix}"
|
||||
|
||||
yq=${pkgs.yq-go}/bin/yq
|
||||
|
||||
for filter in "''${!expectations[@]}"; do
|
||||
expected_value="''${expectations[$filter]}"
|
||||
actual_value="$($yq ".$filter" $config_file)"
|
||||
|
||||
if [[ "$actual_value" != "$expected_value" ]]; then
|
||||
fail "Expected '$filter' to be '$expected_value' but was '$actual_value'"
|
||||
fi
|
||||
done
|
||||
|
||||
one_file_system=$($yq ".location.one_file_system" $config_file)
|
||||
if [[ $one_file_system != "true" ]]; then
|
||||
fail "Expected one_file_system to be true but it was $one_file_system"
|
||||
fi
|
||||
'';
|
||||
};
|
||||
|
||||
test.stubs.borgmatic = { };
|
||||
|
||||
nmt.script = ''
|
||||
config_file=$TESTED/home-files/.config/borgmatic.d/main.yaml
|
||||
assertFileExists $config_file
|
||||
|
||||
declare -A expectations
|
||||
|
||||
expectations[location.source_directories[0]]="${
|
||||
builtins.elemAt backups.main.location.sourceDirectories 0
|
||||
}"
|
||||
expectations[location.repositories[0]]="${
|
||||
builtins.elemAt backups.main.location.repositories 0
|
||||
}"
|
||||
expectations[location.repositories[1]]="${
|
||||
builtins.elemAt backups.main.location.repositories 1
|
||||
}"
|
||||
expectations[location.one_file_system]="${
|
||||
boolToString backups.main.location.extraConfig.one_file_system
|
||||
}"
|
||||
expectations[location.exclude_patterns[0]]="${
|
||||
builtins.elemAt backups.main.location.extraConfig.exclude_patterns 0
|
||||
}"
|
||||
|
||||
expectations[storage.encryption_passcommand]="${backups.main.storage.encryptionPasscommand}"
|
||||
expectations[storage.checkpoint_interval]="${
|
||||
toString backups.main.storage.extraConfig.checkpoint_interval
|
||||
}"
|
||||
|
||||
expectations[retention.keep_within]="${backups.main.retention.keepWithin}"
|
||||
expectations[retention.keep_secondly]="${
|
||||
toString backups.main.retention.keepSecondly
|
||||
}"
|
||||
expectations[retention.prefix]="${backups.main.retention.extraConfig.prefix}"
|
||||
|
||||
expectations[consistency.checks[0].name]="${
|
||||
(builtins.elemAt backups.main.consistency.checks 0).name
|
||||
}"
|
||||
expectations[consistency.checks[0].frequency]="${
|
||||
(builtins.elemAt backups.main.consistency.checks 0).frequency
|
||||
}"
|
||||
expectations[consistency.checks[1].name]="${
|
||||
(builtins.elemAt backups.main.consistency.checks 1).name
|
||||
}"
|
||||
expectations[consistency.checks[1].frequency]="${
|
||||
(builtins.elemAt backups.main.consistency.checks 1).frequency
|
||||
}"
|
||||
expectations[consistency.prefix]="${backups.main.consistency.extraConfig.prefix}"
|
||||
|
||||
yq=${pkgs.yq-go}/bin/yq
|
||||
|
||||
for filter in "''${!expectations[@]}"; do
|
||||
expected_value="''${expectations[$filter]}"
|
||||
actual_value="$($yq ".$filter" $config_file)"
|
||||
|
||||
if [[ "$actual_value" != "$expected_value" ]]; then
|
||||
fail "Expected '$filter' to be '$expected_value' but was '$actual_value'"
|
||||
fi
|
||||
done
|
||||
|
||||
one_file_system=$($yq ".location.one_file_system" $config_file)
|
||||
if [[ $one_file_system != "true" ]]; then
|
||||
fail "Expected one_file_system to be true but it was $one_file_system"
|
||||
fi
|
||||
'';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,40 +1,40 @@
|
|||
{ config, pkgs, ... }:
|
||||
|
||||
let
|
||||
|
||||
backups = config.programs.borgmatic.backups;
|
||||
excludeFile = pkgs.writeText "excludeFile.txt" "/foo/bar";
|
||||
excludeFile = builtins.toFile "excludeFile.txt" "/foo/bar";
|
||||
|
||||
in {
|
||||
config = {
|
||||
programs.borgmatic = {
|
||||
enable = true;
|
||||
backups = {
|
||||
main = {
|
||||
location = {
|
||||
sourceDirectories = [ "/my-stuff-to-backup" ];
|
||||
repositories = [ "/mnt/disk1" ];
|
||||
excludeHomeManagerSymlinks = true;
|
||||
};
|
||||
programs.borgmatic = {
|
||||
enable = true;
|
||||
backups = {
|
||||
main = {
|
||||
location = {
|
||||
sourceDirectories = [ "/my-stuff-to-backup" ];
|
||||
repositories = [ "/mnt/disk1" ];
|
||||
excludeHomeManagerSymlinks = true;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
test.stubs.borgmatic = { };
|
||||
|
||||
nmt.script = ''
|
||||
config_file=$TESTED/home-files/.config/borgmatic.d/main.yaml
|
||||
assertFileExists $config_file
|
||||
|
||||
yq=${pkgs.yq-go}/bin/yq
|
||||
|
||||
hmExclusionsFile=$($yq '.location.exclude_from[0]' $config_file)
|
||||
expected_content='/home/hm-user/.config/borgmatic.d/main.yaml'
|
||||
|
||||
grep --quiet "$expected_content" "$hmExclusionsFile"
|
||||
|
||||
if [[ $? -ne 0 ]]; then
|
||||
echo "Expected to find $expected_content in file $hmExclusionsFile but didn't" >&2
|
||||
exit 1
|
||||
fi
|
||||
'';
|
||||
};
|
||||
|
||||
test.stubs.borgmatic = { };
|
||||
|
||||
nmt.script = ''
|
||||
config_file=$TESTED/home-files/.config/borgmatic.d/main.yaml
|
||||
assertFileExists $config_file
|
||||
|
||||
yq=${pkgs.yq-go}/bin/yq
|
||||
|
||||
hmExclusionsFile=$($yq '.location.exclude_from[0]' $config_file)
|
||||
expected_content='/home/hm-user/.config/borgmatic.d/main.yaml'
|
||||
|
||||
grep --quiet "$expected_content" "$hmExclusionsFile"
|
||||
|
||||
if [[ $? -ne 0 ]]; then
|
||||
echo "Expected to find $expected_content in file $hmExclusionsFile but didn't" >&2
|
||||
exit 1
|
||||
fi
|
||||
'';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,54 +1,54 @@
|
|||
{ config, pkgs, ... }:
|
||||
|
||||
let
|
||||
|
||||
backups = config.programs.borgmatic.backups;
|
||||
excludeFile = pkgs.writeText "excludeFile.txt" "/foo/bar";
|
||||
excludeFile = builtins.toFile "excludeFile.txt" "/foo/bar";
|
||||
|
||||
in {
|
||||
config = {
|
||||
programs.borgmatic = {
|
||||
enable = true;
|
||||
backups = {
|
||||
main = {
|
||||
location = {
|
||||
sourceDirectories = [ "/my-stuff-to-backup" ];
|
||||
repositories = [ "/mnt/disk1" ];
|
||||
excludeHomeManagerSymlinks = true;
|
||||
extraConfig = { exclude_from = [ (toString excludeFile) ]; };
|
||||
};
|
||||
programs.borgmatic = {
|
||||
enable = true;
|
||||
backups = {
|
||||
main = {
|
||||
location = {
|
||||
sourceDirectories = [ "/my-stuff-to-backup" ];
|
||||
repositories = [ "/mnt/disk1" ];
|
||||
excludeHomeManagerSymlinks = true;
|
||||
extraConfig = { exclude_from = [ (toString excludeFile) ]; };
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
test.stubs.borgmatic = { };
|
||||
|
||||
nmt.script = ''
|
||||
config_file=$TESTED/home-files/.config/borgmatic.d/main.yaml
|
||||
assertFileExists $config_file
|
||||
|
||||
declare -A expectations
|
||||
|
||||
expectations[location.exclude_from[0]]="${excludeFile}"
|
||||
|
||||
yq=${pkgs.yq-go}/bin/yq
|
||||
|
||||
for filter in "''${!expectations[@]}"; do
|
||||
expected_value="''${expectations[$filter]}"
|
||||
actual_value="$($yq ".$filter" $config_file)"
|
||||
|
||||
if [[ "$actual_value" != "$expected_value" ]]; then
|
||||
fail "Expected '$filter' to be '$expected_value' but was '$actual_value'"
|
||||
fi
|
||||
done
|
||||
|
||||
hmExclusionsFile=$($yq '.location.exclude_from[1]' $config_file)
|
||||
expected_content='/home/hm-user/.config/borgmatic.d/main.yaml'
|
||||
|
||||
grep --quiet "$expected_content" "$hmExclusionsFile"
|
||||
|
||||
if [[ $? -ne 0 ]]; then
|
||||
echo "Expected to find $expected_content in file $hmExclusionsFile but didn't" >&2
|
||||
exit 1
|
||||
fi
|
||||
'';
|
||||
};
|
||||
|
||||
test.stubs.borgmatic = { };
|
||||
|
||||
nmt.script = ''
|
||||
config_file=$TESTED/home-files/.config/borgmatic.d/main.yaml
|
||||
assertFileExists $config_file
|
||||
|
||||
declare -A expectations
|
||||
|
||||
expectations[location.exclude_from[0]]="${excludeFile}"
|
||||
|
||||
yq=${pkgs.yq-go}/bin/yq
|
||||
|
||||
for filter in "''${!expectations[@]}"; do
|
||||
expected_value="''${expectations[$filter]}"
|
||||
actual_value="$($yq ".$filter" $config_file)"
|
||||
|
||||
if [[ "$actual_value" != "$expected_value" ]]; then
|
||||
fail "Expected '$filter' to be '$expected_value' but was '$actual_value'"
|
||||
fi
|
||||
done
|
||||
|
||||
hmExclusionsFile=$($yq '.location.exclude_from[1]' $config_file)
|
||||
expected_content='/home/hm-user/.config/borgmatic.d/main.yaml'
|
||||
|
||||
grep --quiet "$expected_content" "$hmExclusionsFile"
|
||||
|
||||
if [[ $? -ne 0 ]]; then
|
||||
echo "Expected to find $expected_content in file $hmExclusionsFile but didn't" >&2
|
||||
exit 1
|
||||
fi
|
||||
'';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,45 +1,45 @@
|
|||
{ config, pkgs, ... }:
|
||||
|
||||
let
|
||||
|
||||
backups = config.programs.borgmatic.backups;
|
||||
excludeFile = pkgs.writeText "excludeFile.txt" "/foo/bar";
|
||||
excludeFile = builtins.toFile "excludeFile.txt" "/foo/bar";
|
||||
|
||||
in {
|
||||
config = {
|
||||
programs.borgmatic = {
|
||||
enable = true;
|
||||
backups = {
|
||||
main = {
|
||||
location = {
|
||||
sourceDirectories = [ "/my-stuff-to-backup" ];
|
||||
repositories = [ "/mnt/disk1" ];
|
||||
excludeHomeManagerSymlinks = false;
|
||||
extraConfig = { exclude_from = [ (toString excludeFile) ]; };
|
||||
};
|
||||
programs.borgmatic = {
|
||||
enable = true;
|
||||
backups = {
|
||||
main = {
|
||||
location = {
|
||||
sourceDirectories = [ "/my-stuff-to-backup" ];
|
||||
repositories = [ "/mnt/disk1" ];
|
||||
excludeHomeManagerSymlinks = false;
|
||||
extraConfig = { exclude_from = [ (toString excludeFile) ]; };
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
test.stubs.borgmatic = { };
|
||||
|
||||
nmt.script = ''
|
||||
config_file=$TESTED/home-files/.config/borgmatic.d/main.yaml
|
||||
assertFileExists $config_file
|
||||
|
||||
declare -A expectations
|
||||
|
||||
expectations[location.exclude_from[0]]="${excludeFile}"
|
||||
|
||||
yq=${pkgs.yq-go}/bin/yq
|
||||
|
||||
for filter in "''${!expectations[@]}"; do
|
||||
expected_value="''${expectations[$filter]}"
|
||||
actual_value="$($yq ".$filter" $config_file)"
|
||||
|
||||
if [[ "$actual_value" != "$expected_value" ]]; then
|
||||
fail "Expected '$filter' to be '$expected_value' but was '$actual_value'"
|
||||
fi
|
||||
done
|
||||
|
||||
'';
|
||||
};
|
||||
|
||||
test.stubs.borgmatic = { };
|
||||
|
||||
nmt.script = ''
|
||||
config_file=$TESTED/home-files/.config/borgmatic.d/main.yaml
|
||||
assertFileExists $config_file
|
||||
|
||||
declare -A expectations
|
||||
|
||||
expectations[location.exclude_from[0]]="${excludeFile}"
|
||||
|
||||
yq=${pkgs.yq-go}/bin/yq
|
||||
|
||||
for filter in "''${!expectations[@]}"; do
|
||||
expected_value="''${expectations[$filter]}"
|
||||
actual_value="$($yq ".$filter" $config_file)"
|
||||
|
||||
if [[ "$actual_value" != "$expected_value" ]]; then
|
||||
fail "Expected '$filter' to be '$expected_value' but was '$actual_value'"
|
||||
fi
|
||||
done
|
||||
|
||||
'';
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue