summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@chef.io>2020-06-23 15:10:51 -0700
committerGitHub <noreply@github.com>2020-06-23 15:10:51 -0700
commit281a52e5bf9a5e9c73cb4f8758eb2490ff8c9346 (patch)
tree3faf8c357fd1f69f60cf47ad3d376539187ac1d1
parent66b1f1f4e66ab9dc85381966b7cddf6381541d2a (diff)
parent3c5219c55e024d63302059d994fa9bf3389c529f (diff)
downloadchef-281a52e5bf9a5e9c73cb4f8758eb2490ff8c9346.tar.gz
Merge pull request #10055 from chef/lcg/windows-unit-tests
-rw-r--r--spec/unit/role_spec.rb44
-rw-r--r--spec/unit/util/selinux_spec.rb1
2 files changed, 24 insertions, 21 deletions
diff --git a/spec/unit/role_spec.rb b/spec/unit/role_spec.rb
index cad86b4a63..aaabb397ab 100644
--- a/spec/unit/role_spec.rb
+++ b/spec/unit/role_spec.rb
@@ -310,50 +310,52 @@ describe Chef::Role do
describe "when loading from disk and role_path is an array" do
before(:each) do
- Chef::Config[:role_path] = ["/path1", "/path/path2"]
+ Chef::Config[:role_path] = ["/path1", "/path1/path2"]
end
+ let(:root) { windows? ? "C:/path1" : "/path1" }
+
it "should return a Chef::Role object from JSON" do
- expect(Dir).to receive(:glob).with(File.join("/path1", "**", "**")).exactly(1).times.and_return(["/path1/lolcat.json"])
- expect(File).to receive(:exists?).with("/path1/lolcat.json").exactly(1).times.and_return(true)
- expect(IO).to receive(:read).with("/path1/lolcat.json").and_return('{"name": "ceiling_cat", "json_class": "Chef::Role" }')
+ expect(Dir).to receive(:glob).with(File.join(root, "**", "**")).exactly(1).times.and_return(["#{root}/lolcat.json"])
+ expect(File).to receive(:exists?).with("#{root}/lolcat.json").exactly(1).times.and_return(true)
+ expect(IO).to receive(:read).with("#{root}/lolcat.json").and_return('{"name": "ceiling_cat", "json_class": "Chef::Role" }')
expect(@role).to be_a_kind_of(Chef::Role)
@role.class.from_disk("lolcat")
end
it "should return a Chef::Role object from JSON when role is in the second path" do
- expect(Dir).to receive(:glob).with(File.join("/path1", "**", "**")).exactly(1).times.and_return([])
- expect(Dir).to receive(:glob).with(File.join("/path/path2", "**", "**")).exactly(1).times.and_return(["/path/path2/lolcat.json"])
- expect(File).to receive(:exists?).with("/path/path2/lolcat.json").exactly(1).times.and_return(true)
- expect(IO).to receive(:read).with("/path/path2/lolcat.json").and_return('{"name": "ceiling_cat", "json_class": "Chef::Role" }')
+ expect(Dir).to receive(:glob).with(File.join(root, "**", "**")).exactly(1).times.and_return([])
+ expect(Dir).to receive(:glob).with(File.join("#{root}/path2", "**", "**")).exactly(1).times.and_return(["#{root}/path2/lolcat.json"])
+ expect(File).to receive(:exists?).with("#{root}/path2/lolcat.json").exactly(1).times.and_return(true)
+ expect(IO).to receive(:read).with("#{root}/path2/lolcat.json").and_return('{"name": "ceiling_cat", "json_class": "Chef::Role" }')
expect(@role).to be_a_kind_of(Chef::Role)
@role.class.from_disk("lolcat")
end
it "should return a Chef::Role object from a Ruby DSL" do
- expect(Dir).to receive(:glob).with(File.join("/path1", "**", "**")).exactly(1).times.and_return(["/path1/lolcat.rb"])
- expect(File).to receive(:exists?).with("/path1/lolcat.rb").exactly(1).times.and_return(true)
- expect(File).to receive(:readable?).with("/path1/lolcat.rb").and_return(true)
- expect(File).to receive(:file?).with("/path1/lolcat.rb").and_return(true)
- expect(IO).to receive(:read).with("/path1/lolcat.rb").exactly(1).times.and_return(ROLE_DSL)
+ expect(Dir).to receive(:glob).with(File.join(root, "**", "**")).exactly(1).times.and_return(["#{root}/lolcat.rb"])
+ expect(File).to receive(:exists?).with("#{root}/lolcat.rb").exactly(1).times.and_return(true)
+ expect(File).to receive(:readable?).with("#{root}/lolcat.rb").and_return(true)
+ expect(File).to receive(:file?).with("#{root}/lolcat.rb").and_return(true)
+ expect(IO).to receive(:read).with("#{root}/lolcat.rb").exactly(1).times.and_return(ROLE_DSL)
expect(@role).to be_a_kind_of(Chef::Role)
@role.class.from_disk("lolcat")
end
it "should return a Chef::Role object from a Ruby DSL when role is in the second path" do
- expect(Dir).to receive(:glob).with(File.join("/path1", "**", "**")).exactly(1).times.and_return([])
- expect(Dir).to receive(:glob).with(File.join("/path/path2", "**", "**")).exactly(1).times.and_return(["/path/path2/lolcat.rb"])
- expect(File).to receive(:exists?).with("/path/path2/lolcat.rb").exactly(1).times.and_return(true)
- expect(File).to receive(:readable?).with("/path/path2/lolcat.rb").and_return(true)
- expect(File).to receive(:file?).with("/path/path2/lolcat.rb").and_return(true)
- expect(IO).to receive(:read).with("/path/path2/lolcat.rb").exactly(1).times.and_return(ROLE_DSL)
+ expect(Dir).to receive(:glob).with(File.join(root, "**", "**")).exactly(1).times.and_return([])
+ expect(Dir).to receive(:glob).with(File.join("#{root}/path2", "**", "**")).exactly(1).times.and_return(["#{root}/path2/lolcat.rb"])
+ expect(File).to receive(:exists?).with("#{root}/path2/lolcat.rb").exactly(1).times.and_return(true)
+ expect(File).to receive(:readable?).with("#{root}/path2/lolcat.rb").and_return(true)
+ expect(File).to receive(:file?).with("#{root}/path2/lolcat.rb").and_return(true)
+ expect(IO).to receive(:read).with("#{root}/path2/lolcat.rb").exactly(1).times.and_return(ROLE_DSL)
expect(@role).to be_a_kind_of(Chef::Role)
@role.class.from_disk("lolcat")
end
it "should raise an exception if the file does not exist" do
- expect(Dir).to receive(:glob).with(File.join("/path1", "**", "**")).exactly(1).times.and_return([])
- expect(Dir).to receive(:glob).with(File.join("/path/path2", "**", "**")).exactly(1).times.and_return([])
+ expect(Dir).to receive(:glob).with(File.join(root, "**", "**")).exactly(1).times.and_return([])
+ expect(Dir).to receive(:glob).with(File.join("#{root}/path2", "**", "**")).exactly(1).times.and_return([])
expect { @role.class.from_disk("lolcat") }.to raise_error(Chef::Exceptions::RoleNotFound)
end
diff --git a/spec/unit/util/selinux_spec.rb b/spec/unit/util/selinux_spec.rb
index a14c682996..2b73981934 100644
--- a/spec/unit/util/selinux_spec.rb
+++ b/spec/unit/util/selinux_spec.rb
@@ -30,6 +30,7 @@ describe Chef::Util::Selinux do
end
before do
+ allow(ChefUtils).to receive(:windows?).and_return(false)
TestClass.reset_state
@test_instance = TestClass.new
end