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