| 1 |
require 'puppet' |
| 2 |
require 'puppet/type/cloudkitty_config' |
| 3 |
describe 'Puppet::Type.type(:cloudkitty_config)' do |
| 4 |
before :each do |
| 5 |
@cloudkitty_config = Puppet::Type.type(:cloudkitty_config).new(:name => 'DEFAULT/foo', :value => 'bar') |
| 6 |
end |
| 7 |
|
| 8 |
it 'should require a name' do |
| 9 |
expect { |
| 10 |
Puppet::Type.type(:cloudkitty_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(:cloudkitty_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(:cloudkitty_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(:cloudkitty_config).new(:name => 'DEFAULT/foo', :ensure => :absent) |
| 28 |
end |
| 29 |
|
| 30 |
it 'should accept a valid value' do |
| 31 |
@cloudkitty_config[:value] = 'bar' |
| 32 |
expect(@cloudkitty_config[:value]).to eq(['bar']) |
| 33 |
end |
| 34 |
|
| 35 |
it 'should accept a value with whitespace' do |
| 36 |
@cloudkitty_config[:value] = 'b ar' |
| 37 |
expect(@cloudkitty_config[:value]).to eq(['b ar']) |
| 38 |
end |
| 39 |
|
| 40 |
it 'should accept valid ensure values' do |
| 41 |
@cloudkitty_config[:ensure] = :present |
| 42 |
expect(@cloudkitty_config[:ensure]).to eq(:present) |
| 43 |
@cloudkitty_config[:ensure] = :absent |
| 44 |
expect(@cloudkitty_config[:ensure]).to eq(:absent) |
| 45 |
end |
| 46 |
|
| 47 |
it 'should not accept invalid ensure values' do |
| 48 |
expect { |
| 49 |
@cloudkitty_config[:ensure] = :latest |
| 50 |
}.to raise_error(Puppet::Error, /Invalid value/) |
| 51 |
end |
| 52 |
|
| 53 |
it 'should autorequire the package that install the file' do |
| 54 |
catalog = Puppet::Resource::Catalog.new |
| 55 |
anchor = Puppet::Type.type(:anchor).new(:name => 'cloudkitty::install::end') |
| 56 |
catalog.add_resource anchor, @cloudkitty_config |
| 57 |
dependency = @cloudkitty_config.autorequire |
| 58 |
expect(dependency.size).to eq(1) |
| 59 |
expect(dependency[0].target).to eq(@cloudkitty_config) |
| 60 |
expect(dependency[0].source).to eq(anchor) |
| 61 |
end |
| 62 |
|
| 63 |
|
| 64 |
end |