diff options
author | Jay Mundrawala <jdmundrawala@gmail.com> | 2015-02-27 21:02:31 -0800 |
---|---|---|
committer | Jay Mundrawala <jdmundrawala@gmail.com> | 2015-02-27 21:02:31 -0800 |
commit | 712a34b4a7b7afa21ae43ecc0757672cb961eb98 (patch) | |
tree | 79dcad08156d30039b9f4be43dd6347201f9b0ae | |
parent | f6a41f7c565c8ab6771efe7af0438237d1faa4fc (diff) | |
parent | 08bbb1bcbf584d30b7a1d82af9cd5f8490625899 (diff) | |
download | chef-712a34b4a7b7afa21ae43ecc0757672cb961eb98.tar.gz |
Merge pull request #2992 from chef/jdm/osx-fix
Fix specs on OSX
-rw-r--r-- | lib/chef/knife/cookbook_site_share.rb | 24 | ||||
-rw-r--r-- | spec/unit/knife/cookbook_site_share_spec.rb | 5 |
2 files changed, 18 insertions, 11 deletions
diff --git a/lib/chef/knife/cookbook_site_share.rb b/lib/chef/knife/cookbook_site_share.rb index 560e0669c1..efd2e7f129 100644 --- a/lib/chef/knife/cookbook_site_share.rb +++ b/lib/chef/knife/cookbook_site_share.rb @@ -73,14 +73,6 @@ class Chef begin Chef::Log.debug("Temp cookbook directory is #{tmp_cookbook_dir.inspect}") ui.info("Making tarball #{cookbook_name}.tgz") - tar_cmd = "tar" - begin - # Unix and Mac only - prefer gnutar - if shell_out("which gnutar").exitstatus.equal?(0) - tar_cmd = "gnutar" - end - rescue Errno::ENOENT - end shell_out!("#{tar_cmd} -czf #{cookbook_name}.tgz #{cookbook_name}", :cwd => tmp_cookbook_dir) rescue => e ui.error("Error making tarball #{cookbook_name}.tgz: #{e.message}. Increase log verbosity (-VV) for more information.") @@ -90,7 +82,7 @@ class Chef if config[:dry_run] ui.info("Not uploading #{cookbook_name}.tgz due to --dry-run flag.") - result = shell_out!("tar -tzf #{cookbook_name}.tgz", :cwd => tmp_cookbook_dir) + result = shell_out!("#{tar_cmd} -tzf #{cookbook_name}.tgz", :cwd => tmp_cookbook_dir) ui.info(result.stdout) FileUtils.rm_rf tmp_cookbook_dir return @@ -158,6 +150,20 @@ class Chef end res end + + def tar_cmd + if !@tar_cmd + @tar_cmd = "tar" + begin + # Unix and Mac only - prefer gnutar + if shell_out("which gnutar").exitstatus.equal?(0) + @tar_cmd = "gnutar" + end + rescue Errno::ENOENT + end + end + @tar_cmd + end end end diff --git a/spec/unit/knife/cookbook_site_share_spec.rb b/spec/unit/knife/cookbook_site_share_spec.rb index f7207dd175..76e4ec730e 100644 --- a/spec/unit/knife/cookbook_site_share_spec.rb +++ b/spec/unit/knife/cookbook_site_share_spec.rb @@ -144,8 +144,9 @@ describe Chef::Knife::CookbookSiteShare do end it "should list files in the tarball" do - expect(@knife).to receive(:shell_out!).with("tar -czf #{@cookbook.name}.tgz #{@cookbook.name}", {:cwd => "/var/tmp/dummy"}) - expect(@knife).to receive(:shell_out!).with("tar -tzf #{@cookbook.name}.tgz", {:cwd => "/var/tmp/dummy"}) + allow(@knife).to receive(:tar_cmd).and_return("footar") + expect(@knife).to receive(:shell_out!).with("footar -czf #{@cookbook.name}.tgz #{@cookbook.name}", {:cwd => "/var/tmp/dummy"}) + expect(@knife).to receive(:shell_out!).with("footar -tzf #{@cookbook.name}.tgz", {:cwd => "/var/tmp/dummy"}) @knife.run end |