about summary refs log tree commit diff stats
path: root/tests/by-name/ta
diff options
context:
space:
mode:
Diffstat (limited to 'tests/by-name/ta')
-rw-r--r--tests/by-name/ta/taskchampion-sync/test.nix151
1 files changed, 151 insertions, 0 deletions
diff --git a/tests/by-name/ta/taskchampion-sync/test.nix b/tests/by-name/ta/taskchampion-sync/test.nix
new file mode 100644
index 0000000..cdbe062
--- /dev/null
+++ b/tests/by-name/ta/taskchampion-sync/test.nix
@@ -0,0 +1,151 @@
+{
+  nixos-lib,
+  pkgsUnstable,
+  nixpkgs-unstable,
+  vhackPackages,
+  pkgs,
+  extraModules,
+  nixLib,
+  ...
+}:
+nixos-lib.runTest {
+  hostPkgs = pkgs;
+  name = "taskchampion-sync";
+
+  node = {
+    specialArgs = {inherit pkgsUnstable vhackPackages nixpkgs-unstable nixLib;};
+
+    # Use the nixpkgs as constructed by the `nixpkgs.*` options
+    pkgs = null;
+  };
+
+  nodes = let
+    # The feature flag is only in version 3.2 and upwards. Stable is still on 3.1
+    taskwarriorPackage = pkgsUnstable.taskwarrior3.overrideAttrs (final: prev: {
+      cmakeFlags = (prev.cmakeFlags or []) ++ ["-DENABLE_TLS_NATIVE_ROOTS=true"];
+    });
+  in {
+    acme = {
+      imports = [
+        ../../../common/acme/server.nix
+        ../../../common/dns/client.nix
+      ];
+    };
+    name_server = {nodes, ...}: {
+      imports =
+        extraModules
+        ++ [
+          ../../../common/acme/client.nix
+          ../../../common/dns/server.nix
+        ];
+
+      vhack.dns.zones = {
+        "taskchampion.server" = {
+          SOA = {
+            nameServer = "ns";
+            adminEmail = "admin@server.com";
+            serial = 2025012301;
+          };
+          useOrigin = false;
+
+          A = [
+            nodes.server.networking.primaryIPAddress
+          ];
+          AAAA = [
+            nodes.server.networking.primaryIPv6Address
+          ];
+        };
+      };
+    };
+
+    server = {config, ...}: {
+      imports =
+        extraModules
+        ++ [
+          ../../../../modules
+          ../../../common/acme/client.nix
+          ../../../common/dns/client.nix
+        ];
+
+      vhack = {
+        persist.enable = true;
+        nginx.enable = true;
+        taskchampion-sync = {
+          enable = true;
+          fqdn = "taskchampion.server";
+        };
+      };
+    };
+
+    task_client1 = {config, ...}: {
+      imports = [
+        ../../../common/acme/client.nix
+        ../../../common/dns/client.nix
+      ];
+
+      environment.systemPackages = [
+        taskwarriorPackage
+      ];
+    };
+    task_client2 = {config, ...}: {
+      imports = [
+        ../../../common/acme/client.nix
+        ../../../common/dns/client.nix
+      ];
+
+      environment.systemPackages = [
+        taskwarriorPackage
+      ];
+    };
+  };
+
+  testScript = {nodes, ...}: let
+    # Generated with uuidgen
+    uuid = "bf01376e-04a4-435a-9263-608567531af3";
+    password = "nixos-test";
+
+    mkSyncConfig = path:
+      pkgs.writeShellScript "setup-config-file" ''
+        set -xe
+
+        mkdir --parents "$(dirname "${path}")"
+        echo 'sync.server.url=https://taskchampion.server' >> "${path}"
+        echo 'sync.server.client_id=${uuid}' >> "${path}"
+        echo 'sync.encryption_secret=${password}' >> "${path}"
+      '';
+
+    acme = import ../../../common/acme {inherit pkgs;};
+  in
+    acme.prepare ["server" "task_client1" "task_client2"]
+    # Python
+    ''
+      server.wait_for_unit("taskchampion-sync-server.service")
+      server.wait_for_open_port(443)
+
+      with subtest("Setup task syncing"):
+          for task in [task_client1, task_client2]:
+            # See man task-sync(5)
+            task.succeed("mkdir ~/.task")
+            task.succeed("${mkSyncConfig "$HOME/.taskrc"}")
+
+      with subtest("Can create tasks"):
+          task_client1.succeed("task add 'First task -- task_client1'")
+          task_client2.succeed("task add 'First task -- task_client2'")
+
+      # Wait for the server to acquire the acme certificate
+      task_client1.wait_until_succeeds("curl https://taskchampion.server")
+
+      with subtest("Can sync tasks"):
+          for task in [task_client1, task_client2]:
+            task.succeed("task sync")
+          task_client1.succeed("task sync")
+
+
+      with subtest("Have correct tasks"):
+          count1 = task_client1.succeed("task count")
+          count2 = task_client2.succeed("task count")
+
+          assert int(count1) == 2, f"We don't have exactly 2 tasks, but {count1}"
+          assert count1 == count2, f"The clients don't have the same amount of tasks, client1: {count1}, client2: {count2}"
+    '';
+}