1# This test runs rabbitmq and checks if rabbitmq is up and running.
2
3import ./make-test-python.nix (
4 { pkgs, ... }:
5 let
6 # in real life, you would keep this out of your repo and deploy it to a safe
7 # location using safe means.
8 configKeyPath = pkgs.writeText "fake-config-key" "hOjWzSEn2Z7cHzKOcf6i183O2NdjurSuoMDIIv01";
9 in
10 {
11 name = "rabbitmq";
12 meta = with pkgs.lib.maintainers; {
13 maintainers = [ offline ];
14 };
15
16 nodes.machine = {
17 services.rabbitmq = {
18 enable = true;
19 managementPlugin.enable = true;
20
21 # To encrypt:
22 # rabbitmqctl --quiet encode --cipher blowfish_cfb64 --hash sha256 \
23 # --iterations 10000 '<<"dJT8isYu6t0Xb6u56rPglSj1vK51SlNVlXfwsRxw">>' \
24 # "hOjWzSEn2Z7cHzKOcf6i183O2NdjurSuoMDIIv01" ;
25 config = ''
26 [ { rabbit
27 , [ {default_user, <<"alice">>}
28 , { default_pass
29 , {encrypted,<<"oKKxyTze9PYmsEfl6FG1MxIUhxY7WPQL7HBoMPRC/1ZOdOZbtr9+DxjWW3e1D5SL48n3D9QOsGD0cOgYG7Qdvb7Txrepw8w=">>}
30 }
31 , {config_entry_decoder
32 , [ {passphrase, {file, <<"${configKeyPath}">>}}
33 , {cipher, blowfish_cfb64}
34 , {hash, sha256}
35 , {iterations, 10000}
36 ]
37 }
38 % , {rabbitmq_management, [{path_prefix, "/_queues"}]}
39 ]
40 }
41 ].
42 '';
43 };
44 # Ensure there is sufficient extra disk space for rabbitmq to be happy
45 virtualisation.diskSize = 1024;
46 };
47
48 testScript = ''
49 machine.start()
50
51 machine.wait_for_unit("rabbitmq.service")
52 machine.wait_until_succeeds(
53 'su -s ${pkgs.runtimeShell} rabbitmq -c "rabbitmqctl status"'
54 )
55 machine.wait_for_open_port(15672)
56
57 # The password is the plaintext that was encrypted with rabbitmqctl encode above.
58 machine.wait_until_succeeds(
59 'echo Hello World | ${pkgs.lib.getExe pkgs.amqpcat} --producer --uri=amqp://alice:dJT8isYu6t0Xb6u56rPglSj1vK51SlNVlXfwsRxw@localhost --queue test'
60 )
61 '';
62 }
63)