summaryrefslogtreecommitdiff
path: root/spec/unit
diff options
context:
space:
mode:
authorThom May <thom@chef.io>2016-01-21 11:05:21 +0000
committerThom May <thom@chef.io>2016-01-21 11:05:21 +0000
commitc21a286a4c46b9d30b8945bdd35c4e571b6f1137 (patch)
treed359cb641ec687c1854fb9263c1d6c6aa3c5ad68 /spec/unit
parent348d7367fa1d7d7bea0d49137679d3e6d4b77694 (diff)
downloadchef-c21a286a4c46b9d30b8945bdd35c4e571b6f1137.tar.gz
Dependency inject file locations
Diffstat (limited to 'spec/unit')
-rw-r--r--spec/unit/provider/apt_update_spec.rb36
1 files changed, 33 insertions, 3 deletions
diff --git a/spec/unit/provider/apt_update_spec.rb b/spec/unit/provider/apt_update_spec.rb
index e234cca960..9862eac20d 100644
--- a/spec/unit/provider/apt_update_spec.rb
+++ b/spec/unit/provider/apt_update_spec.rb
@@ -21,6 +21,15 @@ require "spec_helper"
describe Chef::Provider::AptUpdate do
let(:new_resource) { Chef::Resource::AptUpdate.new("update") }
+ let(:config_dir) { Dir.mktmpdir("apt_update_apt_conf_d") }
+ let(:config_file) { File.join(config_dir, "15update-stamp") }
+ let(:stamp_dir) { Dir.mktmpdir("apt_update_periodic") }
+
+ before do
+ stub_const("Chef::Provider::AptUpdate::APT_CONF_DIR", config_dir)
+ stub_const("Chef::Provider::AptUpdate::STAMP_DIR", stamp_dir)
+ end
+
let(:provider) do
node = Chef::Node.new
events = Chef::EventDispatch::Dispatcher.new
@@ -32,6 +41,26 @@ describe Chef::Provider::AptUpdate do
expect(provider).to respond_to(:load_current_resource)
end
+ context "when the apt config directory does not exist" do
+ before do
+ FileUtils.rmdir config_dir
+ expect(File.exist?(config_dir)).to be_falsey
+ allow(provider).to receive(:shell_out!).with("apt-get -q update")
+ end
+
+ it "should create the directory" do
+ provider.run_action(:update)
+ expect(File.exist?(config_dir)).to be_truthy
+ expect(File.directory?(config_dir)).to be_truthy
+ end
+
+ it "should create the config file" do
+ provider.run_action(:update)
+ expect(File.exist?(config_file)).to be_truthy
+ expect(File.read(config_file)).to match(/^APT::Update.*#{stamp_dir}/)
+ end
+ end
+
describe "#action_update" do
it "should update the apt cache" do
provider.load_current_resource
@@ -43,18 +72,19 @@ describe Chef::Provider::AptUpdate do
describe "#action_periodic" do
before do
- allow(File).to receive(:exist?).with("/var/lib/apt/periodic/update-success-stamp").and_return(true)
+ allow(File).to receive(:exist?)
+ expect(File).to receive(:exist?).with("#{stamp_dir}/update-success-stamp").and_return(true)
end
it "should run if the time stamp is old" do
- expect(File).to receive(:mtime).with("/var/lib/apt/periodic/update-success-stamp").and_return(Time.now - 86_500)
+ expect(File).to receive(:mtime).with("#{stamp_dir}/update-success-stamp").and_return(Time.now - 86_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("/var/lib/apt/periodic/update-success-stamp").and_return(Time.now)
+ expect(File).to receive(:mtime).with("#{stamp_dir}/update-success-stamp").and_return(Time.now)
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