summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorPeter Hoeg <peter@hoeg.com>2019-04-24 22:29:08 +0800
committerGitHub <noreply@github.com>2019-04-24 22:29:08 +0800
commitf81ddbf8e7889e63496d3263f4ce28e5f9c79269 (patch)
treeccc006291fd838c09cac4d26ea16cc019fcf18db /nixos
parent28a95c4f7f1c46399e8938d7f3e08169cda61191 (diff)
parentc5af9fd4ddafc64edf74ffe7126eb60c80d635e7 (diff)
downloadnixpkgs-f81ddbf8e7889e63496d3263f4ce28e5f9c79269.tar
nixpkgs-f81ddbf8e7889e63496d3263f4ce28e5f9c79269.tar.gz
nixpkgs-f81ddbf8e7889e63496d3263f4ce28e5f9c79269.tar.bz2
nixpkgs-f81ddbf8e7889e63496d3263f4ce28e5f9c79269.tar.lz
nixpkgs-f81ddbf8e7889e63496d3263f4ce28e5f9c79269.tar.xz
nixpkgs-f81ddbf8e7889e63496d3263f4ce28e5f9c79269.tar.zst
nixpkgs-f81ddbf8e7889e63496d3263f4ce28e5f9c79269.zip
Merge pull request #60149 from peterhoeg/u/mosquitto_160
mosquitto: 1.5.8 -> 1.6 + nixos tests
Diffstat (limited to 'nixos')
-rw-r--r--nixos/tests/all-tests.nix1
-rw-r--r--nixos/tests/mosquitto.nix69
2 files changed, 70 insertions, 0 deletions
diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix
index bf6fd60b144..a1871ee5f90 100644
--- a/nixos/tests/all-tests.nix
+++ b/nixos/tests/all-tests.nix
@@ -144,6 +144,7 @@ in
   misc = handleTest ./misc.nix {};
   mongodb = handleTest ./mongodb.nix {};
   morty = handleTest ./morty.nix {};
+  mosquitto = handleTest ./mosquitto.nix {};
   mpd = handleTest ./mpd.nix {};
   mumble = handleTest ./mumble.nix {};
   munin = handleTest ./munin.nix {};
diff --git a/nixos/tests/mosquitto.nix b/nixos/tests/mosquitto.nix
new file mode 100644
index 00000000000..86b7f9c044d
--- /dev/null
+++ b/nixos/tests/mosquitto.nix
@@ -0,0 +1,69 @@
+import ./make-test.nix ({ pkgs, ... }:
+
+let
+  port = 1888;
+  username = "mqtt";
+  password = "VERY_secret";
+  topic = "test/foo";
+
+  cmd = bin: pkgs.lib.concatStringsSep " " [
+    "${pkgs.mosquitto}/bin/mosquitto_${bin}"
+    "-V mqttv311"
+    "-h server"
+    "-p ${toString port}"
+    "-u ${username}"
+    "-P '${password}'"
+    "-t ${topic}"
+  ];
+
+in rec {
+  name = "mosquitto";
+  meta = with pkgs.stdenv.lib; {
+    maintainers = with maintainers; [ peterhoeg ];
+  };
+
+  nodes = let
+    client = { pkgs, ... }: {
+      environment.systemPackages = with pkgs; [ mosquitto ];
+    };
+  in {
+    server = { pkgs, ... }: {
+      networking.firewall.allowedTCPPorts = [ port ];
+      services.mosquitto = {
+        inherit port;
+        enable = true;
+        host = "0.0.0.0";
+        checkPasswords = true;
+        users."${username}" = {
+          inherit password;
+          acl = [
+            "topic readwrite ${topic}"
+          ];
+        };
+      };
+    };
+
+    client1 = client;
+    client2 = client;
+  };
+
+  testScript = let
+    file = "/tmp/msg";
+    payload = "wootWOOT";
+  in ''
+    startAll;
+    $server->waitForUnit("mosquitto.service");
+
+    $server->fail("test -f ${file}");
+    $server->execute("(${cmd "sub"} -C 1 | tee ${file} &)");
+
+    $client1->fail("test -f ${file}");
+    $client1->execute("(${cmd "sub"} -C 1 | tee ${file} &)");
+
+    $client2->succeed("${cmd "pub"} -m ${payload}");
+
+    $server->succeed("grep -q ${payload} ${file}");
+
+    $client1->succeed("grep -q ${payload} ${file}");
+  '';
+})