diff options
author | Peter Hoeg <peter@hoeg.com> | 2019-04-24 16:23:13 +0800 |
---|---|---|
committer | Peter Hoeg <peter@hoeg.com> | 2019-04-24 17:02:20 +0800 |
commit | c5af9fd4ddafc64edf74ffe7126eb60c80d635e7 (patch) | |
tree | f30597127f9c7dc9fb7e8a171b389ee11a82bee9 /nixos/tests/mosquitto.nix | |
parent | 30e71f9cb89c17de4fc0c945e8a2f53b375ffbaa (diff) | |
download | nixpkgs-c5af9fd4ddafc64edf74ffe7126eb60c80d635e7.tar nixpkgs-c5af9fd4ddafc64edf74ffe7126eb60c80d635e7.tar.gz nixpkgs-c5af9fd4ddafc64edf74ffe7126eb60c80d635e7.tar.bz2 nixpkgs-c5af9fd4ddafc64edf74ffe7126eb60c80d635e7.tar.lz nixpkgs-c5af9fd4ddafc64edf74ffe7126eb60c80d635e7.tar.xz nixpkgs-c5af9fd4ddafc64edf74ffe7126eb60c80d635e7.tar.zst nixpkgs-c5af9fd4ddafc64edf74ffe7126eb60c80d635e7.zip |
nixos/mosquitto: add test
Diffstat (limited to 'nixos/tests/mosquitto.nix')
-rw-r--r-- | nixos/tests/mosquitto.nix | 69 |
1 files changed, 69 insertions, 0 deletions
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}"); + ''; +}) |