Add entropy_repo type/provider, with tests and docs
This commit is contained in:
61
spec/unit/provider/entropy_repo/file_spec.rb
Normal file
61
spec/unit/provider/entropy_repo/file_spec.rb
Normal file
@@ -0,0 +1,61 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Puppet::Type.type(:entropy_repo).provider(:file) do
|
||||
describe 'when fetching existing resources' do
|
||||
let(:instances) do
|
||||
described_class.instances
|
||||
end
|
||||
|
||||
let(:repos) do
|
||||
[
|
||||
{:name => 'sabayonlinux.org', :type => 'entropy', :enabled => 'true'},
|
||||
{:name => 'sabayon-limbo', :type => 'entropy', :enabled => 'false'},
|
||||
{:name => 'community', :type => 'enman', :enabled => 'true'},
|
||||
]
|
||||
end
|
||||
|
||||
before do
|
||||
Dir.stubs(:entries).with('/etc/entropy/repositories.conf.d/').returns([
|
||||
'.', '..', 'README',
|
||||
'entropy_sabayonlinux.org',
|
||||
'_entropy_sabayon-limbo',
|
||||
'entropy_enman_community',
|
||||
'entropy_foobar.example',
|
||||
])
|
||||
end
|
||||
|
||||
it 'should identify the correct number of repos' do
|
||||
expect(instances.size).to eq(repos.size)
|
||||
end
|
||||
|
||||
it 'should identify the correct repo name' do
|
||||
repos.each_with_index do |repo, index|
|
||||
expect(instances[index].name).to eq(repo[:name])
|
||||
end
|
||||
end
|
||||
|
||||
it 'should identify the correct enabled state' do
|
||||
repos.each_with_index do |repo, index|
|
||||
expect(instances[index].enabled).to eq(repo[:enabled])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when enabling a repository' do
|
||||
it 'should enable a disabled repository' do
|
||||
File.stubs(:exists?).with('/etc/entropy/repositories.conf.d/entropy_sabayonlinux.org').returns(true).once
|
||||
File.stubs(:rename).with('/etc/entropy/repositories.conf.d/entropy_sabayonlinux.org', '/etc/entropy/repositories.conf.d/_entropy_sabayonlinux.org').once
|
||||
instance = described_class.new(:name => 'sabayonlinux.org', :enabled => 'true', :type => 'entropy')
|
||||
instance.enabled = 'false'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when disabling a repository' do
|
||||
it 'should disable an enabled repository' do
|
||||
File.stubs(:exists?).with('/etc/entropy/repositories.conf.d/_entropy_sabayon-limbo').returns(true).once
|
||||
File.stubs(:rename).with('/etc/entropy/repositories.conf.d/_entropy_sabayon-limbo', '/etc/entropy/repositories.conf.d/entropy_sabayon-limbo').once
|
||||
instance = described_class.new(:name => 'sabayon-limbo', :enabled => 'false', :type => 'entropy')
|
||||
instance.enabled = 'true'
|
||||
end
|
||||
end
|
||||
end
|
||||
32
spec/unit/type/entropy_repo_spec.rb
Normal file
32
spec/unit/type/entropy_repo_spec.rb
Normal file
@@ -0,0 +1,32 @@
|
||||
describe Puppet::Type.type(:entropy_repo) do
|
||||
before do
|
||||
@provider = stub 'provider'
|
||||
@provider.stubs(:name).returns(:file)
|
||||
described_class.stubs(:defaultprovider).returns(@provider)
|
||||
end
|
||||
|
||||
it "should be an instance of Puppet::Type::Entropy_repo" do
|
||||
expect(described_class.new(:name => "test")).to be_an_instance_of Puppet::Type::Entropy_repo
|
||||
end
|
||||
|
||||
describe "when validating attributes" do
|
||||
params = [:name]
|
||||
properties = [:repo_type, :enabled]
|
||||
|
||||
params.each do |param|
|
||||
it "should have the #{param} param" do
|
||||
expect(described_class.attrtype(param)).to eq :param
|
||||
end
|
||||
end
|
||||
|
||||
properties.each do |property|
|
||||
it "should have the #{property} property" do
|
||||
expect(described_class.attrtype(property)).to eq :property
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "should have name as the namevar" do
|
||||
expect(described_class.key_attributes).to eq [:name]
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user