summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2015-01-28 17:29:32 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2015-01-28 17:29:32 -0800
commit4b63890b270e20b1c1cdf0aab1da305418fed516 (patch)
tree9511200158031ed0c6181eec94c49d4e896dc9f7
parentb845a3d5e40b5888816b858f397995318b44757a (diff)
parent9067413680c0aadae54a0c1c03d8caccd9061279 (diff)
downloadohai-4b63890b270e20b1c1cdf0aab1da305418fed516.tar.gz
Merge pull request #472 from chef/lcg/merges2
Lcg/merges2
-rw-r--r--lib/ohai/plugins/rust.rb32
-rw-r--r--spec/unit/plugins/rust_spec.rb43
2 files changed, 75 insertions, 0 deletions
diff --git a/lib/ohai/plugins/rust.rb b/lib/ohai/plugins/rust.rb
new file mode 100644
index 00000000..9e65a3fa
--- /dev/null
+++ b/lib/ohai/plugins/rust.rb
@@ -0,0 +1,32 @@
+# Author:: Christopher M Luciano (<cmlucian@us.ibm.com>)
+# 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(:Rust) do
+ provides "languages/rust"
+
+ depends "languages"
+
+ collect_data do
+ output = nil
+
+ rust = Mash.new
+ so = shell_out("rustc --version")
+ if so.exitstatus == 0
+ output = so.stdout.split
+ rust[:version] = output[1]
+ languages[:rust] = rust if rust[:version]
+ end
+ end
+end
diff --git a/spec/unit/plugins/rust_spec.rb b/spec/unit/plugins/rust_spec.rb
new file mode 100644
index 00000000..aa4e495f
--- /dev/null
+++ b/spec/unit/plugins/rust_spec.rb
@@ -0,0 +1,43 @@
+# Author:: Christopher M Luciano (<cmlucian@us.ibm.com>)
+# 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.join(File.dirname(__FILE__), '..', '..', '/spec_helper.rb'))
+
+describe Ohai::System, "plugin rust" do
+ let(:stdout) {"rustc 1.0.0-nightly (29bd9a06e 2015-01-20 23:03:09 +0000)"}
+ let (:plugin) do
+ plugin = get_plugin("rust")
+ plugin[:languages] = Mash.new
+ allow(plugin).to receive(:shell_out).with("rustc --version").and_return(mock_shell_out(0, stdout, ""))
+ plugin
+ end
+
+ it "should get the rust version" do
+ expect(plugin).to receive(:shell_out).with("rustc --version").and_return(mock_shell_out(0, stdout, ""))
+ plugin.run
+ end
+
+ it "should set languages[:rust][:version]" do
+ plugin.run
+ expect(plugin.languages[:rust][:version]).to eql("1.0.0-nightly")
+ end
+
+ it "should not set the languages[:rust] if rust command fails" do
+ allow(plugin).to receive(:shell_out).with("rustc --version").and_return(mock_shell_out(1, stdout, ""))
+ plugin.run
+ expect(plugin.languages).not_to have_key(:rust)
+ end
+end