about summary refs log tree commit diff stats
path: root/tests/by-name/ta/taskchampion-sync/test.nix
blob: 4dd273bbf67767a5e11a3c48d42e6d72a58eaa2f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
{
  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 = {
    server = {config, ...}: {
      imports =
        extraModules
        ++ [
          ../../../../modules
        ];

      vhack = {
        taskchampion-sync.enable = true;
      };
    };

    task_client1 = {config, ...}: {
      environment.systemPackages = [
        pkgs.taskwarrior3
      ];
    };
    task_client2 = {config, ...}: {
      environment.systemPackages = [
        pkgs.taskwarrior3
      ];
    };
  };

  testScript = {nodes, ...}: let
    cfg = nodes.server.services.taskchampion-sync-server;
    port = builtins.toString cfg.port;

    # 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.origin=http://server:${port}' >> "${path}"
        echo 'sync.server.client_id=${uuid}' >> "${path}"
        echo 'sync.encryption_secret=${password}' >> "${path}"
      '';
  in
    /*
    python
    */
    ''
      start_all()

      server.wait_for_unit("taskchampion-sync-server.service")
      server.wait_for_open_port(${port})

      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'")

      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}"
    '';
}