Add missing unit tests for config type/resources

Change-Id: I51be077235021d786314a035e94281403120f26a
This commit is contained in:
Takashi Kajinami
2025-06-25 22:34:55 +09:00
parent 482d70d481
commit 777191f89b
6 changed files with 318 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
require 'spec_helper'
provider_class = Puppet::Type.type(:neutron_config).provider(:openstackconfig)
describe provider_class do
it 'should default to the default setting when no other one is specified' do
resource = Puppet::Type::Neutron_config.new(
{:name => 'DEFAULT/foo', :value => 'bar'}
)
provider = provider_class.new(resource)
expect(provider.section).to eq('DEFAULT')
expect(provider.setting).to eq('foo')
end
it 'should allow setting to be set explicitly' do
resource = Puppet::Type::Neutron_config.new(
{:name => 'dude/foo', :value => 'bar'}
)
provider = provider_class.new(resource)
expect(provider.section).to eq('dude')
expect(provider.setting).to eq('foo')
end
it 'should ensure absent when <SERVICE DEFAULT> is specified as a value' do
resource = Puppet::Type::Neutron_config.new(
{:name => 'dude/foo', :value => '<SERVICE DEFAULT>'}
)
provider = provider_class.new(resource)
provider.exists?
expect(resource[:ensure]).to eq :absent
end
it 'should ensure absent when value matches ensure_absent_val' do
resource = Puppet::Type::Neutron_config.new(
{:name => 'dude/foo', :value => 'foo', :ensure_absent_val => 'foo' }
)
provider = provider_class.new(resource)
provider.exists?
expect(resource[:ensure]).to eq :absent
end
end

View File

@@ -0,0 +1,41 @@
require 'spec_helper'
provider_class = Puppet::Type.type(:neutron_taas_service_config).provider(:openstackconfig)
describe provider_class do
it 'should default to the default setting when no other one is specified' do
resource = Puppet::Type::Neutron_taas_service_config.new(
{:name => 'DEFAULT/foo', :value => 'bar'}
)
provider = provider_class.new(resource)
expect(provider.section).to eq('DEFAULT')
expect(provider.setting).to eq('foo')
end
it 'should allow setting to be set explicitly' do
resource = Puppet::Type::Neutron_taas_service_config.new(
{:name => 'dude/foo', :value => 'bar'}
)
provider = provider_class.new(resource)
expect(provider.section).to eq('dude')
expect(provider.setting).to eq('foo')
end
it 'should ensure absent when <SERVICE DEFAULT> is specified as a value' do
resource = Puppet::Type::Neutron_taas_service_config.new(
{:name => 'dude/foo', :value => '<SERVICE DEFAULT>'}
)
provider = provider_class.new(resource)
provider.exists?
expect(resource[:ensure]).to eq :absent
end
it 'should ensure absent when value matches ensure_absent_val' do
resource = Puppet::Type::Neutron_taas_service_config.new(
{:name => 'dude/foo', :value => 'foo', :ensure_absent_val => 'foo' }
)
provider = provider_class.new(resource)
provider.exists?
expect(resource[:ensure]).to eq :absent
end
end

View File

@@ -0,0 +1,41 @@
require 'spec_helper'
provider_class = Puppet::Type.type(:neutron_vpnaas_service_config).provider(:openstackconfig)
describe provider_class do
it 'should default to the default setting when no other one is specified' do
resource = Puppet::Type::Neutron_vpnaas_service_config.new(
{:name => 'DEFAULT/foo', :value => 'bar'}
)
provider = provider_class.new(resource)
expect(provider.section).to eq('DEFAULT')
expect(provider.setting).to eq('foo')
end
it 'should allow setting to be set explicitly' do
resource = Puppet::Type::Neutron_vpnaas_service_config.new(
{:name => 'dude/foo', :value => 'bar'}
)
provider = provider_class.new(resource)
expect(provider.section).to eq('dude')
expect(provider.setting).to eq('foo')
end
it 'should ensure absent when <SERVICE DEFAULT> is specified as a value' do
resource = Puppet::Type::Neutron_vpnaas_service_config.new(
{:name => 'dude/foo', :value => '<SERVICE DEFAULT>'}
)
provider = provider_class.new(resource)
provider.exists?
expect(resource[:ensure]).to eq :absent
end
it 'should ensure absent when value matches ensure_absent_val' do
resource = Puppet::Type::Neutron_vpnaas_service_config.new(
{:name => 'dude/foo', :value => 'foo', :ensure_absent_val => 'foo' }
)
provider = provider_class.new(resource)
provider.exists?
expect(resource[:ensure]).to eq :absent
end
end

