summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2016-06-17 23:20:16 +0200
committerGitHub <noreply@github.com>2016-06-17 23:20:16 +0200
commitd1e2fe982c3648b219715d056428a75d44af5c0d (patch)
tree10031b195de3ad971f9680d2311c937e2ccb40e6
parentcd5324d7e421baed8de42b0bba2b7c9b27763941 (diff)
parent3528c0531621bc9a99f48e978ef7e10759aa0db6 (diff)
downloadohai-d1e2fe982c3648b219715d056428a75d44af5c0d.tar.gz
Merge pull request #829 from johnbellone/master
Add a simple plugin to get the local timezone.
-rw-r--r--lib/ohai/plugins/timezone.rb23
-rw-r--r--spec/unit/plugins/timezone_spec.rb30
2 files changed, 53 insertions, 0 deletions
diff --git a/lib/ohai/plugins/timezone.rb b/lib/ohai/plugins/timezone.rb
new file mode 100644
index 00000000..fb35987d
--- /dev/null
+++ b/lib/ohai/plugins/timezone.rb
@@ -0,0 +1,23 @@
+#
+# Author:: John Bellone (<jbellone@bloomberg.net>)
+# 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.
+
+Ohai.plugin(:Timezone) do
+ provides "timezone"
+
+ collect_data(:default) do
+ timezone Time.now.getlocal.zone
+ end
+end
diff --git a/spec/unit/plugins/timezone_spec.rb b/spec/unit/plugins/timezone_spec.rb
new file mode 100644
index 00000000..770dc838
--- /dev/null
+++ b/spec/unit/plugins/timezone_spec.rb
@@ -0,0 +1,30 @@
+#
+# Author:: John Bellone (<jbellone@bloomberg.net>)
+# 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 File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb")
+
+describe Ohai::System, "timezone plugin" do
+ before(:each) do
+ @plugin = get_plugin("timezone")
+ allow(Time).to receive_message_chain(:now, :getlocal, :zone) { "ZZZ" }
+ end
+
+ it "should get the local timezone" do
+ @plugin.run
+ expect(@plugin["timezone"]).to eq("ZZZ")
+ end
+end