diff options
author | Tim Smith <tsmith@chef.io> | 2017-12-18 17:57:41 -0800 |
---|---|---|
committer | Tim Smith <tsmith@chef.io> | 2017-12-18 17:57:41 -0800 |
commit | 98eee03ef7649475bf0a1fa1dba574732078b391 (patch) | |
tree | e9ed338200d7d9fc72f53db0df6f240d09c20d25 /spec | |
parent | 13581a1c2e30950d68682bea2a9e36f9b51bc0ca (diff) | |
download | chef-98eee03ef7649475bf0a1fa1dba574732078b391.tar.gz |
Improve the yum_repository resource specs
Signed-off-by: Tim Smith <tsmith@chef.io>
Diffstat (limited to 'spec')
-rw-r--r-- | spec/unit/resource/yum_repository_spec.rb | 62 | ||||
-rw-r--r-- | spec/unit/resource/zypper_repository_spec.rb | 8 |
2 files changed, 61 insertions, 9 deletions
diff --git a/spec/unit/resource/yum_repository_spec.rb b/spec/unit/resource/yum_repository_spec.rb index 5de2955b83..c3732c2eab 100644 --- a/spec/unit/resource/yum_repository_spec.rb +++ b/spec/unit/resource/yum_repository_spec.rb @@ -24,12 +24,64 @@ describe Chef::Resource::YumRepository do let(:run_context) { Chef::RunContext.new(node, {}, events) } let(:resource) { Chef::Resource::YumRepository.new("multiverse", run_context) } - context "on linux", :linux_only do - it "creates a new Chef::Resource::YumRepository" do - expect(resource).to be_a_kind_of(Chef::Resource) - expect(resource).to be_a_kind_of(Chef::Resource::YumRepository) - end + it "has a resource_name of :yum_repository" do + expect(resource.resource_name).to eq(:yum_repository) + end + + it "the repositoryid property is the name_property" do + expect(resource.repositoryid).to eq("multiverse") + end + + it "the timeout property expects numeric Strings" do + expect { resource.timeout "123" }.not_to raise_error(ArgumentError) + expect { resource.timeout "123foo" }.to raise_error(ArgumentError) + end + + it "the priority property expects numeric Strings from '1' to '99'" do + expect { resource.priority "99" }.not_to raise_error(ArgumentError) + expect { resource.priority "1" }.not_to raise_error(ArgumentError) + expect { resource.priority "100" }.to raise_error(ArgumentError) + end + + it "the failovermethod property accepts 'priority' or 'roundrobin'" do + expect { resource.failovermethod "priority" }.not_to raise_error(ArgumentError) + expect { resource.failovermethod "roundrobin" }.not_to raise_error(ArgumentError) + expect { resource.failovermethod "bob" }.to raise_error(ArgumentError) + end + + it "the http_caching property accepts 'packages', 'all', or 'none'" do + expect { resource.http_caching "packages" }.not_to raise_error(ArgumentError) + expect { resource.http_caching "all" }.not_to raise_error(ArgumentError) + expect { resource.http_caching "none" }.not_to raise_error(ArgumentError) + expect { resource.http_caching "bob" }.to raise_error(ArgumentError) + end + + it "the metadata_expire property accepts a time value or 'never'" do + expect { resource.metadata_expire "100" }.not_to raise_error(ArgumentError) + expect { resource.metadata_expire "100d" }.not_to raise_error(ArgumentError) + expect { resource.metadata_expire "100h" }.not_to raise_error(ArgumentError) + expect { resource.metadata_expire "100m" }.not_to raise_error(ArgumentError) + expect { resource.metadata_expire "never" }.not_to raise_error(ArgumentError) + expect { resource.metadata_expire "100s" }.to raise_error(ArgumentError) + end + it "the mirror_expire property accepts a time value" do + expect { resource.mirror_expire "100" }.not_to raise_error(ArgumentError) + expect { resource.mirror_expire "100d" }.not_to raise_error(ArgumentError) + expect { resource.mirror_expire "100h" }.not_to raise_error(ArgumentError) + expect { resource.mirror_expire "100m" }.not_to raise_error(ArgumentError) + expect { resource.mirror_expire "never" }.to raise_error(ArgumentError) + end + + it "the mirrorlist_expire property accepts a time value" do + expect { resource.mirrorlist_expire "100" }.not_to raise_error(ArgumentError) + expect { resource.mirrorlist_expire "100d" }.not_to raise_error(ArgumentError) + expect { resource.mirrorlist_expire "100h" }.not_to raise_error(ArgumentError) + expect { resource.mirrorlist_expire "100m" }.not_to raise_error(ArgumentError) + expect { resource.mirrorlist_expire "never" }.to raise_error(ArgumentError) + end + + context "on linux", :linux_only do it "resolves to a Noop class when yum is not found" do expect(Chef::Provider::YumRepository).to receive(:which).with("yum").and_return(false) expect(resource.provider_for_action(:add)).to be_a(Chef::Provider::Noop) diff --git a/spec/unit/resource/zypper_repository_spec.rb b/spec/unit/resource/zypper_repository_spec.rb index d18b83cc2d..0758c2513f 100644 --- a/spec/unit/resource/zypper_repository_spec.rb +++ b/spec/unit/resource/zypper_repository_spec.rb @@ -38,13 +38,13 @@ describe Chef::Resource::ZypperRepository do end it "aliases the uri property to baseurl" do - resource.uri = 'something' - expect(resource.baseurl).to eql('something') + resource.uri = "something" + expect(resource.baseurl).to eql("something") end it "aliases the key property to gpgkey" do - resource.key = 'something' - expect(resource.gpgkey).to eql('something') + resource.key = "something" + expect(resource.gpgkey).to eql("something") end it "supports all valid actions" do |