summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/functional/resource/macos_userdefaults_spec.rb20
-rw-r--r--spec/unit/compliance/runner_spec.rb60
2 files changed, 80 insertions, 0 deletions
diff --git a/spec/functional/resource/macos_userdefaults_spec.rb b/spec/functional/resource/macos_userdefaults_spec.rb
index 2f79135c45..0ed7839ad0 100644
--- a/spec/functional/resource/macos_userdefaults_spec.rb
+++ b/spec/functional/resource/macos_userdefaults_spec.rb
@@ -116,4 +116,24 @@ describe Chef::Resource::MacosUserDefaults, :macos_only do
resource.key "titlesize"
expect { resource.run_action(:delete) }. to_not raise_error
end
+
+ context "resource can process FFI::Pointer type" do
+ it "for host property" do
+ resource.domain "/Library/Preferences/ManagedInstalls"
+ resource.key "TestDictionaryValues"
+ resource.value "User": "/Library/Managed Installs/way_fake.log"
+ resource.host :current
+ resource.run_action(:write)
+ expect { resource.run_action(:write) }. to_not raise_error
+ end
+
+ it "for user property" do
+ resource.domain "/Library/Preferences/ManagedInstalls"
+ resource.key "TestDictionaryValues"
+ resource.value "User": "/Library/Managed Installs/way_fake.log"
+ resource.user :current
+ resource.run_action(:write)
+ expect { resource.run_action(:write) }. to_not raise_error
+ end
+ end
end
diff --git a/spec/unit/compliance/runner_spec.rb b/spec/unit/compliance/runner_spec.rb
index 602d675d4d..e8a08abfc1 100644
--- a/spec/unit/compliance/runner_spec.rb
+++ b/spec/unit/compliance/runner_spec.rb
@@ -1,4 +1,5 @@
require "spec_helper"
+require "tmpdir"
describe Chef::Compliance::Runner do
let(:logger) { double(:logger).as_null_object }
@@ -283,4 +284,63 @@ describe Chef::Compliance::Runner do
expect(inputs["chef_node"]["chef_environment"]).to eq("_default")
end
end
+
+ describe "interval running" do
+ let(:tempdir) { Dir.mktmpdir("chef-compliance-tests") }
+
+ before do
+ allow(runner).to receive(:report_timing_file).and_return("#{tempdir}/report_timing.json")
+ end
+
+ it "is disabled by default" do
+ expect(runner.node["audit"]["interval"]["enabled"]).to be false
+ end
+
+ it "defaults to 24 hours / 1440 minutes" do
+ expect(runner.node["audit"]["interval"]["time"]).to be 1440
+ end
+
+ it "runs when the timing file does not exist" do
+ expect(runner).to receive(:report)
+ runner.report_with_interval
+ end
+
+ it "runs when the timing file does not exist and intervals are enabled" do
+ node.normal["audit"]["interval"]["enabled"] = true
+ expect(runner).to receive(:report)
+ runner.report_with_interval
+ end
+
+ it "runs when the timing file exists and has a recent timestamp" do
+ FileUtils.touch runner.report_timing_file
+ expect(runner).to receive(:report)
+ runner.report_with_interval
+ end
+
+ it "does not runs when the timing file exists and has a recent timestamp and intervals are enabled" do
+ node.normal["audit"]["interval"]["enabled"] = true
+ FileUtils.touch runner.report_timing_file
+ expect(runner).not_to receive(:report)
+ runner.report_with_interval
+ end
+
+ it "does not runs when the timing file exists and has a recent timestamp and intervals are enabled" do
+ node.normal["audit"]["interval"]["enabled"] = true
+ FileUtils.touch runner.report_timing_file
+ ten_minutes_ago = Time.now - 600
+ File.utime ten_minutes_ago, ten_minutes_ago, runner.report_timing_file
+ expect(runner).not_to receive(:report)
+ runner.report_with_interval
+ end
+
+ it "runs when the timing file exists and has a recent timestamp and intervals are enabled and the time is short" do
+ node.normal["audit"]["interval"]["enabled"] = true
+ node.normal["audit"]["interval"]["time"] = 9
+ FileUtils.touch runner.report_timing_file
+ ten_minutes_ago = Time.now - 600
+ File.utime ten_minutes_ago, ten_minutes_ago, runner.report_timing_file
+ expect(runner).to receive(:report)
+ runner.report_with_interval
+ end
+ end
end