diff options
author | Pete Higgins <pete@peterhiggins.org> | 2020-03-11 18:07:04 -0700 |
---|---|---|
committer | Pete Higgins <pete@peterhiggins.org> | 2020-03-23 13:55:01 -0700 |
commit | 1bc1c904749997ca8696c575f880d0f50a8c05a6 (patch) | |
tree | 0594488043bfdf0ef0c30c43fff0fa0a46c347d2 /spec | |
parent | 1f629d3a004e45dfd25d06a46f565d52ac192c18 (diff) | |
download | chef-1bc1c904749997ca8696c575f880d0f50a8c05a6.tar.gz |
Update gem_package to make clear_sources opt-out.
Signed-off-by: Pete Higgins <pete@peterhiggins.org>
Diffstat (limited to 'spec')
-rw-r--r-- | spec/unit/provider/package/rubygems_spec.rb | 23 | ||||
-rw-r--r-- | spec/unit/resource/gem_package_spec.rb | 40 |
2 files changed, 57 insertions, 6 deletions
diff --git a/spec/unit/provider/package/rubygems_spec.rb b/spec/unit/provider/package/rubygems_spec.rb index 1bafefe5e8..1ef76c05c3 100644 --- a/spec/unit/provider/package/rubygems_spec.rb +++ b/spec/unit/provider/package/rubygems_spec.rb @@ -743,7 +743,7 @@ describe Chef::Provider::Package::Rubygems do let(:gem_binary) { "/foo/bar" } it "installs the gem with rubygems.org as an added source" do - expected = "#{gem_binary} install rspec-core -q --no-document -v \"#{target_version}\" --source=#{source} --source=https://www.rubygems.org" + expected = "#{gem_binary} install rspec-core -q --no-document -v \"#{target_version}\" --clear-sources --source=#{source} --source=https://www.rubygems.org" expect(provider).to receive(:shell_out_compacted!).with(expected, env: nil, timeout: 900) provider.run_action(:install) expect(new_resource).to be_updated_by_last_action @@ -754,7 +754,7 @@ describe Chef::Provider::Package::Rubygems do it "ignores the Chef::Config setting" do Chef::Config[:rubygems_url] = "https://ignored" - expected = "#{gem_binary} install rspec-core -q --no-document -v \"#{target_version}\" --source=#{source}" + expected = "#{gem_binary} install rspec-core -q --no-document -v \"#{target_version}\" --clear-sources --source=#{source}" expect(provider).to receive(:shell_out_compacted!).with(expected, env: nil, timeout: 900) provider.run_action(:install) expect(new_resource).to be_updated_by_last_action @@ -767,7 +767,7 @@ describe Chef::Provider::Package::Rubygems do let(:gem_binary) { "/foo/bar" } it "installs the gem with an array as an added source" do - expected = "#{gem_binary} install rspec-core -q --no-document -v \"#{target_version}\" --source=https://mirror1 --source=https://mirror2 --source=https://www.rubygems.org" + expected = "#{gem_binary} install rspec-core -q --no-document -v \"#{target_version}\" --clear-sources --source=https://mirror1 --source=https://mirror2 --source=https://www.rubygems.org" expect(provider).to receive(:shell_out_compacted!).with(expected, env: nil, timeout: 900) provider.run_action(:install) expect(new_resource).to be_updated_by_last_action @@ -778,7 +778,7 @@ describe Chef::Provider::Package::Rubygems do it "ignores the Chef::Config setting" do Chef::Config[:rubygems_url] = "https://ignored" - expected = "#{gem_binary} install rspec-core -q --no-document -v \"#{target_version}\" --source=https://mirror1 --source=https://mirror2" + expected = "#{gem_binary} install rspec-core -q --no-document -v \"#{target_version}\" --clear-sources --source=https://mirror1 --source=https://mirror2" expect(provider).to receive(:shell_out_compacted!).with(expected, env: nil, timeout: 900) provider.run_action(:install) expect(new_resource).to be_updated_by_last_action @@ -786,7 +786,7 @@ describe Chef::Provider::Package::Rubygems do end end - context "when we have cleared sources and an explict source is specified" do + context "when clear_sources is set true and an explict source is specified" do let(:gem_binary) { "/foo/bar" } let(:source) { "http://mirror.ops.rhcloud.com/mirror/ruby" } @@ -799,6 +799,19 @@ describe Chef::Provider::Package::Rubygems do end end + context "when clear_sources is set false and an explict source is specified" do + let(:gem_binary) { "/foo/bar" } + let(:source) { "http://mirror.ops.rhcloud.com/mirror/ruby" } + + it "installs the gem" do + new_resource.clear_sources(false) + expected = "#{gem_binary} install rspec-core -q --no-document -v \"#{target_version}\" --source=#{source} --source=https://www.rubygems.org" + expect(provider).to receive(:shell_out_compacted!).with(expected, env: nil, timeout: 900) + provider.run_action(:install) + expect(new_resource).to be_updated_by_last_action + end + end + context "when no version is given" do let(:target_version) { nil } let(:options) { "-i /alt/install/location" } diff --git a/spec/unit/resource/gem_package_spec.rb b/spec/unit/resource/gem_package_spec.rb index 949396abbc..5ecc2f46ca 100644 --- a/spec/unit/resource/gem_package_spec.rb +++ b/spec/unit/resource/gem_package_spec.rb @@ -53,7 +53,7 @@ describe Chef::Resource::GemPackage, "gem_binary" do end end -describe Chef::Resource::GemPackage, "clear_gem_sources" do +describe Chef::Resource::GemPackage, "clear_sources" do let(:resource) { Chef::Resource::GemPackage.new("foo") } it "is nil by default" do @@ -65,3 +65,41 @@ describe Chef::Resource::GemPackage, "clear_gem_sources" do expect(resource.clear_sources).to be true end end + +describe Chef::Resource::GemPackage, "clear_sources?" do + let(:resource) { Chef::Resource::GemPackage.new("foo") } + + it "is false when clear_sources is unset" do + expect(resource.clear_sources?).to be false + end + + it "is false when clear_sources is set false" do + resource.clear_sources(false) + expect(resource.clear_sources?).to be false + end + + it "is true when clear_sources is set true" do + resource.clear_sources(true) + expect(resource.clear_sources?).to be true + end + + context "when a source is set" do + before do + resource.source("http://mirror.ops.rhcloud.com/mirror/ruby") + end + + it "is true when clear_sources is unset" do + expect(resource.clear_sources?).to be true + end + + it "is false when clear_sources is set false" do + resource.clear_sources(false) + expect(resource.clear_sources?).to be false + end + + it "is true when clear_sources is set true" do + resource.clear_sources(true) + expect(resource.clear_sources?).to be true + end + end +end |