Debian Codegraph @

spec/unit/type/nova_config_spec.rb

raw
1 require 'puppet'
2 require 'puppet/type/nova_config'
3
4 describe 'Puppet::Type.type(:nova_config)' do
5 before :each do
6 @nova_config = Puppet::Type.type(:nova_config).new(:name => 'DEFAULT/foo', :value => 'bar')
7 end
8
9 it 'should require a name' do
10 expect {
11 Puppet::Type.type(:nova_config).new({})
12 }.to raise_error(Puppet::Error, 'Title or name must be provided')
13 end
14
15 it 'should not expect a name with whitespace' do
16 expect {
17 Puppet::Type.type(:nova_config).new(:name => 'f oo')
18 }.to raise_error(Puppet::Error, /Parameter name failed/)
19 end
20
21 it 'should fail when there is no section' do
22 expect {
23 Puppet::Type.type(:nova_config).new(:name => 'foo')
24 }.to raise_error(Puppet::Error, /Parameter name failed/)
25 end
26
27 it 'should not require a value when ensure is absent' do
28 Puppet::Type.type(:nova_config).new(:name => 'DEFAULT/foo', :ensure => :absent)
29 end
30
31 it 'should accept a valid value' do
32 @nova_config[:value] = 'bar'
33 expect(@nova_config[:value]).to eq(['bar'])
34 end
35
36 it 'should accept a value with whitespace' do
37 @nova_config[:value] = 'b ar'
38 expect(@nova_config[:value]).to eq(['b ar'])
39 end
40
41 it 'should accept valid ensure values' do
42 @nova_config[:ensure] = :present
43 expect(@nova_config[:ensure]).to eq(:present)
44 @nova_config[:ensure] = :absent
45 expect(@nova_config[:ensure]).to eq(:absent)
46 end
47
48 it 'should not accept invalid ensure values' do
49 expect {
50 @nova_config[:ensure] = :latest
51 }.to raise_error(Puppet::Error, /Invalid value/)
52 end
53
54 it 'should autorequire the package that install the file' do
55 catalog = Puppet::Resource::Catalog.new
56 anchor = Puppet::Type.type(:anchor).new(:name => 'nova::install::end')
57 catalog.add_resource anchor, @nova_config
58 dependency = @nova_config.autorequire
59 expect(dependency.size).to eq(1)
60 expect(dependency[0].target).to eq(@nova_config)
61 expect(dependency[0].source).to eq(anchor)
62 end
63
64 end