summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-08-18 14:15:29 -0700
committerTim Smith <tsmith84@gmail.com>2020-08-18 14:15:29 -0700
commit2c4130c520c8819cb75f18eff7bc8c1312660b3b (patch)
treefae5f6c1f69f85dfa470bd59180186fd68e19c23
parent8177af017447d7976365f41a78cc2cec482c3281 (diff)
downloadchef-2c4130c520c8819cb75f18eff7bc8c1312660b3b.tar.gz
Add some specs for the methods to load state
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--spec/unit/resource/timezone_spec.rb44
1 files changed, 44 insertions, 0 deletions
diff --git a/spec/unit/resource/timezone_spec.rb b/spec/unit/resource/timezone_spec.rb
index da48ab7c16..ca71ccb679 100644
--- a/spec/unit/resource/timezone_spec.rb
+++ b/spec/unit/resource/timezone_spec.rb
@@ -20,6 +20,27 @@ require "spec_helper"
describe Chef::Resource::Timezone do
let(:resource) { Chef::Resource::Timezone.new("fakey_fakerton") }
+ # note: This weird indention is correct
+ let(:shellout_timedatectl) do
+ double("shell_out", exitstatus: 0, error?: false, stdout: <<-OUTPUT)
+ Local time: Tue 2020-08-18 20:55:05 UTC
+ Universal time: Tue 2020-08-18 20:55:05 UTC
+ RTC time: Tue 2020-08-18 20:55:05
+ Time zone: Etc/UTC (UTC, +0000)
+System clock synchronized: yes
+systemd-timesyncd.service active: yes
+ RTC in local TZ: no
+ OUTPUT
+ end
+
+ let(:shellout_systemsetup_fail) do
+ double("shell_out", stdout: "You need administrator access to run this tool... exiting!", exitstatus: 0, error?: false) # yes it's a non-error exit
+ end
+
+ let(:shellout_systemsetup) do
+ double("shell_out", stdout: "Time Zone: UTC", exitstatus: 0, error?: false)
+ end
+
it "sets resource name as :timezone" do
expect(resource.resource_name).to eql(:timezone)
end
@@ -36,4 +57,27 @@ describe Chef::Resource::Timezone do
expect { resource.action :set }.not_to raise_error
expect { resource.action :unset }.to raise_error(Chef::Exceptions::ValidationFailed)
end
+
+ describe "#current_darwin_tz?" do
+ context "with admin privs" do
+ it "returns the TZ" do
+ expect(resource).to receive(:shell_out!).and_return(shellout_systemsetup)
+ expect(resource.current_darwin_tz).to eql("UTC")
+ end
+ end
+
+ context "without admin privs" do
+ it "returns the TZ" do
+ expect(resource).to receive(:shell_out!).and_return(shellout_systemsetup_fail)
+ expect { resource.current_darwin_tz }.to raise_error(RuntimeError)
+ end
+ end
+ end
+
+ describe "#current_systemd_tz?" do
+ it "returns the TZ" do
+ expect(resource).to receive(:shell_out!).and_return(shellout_timedatectl)
+ expect(resource.current_systemd_tz).to eql("Etc/UTC")
+ end
+ end
end