Remove use of `system`. Add test coverage.

This commit is contained in:
Chris Roberts 2018-12-19 09:44:05 -08:00
parent b9b9eeac85
commit ac5b45445a
2 changed files with 64 additions and 1 deletions

View File

@ -15,7 +15,8 @@ module VagrantPlugins
end
def self.nfs_installed(env)
Kernel.system("/usr/bin/xbps-query nfs-utils", [:out, :err] => "/dev/null")
result = Vagrant::Util::Subprocess.execute("/usr/bin/xbps-query nfs-utils")
result.exit_code == 0
end
end
end

View File

@ -0,0 +1,62 @@
require_relative "../../../../base"
require_relative "../../../../../../plugins/hosts/void/cap/nfs"
require_relative "../../../../../../lib/vagrant/util"
describe VagrantPlugins::HostVoid::Cap::NFS do
include_context "unit"
let(:caps) do
VagrantPlugins::HostVoid::Plugin
.components
.host_capabilities[:void]
end
let(:env) { double("env") }
context ".nfs_check_command" do
it "should provide nfs_check_command capability" do
expect(caps.get(:nfs_check_command)).to eq(described_class)
end
it "should return command to execute" do
expect(caps.get(:nfs_check_command).nfs_check_command(env)).to be_a(String)
end
end
context ".nfs_start_command" do
it "should provide nfs_start_command capability" do
expect(caps.get(:nfs_start_command)).to eq(described_class)
end
it "should return command to execute" do
expect(caps.get(:nfs_start_command).nfs_start_command(env)).to be_a(String)
end
end
context ".nfs_installed" do
let(:exit_code) { 0 }
let(:result) { Vagrant::Util::Subprocess::Result.new(exit_code, "", "") }
before { allow(Vagrant::Util::Subprocess).to receive(:execute).
with(/xbps-query nfs-utils/).and_return(result) }
it "should provide nfs_installed capability" do
expect(caps.get(:nfs_installed)).to eq(described_class)
end
context "when installed" do
it "should return true" do
expect(caps.get(:nfs_installed).nfs_installed(env)).to be_truthy
end
end
context "when not installed" do
let(:exit_code) { 1 }
it "should return false" do
expect(caps.get(:nfs_installed).nfs_installed(env)).to be_falsey
end
end
end
end