summary refs log tree commit diff
path: root/nixos/tests/radicale.nix
diff options
context:
space:
mode:
authorAneesh Agrawal <aneeshusa@gmail.com>2017-09-18 01:46:07 -0700
committerAneesh Agrawal <aneeshusa@gmail.com>2017-09-18 09:11:36 -0700
commit28c2cea847026b62c4215aaaa808ee561d8b04ad (patch)
treec180cde3d2e757c0687115eb7251fcaf160a4aad /nixos/tests/radicale.nix
parent61de150aa8c2b6dab46cf0a3344f5df641bdc5eb (diff)
downloadnixlib-28c2cea847026b62c4215aaaa808ee561d8b04ad.tar
nixlib-28c2cea847026b62c4215aaaa808ee561d8b04ad.tar.gz
nixlib-28c2cea847026b62c4215aaaa808ee561d8b04ad.tar.bz2
nixlib-28c2cea847026b62c4215aaaa808ee561d8b04ad.tar.lz
nixlib-28c2cea847026b62c4215aaaa808ee561d8b04ad.tar.xz
nixlib-28c2cea847026b62c4215aaaa808ee561d8b04ad.tar.zst
nixlib-28c2cea847026b62c4215aaaa808ee561d8b04ad.zip
radicale: Test migration functionality
This also provides an example of how to migrate.
Diffstat (limited to 'nixos/tests/radicale.nix')
-rw-r--r--nixos/tests/radicale.nix90
1 files changed, 78 insertions, 12 deletions
diff --git a/nixos/tests/radicale.nix b/nixos/tests/radicale.nix
index bec86d2cb284..2c888469d0a4 100644
--- a/nixos/tests/radicale.nix
+++ b/nixos/tests/radicale.nix
@@ -2,12 +2,8 @@ let
   user = "someuser";
   password = "some_password";
   port = builtins.toString 5232;
-in
-  import ./make-test.nix ({ pkgs, lib, ... }: {
-  name = "radicale";
-  meta.maintainers = with lib.maintainers; [ aneeshusa infinisil ];
 
-  machine = {
+  common = { pkgs, ... }: {
     services.radicale = {
       enable = true;
       config = ''
@@ -29,11 +25,81 @@ in
       ${pkgs.apacheHttpd}/bin/htpasswd -bcB "$out" ${user} ${password}
     '';
   };
-  
-  # This tests whether the web interface is accessible to an authenticated user
-  testScript = ''
-    $machine->waitForUnit('radicale.service');
-    $machine->waitForOpenPort(${port});
-    $machine->succeed('curl --fail http://${user}:${password}@localhost:${port}/.web/');
-  '';
+
+in
+
+  import ./make-test.nix ({ pkgs, lib, ... }@args: {
+    name = "radicale";
+    meta.maintainers = with lib.maintainers; [ aneeshusa infinisil ];
+
+    nodes = rec {
+      radicale = radicale1; # Make the test script read more nicely
+      radicale1 = lib.recursiveUpdate (common args) {
+        nixpkgs.overlays = [
+          (self: super: {
+            radicale1 = super.radicale1.overrideAttrs (oldAttrs: {
+              propagatedBuildInputs = with self.pythonPackages;
+                (oldAttrs.propagatedBuildInputs or []) ++ [ passlib ];
+            });
+          })
+        ];
+      };
+      radicale1_export = lib.recursiveUpdate radicale1 {
+        services.radicale.extraArgs = [
+          "--export-storage" "/tmp/collections-new"
+        ];
+      };
+      radicale2_verify = lib.recursiveUpdate radicale2 {
+        services.radicale.extraArgs = [ "--verify-storage" ];
+      };
+      radicale2 = lib.recursiveUpdate (common args) {
+        system.stateVersion = "17.09";
+      };
+    };
+
+    # This tests whether the web interface is accessible to an authenticated user
+    testScript = { nodes }: let
+      switchToConfig = nodeName: let
+        newSystem = nodes.${nodeName}.config.system.build.toplevel;
+      in "${newSystem}/bin/switch-to-configuration test";
+    in ''
+      # Check Radicale 1 functionality
+      $radicale->succeed('${switchToConfig "radicale1"} >&2');
+      $radicale->waitForUnit('radicale.service');
+      $radicale->waitForOpenPort(${port});
+      $radicale->succeed('curl --fail http://${user}:${password}@localhost:${port}/someuser/calendar.ics/');
+
+      # Export data in Radicale 2 format
+      $radicale->succeed('systemctl stop radicale');
+      $radicale->succeed('ls -al /tmp/collections');
+      $radicale->fail('ls -al /tmp/collections-new');
+      # Radicale exits immediately after exporting storage
+      $radicale->succeed('${switchToConfig "radicale1_export"} >&2');
+      $radicale->waitUntilFails('systemctl status radicale');
+      $radicale->succeed('ls -al /tmp/collections');
+      $radicale->succeed('ls -al /tmp/collections-new');
+
+      # Verify data in Radicale 2 format
+      $radicale->succeed('rm -r /tmp/collections/${user}');
+      $radicale->succeed('mv /tmp/collections-new/collection-root /tmp/collections');
+      $radicale->succeed('${switchToConfig "radicale2_verify"} >&2');
+      $radicale->waitUntilFails('systemctl status radicale');
+      my ($retcode, $logs) = $radicale->execute('journalctl -u radicale -n 5');
+      if ($retcode != 0 || index($logs, 'Verifying storage') == -1) {
+        die "Radicale 2 didn't verify storage"
+      }
+      if (index($logs, 'failed') != -1 || index($logs, 'exception') != -1) {
+        die "storage verification failed"
+      }
+
+      # Check Radicale 2 functionality
+      $radicale->succeed('${switchToConfig "radicale2"} >&2');
+      $radicale->waitForUnit('radicale.service');
+      $radicale->waitForOpenPort(${port});
+      my ($retcode, $output) = $radicale->execute('curl --fail http://${user}:${password}@localhost:${port}/someuser/calendar.ics/');
+      if ($retcode != 0 || index($output, 'VCALENDAR') == -1) {
+        die "Could not read calendar from Radicale 2"
+      }
+      $radicale->succeed('curl --fail http://${user}:${password}@localhost:${port}/.web/');
+    '';
 })