|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +describe 'os_transport_url' do |
| 4 | + |
| 5 | + it 'refuses String' do |
| 6 | + is_expected.to run.with_params('foo').\ |
| 7 | + and_raise_error(Puppet::ParseError, /Requires an hash/) |
| 8 | + end |
| 9 | + |
| 10 | + it 'refuses Array' do |
| 11 | + is_expected.to run.with_params(['foo']).\ |
| 12 | + and_raise_error(Puppet::ParseError, /Requires an hash/) |
| 13 | + end |
| 14 | + |
| 15 | + it 'refuses without at least one argument' do |
| 16 | + is_expected.to run.with_params().\ |
| 17 | + and_raise_error(ArgumentError, /Wrong number of arguments/) |
| 18 | + end |
| 19 | + |
| 20 | + it 'refuses too many arguments' do |
| 21 | + is_expected.to run.with_params('foo', 'bar').\ |
| 22 | + and_raise_error(ArgumentError, /Wrong number of arguments/) |
| 23 | + end |
| 24 | + |
| 25 | + it 'refuses hosts params passed as String' do |
| 26 | + is_expected.to run.with_params({ |
| 27 | + 'transport'=> 'rabbit', |
| 28 | + 'hosts' => '127.0.0.1', |
| 29 | + }).and_raise_error(Puppet::ParseError, /hosts should be a Array/) |
| 30 | + end |
| 31 | + |
| 32 | + it 'fails if missing host' do |
| 33 | + is_expected.to run.with_params({ |
| 34 | + 'transport'=> 'rabbit', |
| 35 | + }).and_raise_error(Puppet::ParseError, /host or hosts is required/) |
| 36 | + end |
| 37 | + |
| 38 | + context 'creates the correct transport URI' do |
| 39 | + |
| 40 | + it 'with all params for a single host' do |
| 41 | + is_expected.to run.with_params({ |
| 42 | + 'transport' => 'rabbit', |
| 43 | + 'host' => '127.0.0.1', |
| 44 | + 'port' => '5672', |
| 45 | + 'username' => 'guest', |
| 46 | + 'password' => 's3cr3t', |
| 47 | + 'virtual_host' => 'virt', |
| 48 | + 'ssl' => '1', |
| 49 | + 'query' => { 'read_timeout' => '60' }, |
| 50 | + }).and_return('rabbit://guest:s3cr3t@127.0.0.1:5672/virt?read_timeout=60&ssl=1') |
| 51 | + end |
| 52 | + |
| 53 | + it 'with only required params for a single host' do |
| 54 | + is_expected.to run.with_params({ |
| 55 | + 'transport' => 'rabbit', |
| 56 | + 'host' => '127.0.0.1', |
| 57 | + }).and_return('rabbit://127.0.0.1/') |
| 58 | + end |
| 59 | + |
| 60 | + it 'with a single ipv6 address' do |
| 61 | + is_expected.to run.with_params({ |
| 62 | + 'transport' => 'rabbit', |
| 63 | + 'host' => 'fe80::ca5b:76ff:fe4b:be3b', |
| 64 | + 'port' => '5672' |
| 65 | + }).and_return('rabbit://[fe80::ca5b:76ff:fe4b:be3b]:5672/') |
| 66 | + end |
| 67 | + |
| 68 | + it 'with all params with multiple hosts' do |
| 69 | + is_expected.to run.with_params({ |
| 70 | + 'transport' => 'rabbit', |
| 71 | + 'hosts' => ['1.1.1.1', '2.2.2.2'], |
| 72 | + 'port' => '5672', |
| 73 | + 'username' => 'guest', |
| 74 | + 'password' => 's3cr3t', |
| 75 | + 'virtual_host' => 'virt', |
| 76 | + 'query' => { 'read_timeout' => '60' }, |
| 77 | + }).and_return('rabbit://guest:s3cr3t@1.1.1.1:5672,guest:s3cr3t@2.2.2.2:5672/virt?read_timeout=60') |
| 78 | + end |
| 79 | + |
| 80 | + it 'with only required params for multiple hosts' do |
| 81 | + is_expected.to run.with_params({ |
| 82 | + 'transport' => 'rabbit', |
| 83 | + 'hosts' => [ '1.1.1.1', '2.2.2.2' ], |
| 84 | + 'port' => '5672', |
| 85 | + 'username' => 'guest', |
| 86 | + 'password' => 's3cr3t', |
| 87 | + }).and_return('rabbit://guest:s3cr3t@1.1.1.1:5672,guest:s3cr3t@2.2.2.2:5672/') |
| 88 | + end |
| 89 | + |
| 90 | + it 'with multiple ipv6 hosts' do |
| 91 | + is_expected.to run.with_params({ |
| 92 | + 'transport' => 'rabbit', |
| 93 | + 'hosts' => [ 'fe80::ca5b:76ff:fe4b:be3b', 'fe80::ca5b:76ff:fe4b:be3c' ], |
| 94 | + 'port' => '5672', |
| 95 | + 'username' => 'guest', |
| 96 | + 'password' => 's3cr3t', |
| 97 | + }).and_return('rabbit://guest:s3cr3t@[fe80::ca5b:76ff:fe4b:be3b]:5672,guest:s3cr3t@[fe80::ca5b:76ff:fe4b:be3c]:5672/') |
| 98 | + end |
| 99 | + |
| 100 | + it 'with a mix of ipv4 and ipv6 hosts' do |
| 101 | + is_expected.to run.with_params({ |
| 102 | + 'transport' => 'rabbit', |
| 103 | + 'hosts' => [ 'fe80::ca5b:76ff:fe4b:be3b', '1.1.1.1' ], |
| 104 | + 'port' => '5672', |
| 105 | + 'username' => 'guest', |
| 106 | + 'password' => 's3cr3t', |
| 107 | + }).and_return('rabbit://guest:s3cr3t@[fe80::ca5b:76ff:fe4b:be3b]:5672,guest:s3cr3t@1.1.1.1:5672/') |
| 108 | + end |
| 109 | + |
| 110 | + it 'without port' do |
| 111 | + is_expected.to run.with_params({ |
| 112 | + 'transport' => 'rabbit', |
| 113 | + 'host' => '127.0.0.1', |
| 114 | + 'username' => 'guest', |
| 115 | + 'password' => 's3cr3t', |
| 116 | + 'virtual_host' => 'virt', |
| 117 | + 'query' => { 'read_timeout' => '60' }, |
| 118 | + }).and_return('rabbit://guest:s3cr3t@127.0.0.1/virt?read_timeout=60') |
| 119 | + end |
| 120 | + |
| 121 | + it 'without port and query' do |
| 122 | + is_expected.to run.with_params({ |
| 123 | + 'transport' => 'rabbit', |
| 124 | + 'host' => '127.0.0.1', |
| 125 | + 'username' => 'guest', |
| 126 | + 'password' => 's3cr3t', |
| 127 | + 'virtual_host' => 'virt', |
| 128 | + }).and_return('rabbit://guest:s3cr3t@127.0.0.1/virt') |
| 129 | + end |
| 130 | + |
| 131 | + it 'without username and password' do |
| 132 | + is_expected.to run.with_params({ |
| 133 | + 'transport' => 'rabbit', |
| 134 | + 'host' => '127.0.0.1', |
| 135 | + 'port' => '5672', |
| 136 | + 'virtual_host' => 'virt', |
| 137 | + 'query' => { 'read_timeout' => '60' }, |
| 138 | + }).and_return('rabbit://127.0.0.1:5672/virt?read_timeout=60') |
| 139 | + end |
| 140 | + |
| 141 | + it 'with username set to undef' do |
| 142 | + is_expected.to run.with_params({ |
| 143 | + 'transport' => 'rabbit', |
| 144 | + 'host' => '127.0.0.1', |
| 145 | + 'port' => '5672', |
| 146 | + 'username' => :undef, |
| 147 | + 'virtual_host' => 'virt', |
| 148 | + 'query' => { 'read_timeout' => '60' }, |
| 149 | + }).and_return('rabbit://127.0.0.1:5672/virt?read_timeout=60') |
| 150 | + end |
| 151 | + |
| 152 | + it 'with username set to an empty string' do |
| 153 | + is_expected.to run.with_params({ |
| 154 | + 'transport' => 'rabbit', |
| 155 | + 'host' => '127.0.0.1', |
| 156 | + 'port' => '5672', |
| 157 | + 'username' => '', |
| 158 | + 'virtual_host' => 'virt', |
| 159 | + 'query' => { 'read_timeout' => '60' }, |
| 160 | + }).and_return('rabbit://127.0.0.1:5672/virt?read_timeout=60') |
| 161 | + end |
| 162 | + |
| 163 | + it 'without password' do |
| 164 | + is_expected.to run.with_params({ |
| 165 | + 'transport' => 'rabbit', |
| 166 | + 'host' => '127.0.0.1', |
| 167 | + 'port' => '5672', |
| 168 | + 'username' => 'guest', |
| 169 | + 'virtual_host' => 'virt', |
| 170 | + 'query' => { 'read_timeout' => '60' }, |
| 171 | + }).and_return('rabbit://guest@127.0.0.1:5672/virt?read_timeout=60') |
| 172 | + end |
| 173 | + |
| 174 | + it 'with password set to undef' do |
| 175 | + is_expected.to run.with_params({ |
| 176 | + 'transport' => 'rabbit', |
| 177 | + 'host' => '127.0.0.1', |
| 178 | + 'port' => '5672', |
| 179 | + 'username' => 'guest', |
| 180 | + 'password' => :undef, |
| 181 | + 'virtual_host' => 'virt', |
| 182 | + 'query' => { 'read_timeout' => '60' }, |
| 183 | + }).and_return('rabbit://guest@127.0.0.1:5672/virt?read_timeout=60') |
| 184 | + end |
| 185 | + |
| 186 | + it 'with password set to an empty string' do |
| 187 | + is_expected.to run.with_params({ |
| 188 | + 'transport' => 'rabbit', |
| 189 | + 'host' => '127.0.0.1', |
| 190 | + 'port' => '5672', |
| 191 | + 'username' => 'guest', |
| 192 | + 'password' => '', |
| 193 | + 'virtual_host' => 'virt', |
| 194 | + 'query' => { 'read_timeout' => '60' }, |
| 195 | + }).and_return('rabbit://guest@127.0.0.1:5672/virt?read_timeout=60') |
| 196 | + end |
| 197 | + |
| 198 | + it 'with ssl overrides ssl in querty hash' do |
| 199 | + is_expected.to run.with_params({ |
| 200 | + 'transport' => 'rabbit', |
| 201 | + 'host' => '127.0.0.1', |
| 202 | + 'port' => '5672', |
| 203 | + 'username' => 'guest', |
| 204 | + 'password' => '', |
| 205 | + 'virtual_host' => 'virt', |
| 206 | + 'ssl' => '1', |
| 207 | + 'query' => { 'read_timeout' => '60' , 'ssl' => '0'}, |
| 208 | + }).and_return('rabbit://guest@127.0.0.1:5672/virt?read_timeout=60&ssl=1') |
| 209 | + end |
| 210 | + |
| 211 | + end |
| 212 | +end |
0 commit comments