View File

@@ -0,0 +1,65 @@
require 'puppet'
require 'puppet/type/neutron_sriov_agent_config'
describe 'Puppet::Type.type(:neutron_sriov_agent_config)' do
before :each do
@neutron_sriov_agent_config = Puppet::Type.type(:neutron_sriov_agent_config).new(:name => 'DEFAULT/foo', :value => 'bar')
end
it 'should require a name' do
expect {
Puppet::Type.type(:neutron_sriov_agent_config).new({})
}.to raise_error(Puppet::Error, 'Title or name must be provided')
end
it 'should not expect a name with whitespace' do
expect {
Puppet::Type.type(:neutron_sriov_agent_config).new(:name => 'f oo')
}.to raise_error(Puppet::Error, /Parameter name failed/)
end
it 'should fail when there is no section' do
expect {
Puppet::Type.type(:neutron_sriov_agent_config).new(:name => 'foo')
}.to raise_error(Puppet::Error, /Parameter name failed/)
end
it 'should not require a value when ensure is absent' do
Puppet::Type.type(:neutron_sriov_agent_config).new(:name => 'DEFAULT/foo', :ensure => :absent)
end
it 'should accept a valid value' do
@neutron_sriov_agent_config[:value] = 'bar'
expect(@neutron_sriov_agent_config[:value]).to eq('bar')
end
it 'should accept a value with whitespace' do
@neutron_sriov_agent_config[:value] = 'b ar'
expect(@neutron_sriov_agent_config[:value]).to eq('b ar')
end
it 'should accept valid ensure values' do
@neutron_sriov_agent_config[:ensure] = :present
expect(@neutron_sriov_agent_config[:ensure]).to eq(:present)
@neutron_sriov_agent_config[:ensure] = :absent
expect(@neutron_sriov_agent_config[:ensure]).to eq(:absent)
end
it 'should not accept invalid ensure values' do
expect {
@neutron_sriov_agent_config[:ensure] = :latest
}.to raise_error(Puppet::Error, /Invalid value/)
end
it 'should autorequire the package that install the file' do
catalog = Puppet::Resource::Catalog.new
anchor = Puppet::Type.type(:anchor).new(:name => 'neutron::install::end')
catalog.add_resource anchor, @neutron_sriov_agent_config
dependency = @neutron_sriov_agent_config.autorequire
expect(dependency.size).to eq(1)
expect(dependency[0].target).to eq(@neutron_sriov_agent_config)
expect(dependency[0].source).to eq(anchor)
end
end

View File

