summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2020-08-21 16:30:54 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2020-08-21 16:30:54 -0700
commitf11b854cd189e8ad311592d507a0849cfbc0da52 (patch)
treef1814b84c9d2a9520a59a55a13eb27feb6ee21aa /spec
parent654df0481f3c35c027a9afc313c74583f3d4112f (diff)
downloadohai-f11b854cd189e8ad311592d507a0849cfbc0da52.tar.gz
Migrate to the chef-utils helpers
This replaces the which/shell_out helpers with ones from chef-utils. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/mixin/shell_out_spec.rb (renamed from spec/unit/mixin/command_spec.rb)46
1 files changed, 34 insertions, 12 deletions
diff --git a/spec/unit/mixin/command_spec.rb b/spec/unit/mixin/shell_out_spec.rb
index d6df3b0d..6c54b166 100644
--- a/spec/unit/mixin/command_spec.rb
+++ b/spec/unit/mixin/shell_out_spec.rb
@@ -18,20 +18,42 @@
require "spec_helper"
-describe Ohai::Mixin::Command, "shell_out" do
+describe Ohai::Mixin::ShellOut, "shell_out" do
let(:cmd) { "sparkle-dream --version" }
- let(:shell_out) { double("Mixlib::ShellOut") }
+ let(:shell_out) { double("Mixlib::ShellOut", live_stream: nil, :live_stream= => nil) }
let(:plugin_name) { :OSSparkleDream }
- let(:options) { windows? ? { timeout: 30 } : { timeout: 30, env: { "PATH" => "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" } } }
+ let(:timeout) { 30 }
+
+ let(:options) do
+ if windows?
+ { timeout: timeout }
+ else
+ {
+ timeout: timeout,
+ environment: {
+ "LANG" => "en_US.UTF-8",
+ "LANGUAGE" => "en_US.UTF-8",
+ "LC_ALL" => "en_US.UTF-8",
+ "PATH" => "/Users/lamont/.asdf/installs/ruby/2.7.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
+ },
+ }
+ end
+ end
+
+ let(:logger) { instance_double("Mixlib::Log::Child", trace: nil, debug: nil, warn: nil, debug?: false) }
+
+ class DummyPlugin
+ include Ohai::Mixin::ShellOut
+ end
- let(:logger) { instance_double("Mixlib::Log::Child", trace: nil, debug: nil, warn: nil) }
+ let(:instance) { DummyPlugin.new }
before do
- allow(described_class).to receive(:logger).and_return(logger)
- allow(described_class).to receive(:name).and_return(plugin_name)
+ allow(instance).to receive(:logger).and_return(logger)
+ allow(instance).to receive(:name).and_return(plugin_name)
@original_env = ENV.to_hash
ENV.clear
end
@@ -58,7 +80,7 @@ describe Ohai::Mixin::Command, "shell_out" do
expect(logger).to receive(:trace)
.with("Plugin OSSparkleDream: ran 'sparkle-dream --version' and returned 256")
- described_class.shell_out(cmd)
+ instance.shell_out(cmd)
end
end
@@ -78,7 +100,7 @@ describe Ohai::Mixin::Command, "shell_out" do
.with("Plugin OSSparkleDream: ran 'sparkle-dream --version' and failed " \
"#<Errno::ENOENT: No such file or directory - sparkle-dream>")
- expect { described_class.shell_out(cmd) }
+ expect { instance.shell_out(cmd) }
.to raise_error(Ohai::Exceptions::Exec)
end
end
@@ -99,13 +121,13 @@ describe Ohai::Mixin::Command, "shell_out" do
.with("Plugin OSSparkleDream: ran 'sparkle-dream --version' and timed " \
"out after 30 seconds")
- expect { described_class.shell_out(cmd) }
+ expect { instance.shell_out(cmd) }
.to raise_error(Ohai::Exceptions::Exec)
end
end
describe "when a timeout option is provided" do
- let(:options) { windows? ? { timeout: 10 } : { timeout: 10, env: { "PATH" => "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" } } }
+ let(:timeout) { 10 }
it "runs the command with the provided timeout" do
expect(Mixlib::ShellOut)
@@ -123,7 +145,7 @@ describe Ohai::Mixin::Command, "shell_out" do
expect(logger).to receive(:trace)
.with("Plugin OSSparkleDream: ran 'sparkle-dream --version' and returned 256")
- described_class.shell_out(cmd, options)
+ instance.shell_out(cmd, timeout: 10)
end
describe "when the command times out" do
@@ -142,7 +164,7 @@ describe Ohai::Mixin::Command, "shell_out" do
.with("Plugin OSSparkleDream: ran 'sparkle-dream --version' and timed " \
"out after 10 seconds")
- expect { described_class.shell_out(cmd, options) }
+ expect { instance.shell_out(cmd, timeout: 10) }
.to raise_error(Ohai::Exceptions::Exec)
end
end