Merge remote-tracking branch 'gfa/gfa/prosody'
[mirror/dsa-puppet.git] / 3rdparty / modules / prosody / spec / defines / virtualhost_spec.rb
1 require 'spec_helper'
2 require 'erb'
3
4 describe 'prosody::virtualhost' do
5   let(:pre_condition) do
6     'include ::prosody'
7   end
8   let(:facts) do
9     {
10       osfamily: 'SomeOS'
11     }
12   end
13   let(:title) { 'mockvirtualhost' }
14
15   before :each do
16     @path_avail = "/etc/prosody/conf.avail/#{title}.cfg.lua"
17     @path_link = "/etc/prosody/conf.d/#{title}.cfg.lua"
18   end
19
20   context 'with no parameters' do
21     it {
22       should contain_file(@path_avail).with(
23         ensure: 'present'
24       )
25     }
26
27     it {
28       should contain_file(@path_link).with(
29         ensure: 'link',
30         target: @path_avail,
31         require: "File[#{@path_avail}]"
32       )
33     }
34   end
35
36   context 'with ssl_key but no ssl_cert' do
37     let(:params) { { ssl_key: 'bananas' } }
38     it {
39       expect do
40         should contain_class('prosody')
41       end.to raise_error(Puppet::Error)
42     }
43   end
44
45   context 'with ssl_cert but no ssl_key' do
46     let(:params) { { ssl_cert: 'bananas' } }
47     it {
48       expect do
49         should contain_class('prosody')
50       end.to raise_error(Puppet::Error)
51     }
52   end
53
54   context 'with ssl keys and certs' do
55     let(:ssl_key) { '/etc/prosody/certs/rspec-puppet.com.key' }
56     let(:ssl_cert) { '/etc/prosody/certs/rspec-puppet.com.crt' }
57     let(:params) { { ssl_key: ssl_key, ssl_cert: ssl_cert } }
58
59     before :each do
60       @ssl_key = ssl_key
61       @ssl_cert = ssl_cert
62     end
63
64     it {
65       # This require statment is bananas
66       should contain_file(@path_avail).with(
67         ensure: 'present',
68         require: ['File[/etc/prosody/certs/mockvirtualhost.key]', 'File[/etc/prosody/certs/mockvirtualhost.crt]', 'Class[Prosody::Package]']
69       )
70
71       should contain_file('/etc/prosody/certs/mockvirtualhost.key').with_source(@ssl_key)
72       should contain_file('/etc/prosody/certs/mockvirtualhost.crt').with_source(@ssl_cert)
73     }
74   end
75
76   context 'ensure => absent' do
77     let(:params) { { ensure: 'absent' } }
78     it {
79       @ensure = 'absent'
80       should contain_file(@path_avail).with(
81         ensure: @ensure
82       )
83     }
84
85     it {
86       should contain_file(@path_link).with_ensure('absent')
87     }
88   end
89
90   context 'with custom options' do
91     let(:params) { { custom_options: { 'foo' => 'bar', 'baz' => 'quux' } } }
92     it {
93       should contain_file(@path_avail) \
94         .with_content(/^foo = "bar"$/, /^baz = "quux"$/)
95     }
96   end
97
98   context 'with deeply nested custom options' do
99     let(:params) { { custom_options: { 'foo' => { 'fnord' => '23', 'xyzzy' => '42' }, 'bar' => %w[cool elements], 'baz' => 'quux' } } }
100     it {
101       should contain_file(@path_avail) \
102         .with_content(/^foo = {\n  fnord = "23";\n  xyzzy = "42";\n}$/, /^baz = "quux"$/, /^bar = [ "cool"; "elements" ]$/)
103     }
104   end
105 end