diff options
-rw-r--r-- | lib/chef/provider/apt_update.rb | 3 | ||||
-rw-r--r-- | lib/chef/resource/apt_update.rb | 1 | ||||
-rw-r--r-- | spec/unit/provider/apt_update_spec.rb | 20 | ||||
-rw-r--r-- | spec/unit/resource/apt_update_spec.rb | 8 |
4 files changed, 30 insertions, 2 deletions
diff --git a/lib/chef/provider/apt_update.rb b/lib/chef/provider/apt_update.rb index d6d79bcf18..00c3ad16bb 100644 --- a/lib/chef/provider/apt_update.rb +++ b/lib/chef/provider/apt_update.rb @@ -16,7 +16,8 @@ # limitations under the License. # -require "chef/resource/apt_update" +require "chef/resource" +require "chef/dsl/declare_resource" class Chef class Provider diff --git a/lib/chef/resource/apt_update.rb b/lib/chef/resource/apt_update.rb index 660bcd819f..df2033b063 100644 --- a/lib/chef/resource/apt_update.rb +++ b/lib/chef/resource/apt_update.rb @@ -17,7 +17,6 @@ # require "chef/resource" -require "chef/provider/apt_update" class Chef class Resource diff --git a/spec/unit/provider/apt_update_spec.rb b/spec/unit/provider/apt_update_spec.rb index 9862eac20d..b72f7d9a76 100644 --- a/spec/unit/provider/apt_update_spec.rb +++ b/spec/unit/provider/apt_update_spec.rb @@ -89,5 +89,25 @@ describe Chef::Provider::AptUpdate do provider.run_action(:periodic) expect(new_resource).to_not be_updated_by_last_action end + + context "with a different frequency" do + before do + new_resource.frequency(400) + end + + it "should run if the time stamp is old" do + expect(File).to receive(:mtime).with("#{stamp_dir}/update-success-stamp").and_return(Time.now - 500) + expect(provider).to receive(:shell_out!).with("apt-get -q update") + provider.run_action(:periodic) + expect(new_resource).to be_updated_by_last_action + end + + it "should not run if the time stamp is new" do + expect(File).to receive(:mtime).with("#{stamp_dir}/update-success-stamp").and_return(Time.now - 300) + expect(provider).to_not receive(:shell_out!).with("apt-get -q update") + provider.run_action(:periodic) + expect(new_resource).to_not be_updated_by_last_action + end + end end end diff --git a/spec/unit/resource/apt_update_spec.rb b/spec/unit/resource/apt_update_spec.rb index 2814089aeb..786f9bf0a4 100644 --- a/spec/unit/resource/apt_update_spec.rb +++ b/spec/unit/resource/apt_update_spec.rb @@ -27,4 +27,12 @@ describe Chef::Resource::AptUpdate do expect(resource).to be_a_kind_of(Chef::Resource::AptUpdate) end + it "the default frequency should be 1 day" do + expect(resource.frequency).to eql(86_400) + end + + it "the frequency should accept integers" do + resource.frequency(400) + expect(resource.frequency).to eql(400) + end end |