59 lines
1.8 KiB
Nix
59 lines
1.8 KiB
Nix
# `checks.script-test-archive-metrics` — runs the metric functions of the archive's
|
|
# backup and prune scripts (../host-modules/lib/archive-backup.nix and
|
|
# archive-server.nix) against a stub `curl` and a fake `restic`. The cases are in
|
|
# ./archive-metrics.sh, which cuts each function out of the rendered script.
|
|
{
|
|
pkgs,
|
|
...
|
|
}:
|
|
let
|
|
fakeRestic = pkgs.writeShellScriptBin "restic" ''
|
|
# Answers from the files named by FAKE_SNAPSHOTS and FAKE_STATS; an unset
|
|
# variable makes that subcommand fail.
|
|
case " $* " in
|
|
*" snapshots "*) [ -n "''${FAKE_SNAPSHOTS:-}" ] && cat "$FAKE_SNAPSHOTS" ;;
|
|
*" stats "*) [ -n "''${FAKE_STATS:-}" ] && cat "$FAKE_STATS" ;;
|
|
*) exit 1 ;;
|
|
esac
|
|
'';
|
|
endpoint = "http://10.42.0.1:4318";
|
|
in
|
|
pkgs.runCommand "hyperhive-script-test-archive-metrics"
|
|
{
|
|
nativeBuildInputs = [
|
|
pkgs.coreutils
|
|
pkgs.jq
|
|
];
|
|
BACKUP_SCRIPT = pkgs.writeText "archive-backup.sh" (
|
|
import ../host-modules/lib/archive-backup.nix { inherit (pkgs) lib; } {
|
|
restic = fakeRestic;
|
|
hive = "h";
|
|
agentRoot = "/agents";
|
|
url = "https://archive.test";
|
|
scope = "paths";
|
|
paths = [ "state" ];
|
|
excludes = [ ];
|
|
caBundle = null;
|
|
otlpEndpoint = endpoint;
|
|
}
|
|
);
|
|
PRUNE_SCRIPT = pkgs.writeText "archive-prune.sh" (
|
|
(import ../host-modules/lib/archive-server.nix { inherit (pkgs) lib; } {
|
|
rclone = pkgs.rclone;
|
|
restic = fakeRestic;
|
|
reposDir = "/repos";
|
|
addr = "127.0.0.1:1";
|
|
authFile = "/auth";
|
|
authGroup = "g";
|
|
retention = {
|
|
keepWithin = null;
|
|
keepLast = 1;
|
|
};
|
|
otlpEndpoint = endpoint;
|
|
}).pruneScript
|
|
);
|
|
}
|
|
''
|
|
${pkgs.bash}/bin/bash ${./archive-metrics.sh}
|
|
touch "$out"
|
|
''
|