diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/data/mixin/invalid_data.rb | 3 | ||||
-rw-r--r-- | spec/data/mixin/real_data.rb | 2 | ||||
-rw-r--r-- | spec/functional/mixin/from_file_spec.rb | 82 | ||||
-rw-r--r-- | spec/integration/recipes/resource_action_spec.rb | 95 | ||||
-rw-r--r-- | spec/unit/provider/apt_repository_spec.rb | 12 | ||||
-rw-r--r-- | spec/unit/resource/remote_file_spec.rb | 2 | ||||
-rw-r--r-- | spec/unit/resource_reporter_spec.rb | 2 |
7 files changed, 88 insertions, 110 deletions
diff --git a/spec/data/mixin/invalid_data.rb b/spec/data/mixin/invalid_data.rb new file mode 100644 index 0000000000..e6f6c3a783 --- /dev/null +++ b/spec/data/mixin/invalid_data.rb @@ -0,0 +1,3 @@ +# For spec/functional/mixin/from_file_spec.rb +a :foo +c :bar diff --git a/spec/data/mixin/real_data.rb b/spec/data/mixin/real_data.rb new file mode 100644 index 0000000000..e15b86fc68 --- /dev/null +++ b/spec/data/mixin/real_data.rb @@ -0,0 +1,2 @@ +# For spec/functional/mixin/from_file_spec.rb +a :foo diff --git a/spec/functional/mixin/from_file_spec.rb b/spec/functional/mixin/from_file_spec.rb new file mode 100644 index 0000000000..a279f48790 --- /dev/null +++ b/spec/functional/mixin/from_file_spec.rb @@ -0,0 +1,82 @@ +# +# Copyright:: Copyright 2014-2018, Chef Software, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require "spec_helper" + +describe Chef::Mixin::FromFile do + REAL_DATA = File.join(CHEF_SPEC_DATA, "mixin", "real_data.rb") + INVALID_DATA = File.join(CHEF_SPEC_DATA, "mixin", "invalid_data.rb") + NO_DATA = File.join(CHEF_SPEC_DATA, "mixin", "non_existant_data.rb") + + class TestData + include Chef::Mixin::FromFile + + def a(a = nil) + @a = a if a + @a + end + end + + class ClassTestData + class <<self + include Chef::Mixin::FromFile + + def a(a = nil) + @a = a if a + @a + end + end + end + + describe "from_file" do + it "should load data" do + datum = TestData.new + datum.from_file(REAL_DATA) + expect(datum.a).to eq(:foo) + end + + it "should load class data" do + datum = ClassTestData + datum.class_from_file(REAL_DATA) + expect(datum.a).to eq(:foo) + end + + it "should set source_file" do + datum = TestData.new + datum.from_file(REAL_DATA) + expect(datum.source_file).to eq(REAL_DATA) + end + + it "should set class source_file" do + datum = ClassTestData + datum.class_from_file(REAL_DATA) + expect(datum.source_file).to eq(REAL_DATA) + end + + it "should fail on invalid data" do + datum = TestData.new + expect do + datum.from_file(INVALID_DATA) + end.to raise_error(NoMethodError) + end + + it "should fail on nonexistant data" do + datum = TestData.new + expect { datum.from_file(NO_DATA) }.to raise_error(IOError) + end + end +end diff --git a/spec/integration/recipes/resource_action_spec.rb b/spec/integration/recipes/resource_action_spec.rb index d6ea4347c4..149b17fcad 100644 --- a/spec/integration/recipes/resource_action_spec.rb +++ b/spec/integration/recipes/resource_action_spec.rb @@ -378,94 +378,6 @@ module ResourceActionSpec end end - context "With a resource with property x" do - class ResourceActionSpecWithX < Chef::Resource - resource_name :resource_action_spec_with_x - property :x, default: 20 - action :set do - # Access x during converge to ensure that we emit no warnings there - x - end - end - - context "And another resource with a property x and an action that sets property x to its value" do - class ResourceActionSpecAlsoWithX < Chef::Resource - resource_name :resource_action_spec_also_with_x - property :x - action :set_x_to_x do - resource_action_spec_with_x "hi" do - x x - end - end - def self.x_warning_line - __LINE__ - 4 - end - action :set_x_to_x_in_non_initializer do - r = resource_action_spec_with_x "hi" do - x 10 - end - x_times_2 = r.x * 2 - end - action :set_x_to_10 do - resource_action_spec_with_x "hi" do - x 10 - end - end - end - - attr_reader :x_warning_line - - it "Using the enclosing resource to set x to x emits a warning that you're using the wrong x" do - Chef::Config[:treat_deprecation_warnings_as_errors] = false - recipe = converge do - resource_action_spec_also_with_x "hi" do - x 1 - action :set_x_to_x - end - end - warnings = recipe.logs.lines.select { |l| l =~ /warn/i } - expect(warnings.size).to eq 2 - expect(warnings[0]).to match(/property x is declared in both resource_action_spec_with_x\[hi\] and resource_action_spec_also_with_x\[hi\] action :set_x_to_x. Use new_resource.x instead. At #{__FILE__}:#{ResourceActionSpecAlsoWithX.x_warning_line}/) - end - - it "Using the enclosing resource to set x to x outside the initializer emits no warning" do - Chef::Config[:treat_deprecation_warnings_as_errors] = false - recipe = converge do - resource_action_spec_also_with_x "hi" do - x 1 - action :set_x_to_x_in_non_initializer - end - end - warnings = recipe.logs.lines.select { |l| l =~ /warn/i } - expect(warnings.size).to eq 1 # the deprecation warning, not the property masking one - end - - it "Using the enclosing resource to set x to 10 emits no warning" do - Chef::Config[:treat_deprecation_warnings_as_errors] = false - recipe = converge do - resource_action_spec_also_with_x "hi" do - x 1 - action :set_x_to_10 - end - end - warnings = recipe.logs.lines.select { |l| l =~ /warn/i } - expect(warnings.size).to eq 1 # the deprecation warning, not the property masking one - end - - it "Using the enclosing resource to set x to 10 emits no warning" do - Chef::Config[:treat_deprecation_warnings_as_errors] = false - recipe = converge do - r = resource_action_spec_also_with_x "hi" - r.x 1 - r.action :set_x_to_10 - end - warnings = recipe.logs.lines.select { |l| l =~ /warn/i } - expect(warnings.size).to eq 1 # the deprecation warning, not the property masking one - end - end - - end - context "With a resource with a set_or_return property named group (same name as a resource)" do class ResourceActionSpecWithGroupAction < Chef::Resource resource_name :resource_action_spec_set_group_to_nil @@ -504,13 +416,6 @@ module ResourceActionSpec end end end - - it "Raises an error when attempting to use a template in the action" do - Chef::Config[:treat_deprecation_warnings_as_errors] = false - expect_converge do - has_property_named_template "hi" - end.to raise_error(/Property `template` of `has_property_named_template\[hi\]` was incorrectly passed a block. Possible property-resource collision. To call a resource named `template` either rename the property or else use `declare_resource\(:template, ...\)`/) - end end context "When a resource declares methods in action_class" do diff --git a/spec/unit/provider/apt_repository_spec.rb b/spec/unit/provider/apt_repository_spec.rb index ca85831a06..d881d01124 100644 --- a/spec/unit/provider/apt_repository_spec.rb +++ b/spec/unit/provider/apt_repository_spec.rb @@ -251,16 +251,4 @@ C5986B4F1257FFA86632CBA746181433FBB75451 expect(provider.build_repo("ppa:chef/main", "unstable", "main", false, nil)).to eql(target) end end - - describe "#keyfile_is_invalid?" do - it "returns true if the file is invalid" do - expect(provider).to receive(:shell_out).and_return(gpg_shell_out_failure) - expect(provider.keyfile_is_invalid?("/foo/bar.key")).to be_truthy - end - - it "returns false if the file is valid" do - expect(provider).to receive(:shell_out).and_return(gpg_shell_out_success) - expect(provider.keyfile_is_invalid?("/foo/bar.key")).to be_falsey - end - end end diff --git a/spec/unit/resource/remote_file_spec.rb b/spec/unit/resource/remote_file_spec.rb index 3e9ba1904c..691c55219c 100644 --- a/spec/unit/resource/remote_file_spec.rb +++ b/spec/unit/resource/remote_file_spec.rb @@ -31,13 +31,11 @@ describe Chef::Resource::RemoteFile do it "says its provider is RemoteFile when the source is an absolute URI" do resource.source("http://www.google.com/robots.txt") - expect(resource.provider).to eq(Chef::Provider::RemoteFile) expect(resource.provider_for_action(:create)).to be_kind_of(Chef::Provider::RemoteFile) end it "says its provider is RemoteFile when the source is a network share" do resource.source("\\\\fakey\\fakerton\\fake.txt") - expect(resource.provider).to eq(Chef::Provider::RemoteFile) expect(resource.provider_for_action(:create)).to be_kind_of(Chef::Provider::RemoteFile) end diff --git a/spec/unit/resource_reporter_spec.rb b/spec/unit/resource_reporter_spec.rb index 4fcfb01233..0ea704084c 100644 --- a/spec/unit/resource_reporter_spec.rb +++ b/spec/unit/resource_reporter_spec.rb @@ -285,7 +285,7 @@ describe Chef::ResourceReporter do end it "resource_command in prepared_run_data should be blank" do - expect(@first_update_report["after"]).to eq({ :command => "sensitive-resource", :user => nil }) + expect(@first_update_report["after"]).to eq({ :command => "sensitive-resource" }) end end |