nixos/mosquitto: add test
This commit is contained in:
parent
30e71f9cb8
commit
c5af9fd4dd
@ -143,6 +143,7 @@ in
|
|||||||
misc = handleTest ./misc.nix {};
|
misc = handleTest ./misc.nix {};
|
||||||
mongodb = handleTest ./mongodb.nix {};
|
mongodb = handleTest ./mongodb.nix {};
|
||||||
morty = handleTest ./morty.nix {};
|
morty = handleTest ./morty.nix {};
|
||||||
|
mosquitto = handleTest ./mosquitto.nix {};
|
||||||
mpd = handleTest ./mpd.nix {};
|
mpd = handleTest ./mpd.nix {};
|
||||||
mumble = handleTest ./mumble.nix {};
|
mumble = handleTest ./mumble.nix {};
|
||||||
munin = handleTest ./munin.nix {};
|
munin = handleTest ./munin.nix {};
|
||||||
|
69
nixos/tests/mosquitto.nix
Normal file
69
nixos/tests/mosquitto.nix
Normal file
@ -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}");
|
||||||
|
'';
|
||||||
|
})
|
Loading…
x
Reference in New Issue
Block a user