X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=3rdparty%2Fmodules%2Fprosody%2Fspec%2Fdefines%2Fvirtualhost_spec.rb;fp=3rdparty%2Fmodules%2Fprosody%2Fspec%2Fdefines%2Fvirtualhost_spec.rb;h=d3b31cb91ff455abc8304d8bd8b7746b1b83ccc2;hb=bca90484ee186c3159f57f14a609e1e8d63575be;hp=0000000000000000000000000000000000000000;hpb=9e27d3f0aaa21b93d9d256414dcd6335b07c0f53;p=mirror%2Fdsa-puppet.git diff --git a/3rdparty/modules/prosody/spec/defines/virtualhost_spec.rb b/3rdparty/modules/prosody/spec/defines/virtualhost_spec.rb new file mode 100644 index 000000000..d3b31cb91 --- /dev/null +++ b/3rdparty/modules/prosody/spec/defines/virtualhost_spec.rb @@ -0,0 +1,105 @@ +require 'spec_helper' +require 'erb' + +describe 'prosody::virtualhost' do + let(:pre_condition) do + 'include ::prosody' + end + let(:facts) do + { + osfamily: 'SomeOS' + } + end + let(:title) { 'mockvirtualhost' } + + before :each do + @path_avail = "/etc/prosody/conf.avail/#{title}.cfg.lua" + @path_link = "/etc/prosody/conf.d/#{title}.cfg.lua" + end + + context 'with no parameters' do + it { + should contain_file(@path_avail).with( + ensure: 'present' + ) + } + + it { + should contain_file(@path_link).with( + ensure: 'link', + target: @path_avail, + require: "File[#{@path_avail}]" + ) + } + end + + context 'with ssl_key but no ssl_cert' do + let(:params) { { ssl_key: 'bananas' } } + it { + expect do + should contain_class('prosody') + end.to raise_error(Puppet::Error) + } + end + + context 'with ssl_cert but no ssl_key' do + let(:params) { { ssl_cert: 'bananas' } } + it { + expect do + should contain_class('prosody') + end.to raise_error(Puppet::Error) + } + end + + context 'with ssl keys and certs' do + let(:ssl_key) { '/etc/prosody/certs/rspec-puppet.com.key' } + let(:ssl_cert) { '/etc/prosody/certs/rspec-puppet.com.crt' } + let(:params) { { ssl_key: ssl_key, ssl_cert: ssl_cert } } + + before :each do + @ssl_key = ssl_key + @ssl_cert = ssl_cert + end + + it { + # This require statment is bananas + should contain_file(@path_avail).with( + ensure: 'present', + require: ['File[/etc/prosody/certs/mockvirtualhost.key]', 'File[/etc/prosody/certs/mockvirtualhost.crt]', 'Class[Prosody::Package]'] + ) + + should contain_file('/etc/prosody/certs/mockvirtualhost.key').with_source(@ssl_key) + should contain_file('/etc/prosody/certs/mockvirtualhost.crt').with_source(@ssl_cert) + } + end + + context 'ensure => absent' do + let(:params) { { ensure: 'absent' } } + it { + @ensure = 'absent' + should contain_file(@path_avail).with( + ensure: @ensure + ) + } + + it { + should contain_file(@path_link).with_ensure('absent') + } + end + + context 'with custom options' do + let(:params) { { custom_options: { 'foo' => 'bar', 'baz' => 'quux' } } } + it { + should contain_file(@path_avail) \ + .with_content(/^foo = "bar"$/, /^baz = "quux"$/) + } + end + + context 'with deeply nested custom options' do + let(:params) { { custom_options: { 'foo' => { 'fnord' => '23', 'xyzzy' => '42' }, 'bar' => %w[cool elements], 'baz' => 'quux' } } } + it { + should contain_file(@path_avail) \ + .with_content(/^foo = {\n fnord = "23";\n xyzzy = "42";\n}$/, /^baz = "quux"$/, /^bar = [ "cool"; "elements" ]$/) + } + end +end