summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorDavin Taddeo <davin@chef.io>2020-07-13 22:08:08 -0400
committerDavin Taddeo <davin@chef.io>2020-07-13 22:08:08 -0400
commit90c9c18ae56baa10daf77dcd4f52846657a7e38f (patch)
treeb99402a972448259a3bc2f7a6c54a6169dab8fed /spec
parent5a275a65dd1b7c871b3fcfa316e8a8d194acfffa (diff)
parent02dda427ad9f25984b4428a63eabb6db1f1f1a4c (diff)
downloadchef-90c9c18ae56baa10daf77dcd4f52846657a7e38f.tar.gz
Merge branch 'master' of github.com:chef/chef into windows_firewall_profile
Diffstat (limited to 'spec')
-rw-r--r--spec/functional/resource/git_spec.rb22
-rw-r--r--spec/functional/shell_spec.rb10
-rw-r--r--spec/unit/knife/cookbook_upload_spec.rb11
-rw-r--r--spec/unit/provider/package/dnf/python_helper_spec.rb2
-rw-r--r--spec/unit/provider/package/windows_spec.rb21
-rw-r--r--spec/unit/win32/security_spec.rb7
6 files changed, 50 insertions, 23 deletions
diff --git a/spec/functional/resource/git_spec.rb b/spec/functional/resource/git_spec.rb
index f8064fef20..25e5c6da4a 100644
--- a/spec/functional/resource/git_spec.rb
+++ b/spec/functional/resource/git_spec.rb
@@ -239,6 +239,28 @@ describe Chef::Resource::Git, requires_git: true do
end
end
+ context "when updating a branch that's already checked out out" do
+ it "checks out master, commits to the repo, and checks out the latest changes" do
+ git deploy_directory do
+ repository origin_repo
+ revision "master"
+ action :sync
+ end.should_be_updated
+
+ # We don't have a way to test a commit in the git bundle
+ # Revert to a previous commit in the same branch and make sure we can still sync.
+ shell_out!("git", "reset", "--hard", rev_foo, cwd: deploy_directory)
+
+ git deploy_directory do
+ repository origin_repo
+ revision "master"
+ action :sync
+ end.should_be_updated
+ expect_revision_to_be("HEAD", rev_head)
+ expect_branch_to_be("master")
+ end
+ end
+
context "when dealing with a repo with a degenerate tag named 'HEAD'" do
before do
shell_out!("git", "tag", "-m\"degenerate tag\"", "HEAD", "ed181b3419b6f489bedab282348162a110d6d3a1", cwd: origin_repo)
diff --git a/spec/functional/shell_spec.rb b/spec/functional/shell_spec.rb
index 583440d2b6..2289df3ef1 100644
--- a/spec/functional/shell_spec.rb
+++ b/spec/functional/shell_spec.rb
@@ -97,13 +97,13 @@ describe Shell do
[output, e.status]
end
- it "boots correctly with -lauto" do
+ it "boots correctly with -lauto", :executables do
output, exitstatus = run_chef_shell_with("-lauto")
expect(output).to include("done")
expect(exitstatus).to eq(0)
end
- it "sets the log_level from the command line" do
+ it "sets the log_level from the command line", :executables do
output, exitstatus = run_chef_shell_with("-lfatal") do |out, keyboard|
show_log_level_code = %q[puts "===#{Chef::Log.level}==="]
keyboard.puts(show_log_level_code)
@@ -114,13 +114,13 @@ describe Shell do
end
context "on solo mode" do
- it "starts correctly" do
+ it "starts correctly", :executables do
output, exitstatus = run_chef_shell_with("--solo")
expect(output).to include("done")
expect(exitstatus).to eq(0)
end
- it "should be able to use the API" do
+ it "should be able to use the API", :executables do
output, exitstatus = run_chef_shell_with("-s") do |out, keyboard|
simple_api_get = "api.get('data')"
keyboard.puts(simple_api_get)
@@ -131,7 +131,7 @@ describe Shell do
end
end
- it "sets the override_runlist from the command line" do
+ it "sets the override_runlist from the command line", :executables do
output, exitstatus = run_chef_shell_with("-o 'override::foo,override::bar'") do |out, keyboard|
show_recipes_code = %q[puts "#{node["recipes"].inspect}"]
keyboard.puts(show_recipes_code)
diff --git a/spec/unit/knife/cookbook_upload_spec.rb b/spec/unit/knife/cookbook_upload_spec.rb
index 661eb779ea..bc13ce834c 100644
--- a/spec/unit/knife/cookbook_upload_spec.rb
+++ b/spec/unit/knife/cookbook_upload_spec.rb
@@ -323,19 +323,18 @@ describe Chef::Knife::CookbookUpload do
context "when cookbook path is an array" do
it "should warn users that no cookbooks exist" do
- knife.config[:cookbook_path] = ["/chef-repo/cookbooks", "/home/user/cookbooks"]
- expect(knife.ui).to receive(:warn).with(
- /Could not find any cookbooks in your cookbook path: '#{knife.config[:cookbook_path].join(', ')}'\. Use --cookbook-path to specify the desired path\./
- )
+ cookbook_path = windows? ? "C:/chef-repo/cookbooks" : "/chef-repo/cookbooks"
+ knife.config[:cookbook_path] = [cookbook_path, "/home/user/cookbooks"]
+ expect(knife.ui).to receive(:warn).with("Could not find any cookbooks in your cookbook path: '#{knife.config[:cookbook_path].join(", ")}'. Use --cookbook-path to specify the desired path.")
knife.run
end
end
context "when cookbook path is a string" do
it "should warn users that no cookbooks exist" do
- knife.config[:cookbook_path] = "/chef-repo/cookbooks"
+ knife.config[:cookbook_path] = windows? ? "C:/chef-repo/cookbooks" : "/chef-repo/cookbooks"
expect(knife.ui).to receive(:warn).with(
- /Could not find any cookbooks in your cookbook path: '#{knife.config[:cookbook_path]}'\. Use --cookbook-path to specify the desired path\./
+ "Could not find any cookbooks in your cookbook path: '#{knife.config[:cookbook_path]}'. Use --cookbook-path to specify the desired path."
)
knife.run
end
diff --git a/spec/unit/provider/package/dnf/python_helper_spec.rb b/spec/unit/provider/package/dnf/python_helper_spec.rb
index c22e0f6bee..1f94147273 100644
--- a/spec/unit/provider/package/dnf/python_helper_spec.rb
+++ b/spec/unit/provider/package/dnf/python_helper_spec.rb
@@ -22,7 +22,7 @@ require "spec_helper"
describe Chef::Provider::Package::Dnf::PythonHelper do
let(:helper) { Chef::Provider::Package::Dnf::PythonHelper.instance }
- it "propagates stacktraces on stderr from the forked subprocess" do
+ it "propagates stacktraces on stderr from the forked subprocess", :rhel do
allow(helper).to receive(:dnf_command).and_return("ruby -e 'raise \"your hands in the air\"'")
expect { helper.package_query(:whatprovides, "tcpdump") }.to raise_error(/your hands in the air/)
end
diff --git a/spec/unit/provider/package/windows_spec.rb b/spec/unit/provider/package/windows_spec.rb
index b9a32ffd66..6531d9c5ec 100644
--- a/spec/unit/provider/package/windows_spec.rb
+++ b/spec/unit/provider/package/windows_spec.rb
@@ -70,16 +70,18 @@ describe Chef::Provider::Package::Windows, :windows_only do
end
end
- context "when the source is a uri" do
- let(:resource_source) { "https://foo.bar/calculator.msi" }
-
- context "when the source has not been downloaded" do
+ context "when the source is not present it loads from cache" do
+ context "when the package is not installed" do
before(:each) do
- allow(provider).to receive(:downloadable_file_missing?).and_return(true)
+ allow(provider).to receive(:uri_scheme?).and_return(false)
+ allow(provider.package_provider).to receive(:get_product_property).and_return(nil)
+ allow(provider.package_provider).to receive(:get_installed_version).and_return(nil)
+ allow(provider.package_provider).to receive(:package_version).and_return(nil)
end
- it "sets the current version to unknown" do
+
+ it "sets the current version nil" do
provider.load_current_resource
- expect(provider.current_resource.version).to eql("unknown")
+ expect(provider.current_resource.version).to eql(nil)
end
end
@@ -312,7 +314,10 @@ describe Chef::Provider::Package::Windows, :windows_only do
let(:resource_source) { "https://foo.bar/calculator.exe" }
it "downloads the http resource" do
- allow(File).to receive(:exist?).with('c:\cache\calculator.exe').and_return(false)
+ allow(provider).to receive(:uri_scheme?).and_return(true)
+ allow(provider).to receive(:installer_type).and_return(nil)
+ allow(File).to receive(:exist?).with("https\\foo.bar\\calculator.exe").and_return(false)
+ allow(provider).to receive(:compile_and_converge_action)
expect(provider).to receive(:download_source_file)
provider.run_action(:install)
end
diff --git a/spec/unit/win32/security_spec.rb b/spec/unit/win32/security_spec.rb
index d90951c3e2..ed4c033aa3 100644
--- a/spec/unit/win32/security_spec.rb
+++ b/spec/unit/win32/security_spec.rb
@@ -81,9 +81,10 @@ describe "Chef::Win32::Security", :windows_only do
context "when the user has admin privileges" do
it "returns true" do
- allow(Chef::ReservedNames::Win32::Security).to receive(:open_current_process_token)
- token = Chef::ReservedNames::Win32::Security.open_current_process_token
+ token = double(:process_token)
allow(token).to receive_message_chain(:handle, :handle)
+
+ allow(Chef::ReservedNames::Win32::Security).to receive(:open_current_process_token).and_return(token)
allow(Chef::ReservedNames::Win32::Security).to receive(:get_token_information_elevation_type)
allow(Chef::ReservedNames::Win32::Security).to receive(:GetTokenInformation).and_return(true)
allow_any_instance_of(FFI::Buffer).to receive(:read_ulong).and_return(1)
@@ -128,7 +129,7 @@ describe "Chef::Win32::Security", :windows_only do
context "when FFI::LastError.error result is not ERROR_INSUFFICIENT_BUFFER and not NO_ERROR" do
it "raises Chef::ReservedNames::Win32::Error.raise! exception" do
expect(FFI::LastError).to receive(:error).and_return(123).at_least(:once)
- expect { security_class.lookup_account_name "system" }.to raise_error
+ expect { security_class.lookup_account_name "system" }.to raise_error(Chef::Exceptions::Win32APIError)
end
end
end