diff options
author | Jacek Galowicz <jacek.galowicz@cyberus-technology.de> | 2019-11-20 18:58:24 +0100 |
---|---|---|
committer | Jacek Galowicz <jacek.galowicz@cyberus-technology.de> | 2019-11-20 19:13:01 +0100 |
commit | 432f8a424b654955d01496db207cbcd6f10d587f (patch) | |
tree | bf2ea4bbe85a2db99b9597399f41b2469706de3b /nixos/tests/mosquitto.nix | |
parent | 4dba4db1db3ac4aaffc6fb5faaa4703ae59c0e6c (diff) | |
download | nixpkgs-432f8a424b654955d01496db207cbcd6f10d587f.tar nixpkgs-432f8a424b654955d01496db207cbcd6f10d587f.tar.gz nixpkgs-432f8a424b654955d01496db207cbcd6f10d587f.tar.bz2 nixpkgs-432f8a424b654955d01496db207cbcd6f10d587f.tar.lz nixpkgs-432f8a424b654955d01496db207cbcd6f10d587f.tar.xz nixpkgs-432f8a424b654955d01496db207cbcd6f10d587f.tar.zst nixpkgs-432f8a424b654955d01496db207cbcd6f10d587f.zip |
nixos/mosquitto: Refactor integration test code
Diffstat (limited to 'nixos/tests/mosquitto.nix')
-rw-r--r-- | nixos/tests/mosquitto.nix | 61 |
1 files changed, 28 insertions, 33 deletions
diff --git a/nixos/tests/mosquitto.nix b/nixos/tests/mosquitto.nix index 21df2a2ee1a..1f2fdf4237f 100644 --- a/nixos/tests/mosquitto.nix +++ b/nixos/tests/mosquitto.nix @@ -5,17 +5,6 @@ let 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 { name = "mosquitto"; meta = with pkgs.stdenv.lib; { @@ -49,9 +38,27 @@ in { testScript = let file = "/tmp/msg"; - sub = args: - "(${cmd "sub"} -C 1 ${args} | tee ${file} &)"; in '' + def mosquitto_cmd(binary): + return ( + "${pkgs.mosquitto}/bin/mosquitto_{} " + "-V mqttv311 " + "-h server " + "-p ${toString port} " + "-u ${username} " + "-P '${password}' " + "-t ${topic}" + ).format(binary) + + + def publish(args): + return "{} {}".format(mosquitto_cmd("pub"), args) + + + def subscribe(args): + return "({} -C 1 {} | tee ${file} &)".format(mosquitto_cmd("sub"), args) + + start_all() server.wait_for_unit("mosquitto.service") @@ -59,37 +66,25 @@ in { machine.fail("test -f ${file}") # QoS = 0, so only one subscribers should get it - server.execute( - "${sub "-q 0"}" - ) + server.execute(subscribe("-q 0")) # we need to give the subscribers some time to connect client2.execute("sleep 5") - client2.succeed( - "${cmd "pub"} -m FOO -q 0" - ) + client2.succeed(publish("-m FOO -q 0")) server.wait_until_succeeds("grep -q FOO ${file}") server.execute("rm ${file}") # QoS = 1, so both subscribers should get it - server.execute( - "${sub "-q 1"}" - ) - client1.execute( - "${sub "-q 1"}" - ) + server.execute(subscribe("-q 1")) + client1.execute(subscribe("-q 1")) # we need to give the subscribers some time to connect client2.execute("sleep 5") - client2.succeed( - "${cmd "pub"} -m BAR -q 1" - ) - - server.wait_until_succeeds("grep -q BAR ${file}") - server.execute("rm ${file}") + client2.succeed(publish("-m BAR -q 1")) - client1.wait_until_succeeds("grep -q BAR ${file}") - client1.execute("rm ${file}") + for machine in server, client1: + machine.wait_until_succeeds("grep -q BAR ${file}") + machine.execute("rm ${file}") ''; }) |