@@ -0,0 +1,65 @@
require 'puppet'
require 'puppet/type/neutron_taas_service_config'
describe 'Puppet::Type.type(:neutron_taas_service_config)' do
before :each do
@neutron_taas_service_config = Puppet::Type.type(:neutron_taas_service_config).new(:name => 'DEFAULT/foo', :value => 'bar')
end
it 'should require a name' do
expect {
Puppet::Type.type(:neutron_taas_service_config).new({})
}.to raise_error(Puppet::Error, 'Title or name must be provided')
end
it 'should not expect a name with whitespace' do
expect {
Puppet::Type.type(:neutron_taas_service_config).new(:name => 'f oo')
}.to raise_error(Puppet::Error, /Parameter name failed/)
end
it 'should fail when there is no section' do
expect {
Puppet::Type.type(:neutron_taas_service_config).new(:name => 'foo')
}.to raise_error(Puppet::Error, /Parameter name failed/)
end
it 'should not require a value when ensure is absent' do
Puppet::Type.type(:neutron_taas_service_config).new(:name => 'DEFAULT/foo', :ensure => :absent)
end
it 'should accept a valid value' do
@neutron_taas_service_config[:value] = 'bar'
expect(@neutron_taas_service_config[:value]).to eq(['bar'])
end
it 'should accept a value with whitespace' do
@neutron_taas_service_config[:value] = 'b ar'
expect(@neutron_taas_service_config[:value]).to eq(['b ar'])
end
it 'should accept valid ensure values' do
@neutron_taas_service_config[:ensure] = :present
expect(@neutron_taas_service_config[:ensure]).to eq(:present)
@neutron_taas_service_config[:ensure] = :absent
expect(@neutron_taas_service_config[:ensure]).to eq(:absent)
end
it 'should not accept invalid ensure values' do
expect {
@neutron_taas_service_config[:ensure] = :latest
}.to raise_error(Puppet::Error, /Invalid value/)
end
it 'should autorequire the package that install the file' do
catalog = Puppet::Resource::Catalog.new
anchor = Puppet::Type.type(:anchor).new(:name => 'neutron::install::end')
catalog.add_resource anchor, @neutron_taas_service_config
dependency = @neutron_taas_service_config.autorequire
expect(dependency.size).to eq(1)
expect(dependency[0].target).to eq(@neutron_taas_service_config)
expect(dependency[0].source).to eq(anchor)
end
end

View File

@@ -0,0 +1,65 @@
require 'puppet'
require 'puppet/type/neutron_vpnaas_service_config'
describe 'Puppet::Type.type(:neutron_vpnaas_service_config)' do
before :each do
@neutron_vpnaas_service_config = Puppet::Type.type(:neutron_vpnaas_service_config).new(:name => 'DEFAULT/foo', :value => 'bar')
end
it 'should require a name' do
expect {
Puppet::Type.type(:neutron_vpnaas_service_config).new({})
}.to raise_error(Puppet::Error, 'Title or name must be provided')
end
it 'should not expect a name with whitespace' do
expect {
Puppet::Type.type(:neutron_vpnaas_service_config).new(:name => 'f oo')
}.to raise_error(Puppet::Error, /Parameter name failed/)
end
it 'should fail when there is no section' do
expect {
Puppet::Type.type(:neutron_vpnaas_service_config).new(:name => 'foo')
}.to raise_error(Puppet::Error, /Parameter name failed/)
end
it 'should not require a value when ensure is absent' do
Puppet::Type.type(:neutron_vpnaas_service_config).new(:name => 'DEFAULT/foo', :ensure => :absent)
end
it 'should accept a valid value' do
@neutron_vpnaas_service_config[:value] = 'bar'
expect(@neutron_vpnaas_service_config[:value]).to eq(['bar'])
end
it 'should accept a value with whitespace' do
@neutron_vpnaas_service_config[:value] = 'b ar'
expect(@neutron_vpnaas_service_config[:value]).to eq(['b ar'])
end
it 'should accept valid ensure values' do
@neutron_vpnaas_service_config[:ensure] = :present
expect(@neutron_vpnaas_service_config[:ensure]).to eq(:present)
@neutron_vpnaas_service_config[:ensure] = :absent
expect(@neutron_vpnaas_service_config[:ensure]).to eq(:absent)
end
it 'should not accept invalid ensure values' do
expect {
@neutron_vpnaas_service_config[:ensure] = :latest
}.to raise_error(Puppet::Error, /Invalid value/)
end
it 'should autorequire the package that install the file' do
catalog = Puppet::Resource::Catalog.new
anchor = Puppet::Type.type(:anchor).new(:name => 'neutron::install::end')
catalog.add_resource anchor, @neutron_vpnaas_service_config
dependency = @neutron_vpnaas_service_config.autorequire
expect(dependency.size).to eq(1)
expect(dependency[0].target).to eq(@neutron_vpnaas_service_config)
expect(dependency[0].source).to eq(anchor)
end
end