353fff087b5fa9bd48f656b54817beacfe5ad78d
[mirror/dsa-puppet.git] / 3rdparty / modules / nova / spec / unit / type / nova_config_spec.rb
1 require 'puppet'
2 require 'puppet/type/nova_config'
3 describe 'Puppet::Type.type(:nova_config)' do
4   before :each do
5     @nova_config = Puppet::Type.type(:nova_config).new(:name => 'DEFAULT/foo', :value => 'bar')
6   end
7
8   it 'should require a name' do
9     expect {
10       Puppet::Type.type(:nova_config).new({})
11     }.to raise_error(Puppet::Error, 'Title or name must be provided')
12   end
13
14   it 'should not expect a name with whitespace' do
15     expect {
16       Puppet::Type.type(:nova_config).new(:name => 'f oo')
17     }.to raise_error(Puppet::Error, /Parameter name failed/)
18   end
19
20   it 'should fail when there is no section' do
21     expect {
22       Puppet::Type.type(:nova_config).new(:name => 'foo')
23     }.to raise_error(Puppet::Error, /Parameter name failed/)
24   end
25
26   it 'should not require a value when ensure is absent' do
27     Puppet::Type.type(:nova_config).new(:name => 'DEFAULT/foo', :ensure => :absent)
28   end
29
30   it 'should accept a valid value' do
31     @nova_config[:value] = 'bar'
32     @nova_config[:value].should == 'bar'
33   end
34
35   it 'should not accept a value with whitespace' do
36     @nova_config[:value] = 'b ar'
37     @nova_config[:value].should == 'b ar'
38   end
39
40   it 'should accept valid ensure values' do
41     @nova_config[:ensure] = :present
42     @nova_config[:ensure].should == :present
43     @nova_config[:ensure] = :absent
44     @nova_config[:ensure].should == :absent
45   end
46
47   it 'should not accept invalid ensure values' do
48     expect {
49       @nova_config[:ensure] = :latest
50     }.to raise_error(Puppet::Error, /Invalid value/)
51   end
52 end