packaging 0.88.77

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +17 -0
  3. data/README-Solaris.md +117 -0
  4. data/README.md +977 -0
  5. data/lib/packaging.rb +32 -0
  6. data/lib/packaging/archive.rb +126 -0
  7. data/lib/packaging/artifactory.rb +651 -0
  8. data/lib/packaging/artifactory/extensions.rb +94 -0
  9. data/lib/packaging/config.rb +492 -0
  10. data/lib/packaging/config/params.rb +387 -0
  11. data/lib/packaging/config/validations.rb +13 -0
  12. data/lib/packaging/deb.rb +28 -0
  13. data/lib/packaging/deb/repo.rb +264 -0
  14. data/lib/packaging/gem.rb +70 -0
  15. data/lib/packaging/metrics.rb +15 -0
  16. data/lib/packaging/nuget.rb +39 -0
  17. data/lib/packaging/paths.rb +376 -0
  18. data/lib/packaging/platforms.rb +507 -0
  19. data/lib/packaging/repo.rb +155 -0
  20. data/lib/packaging/retrieve.rb +75 -0
  21. data/lib/packaging/rpm.rb +5 -0
  22. data/lib/packaging/rpm/repo.rb +254 -0
  23. data/lib/packaging/sign.rb +8 -0
  24. data/lib/packaging/sign/deb.rb +9 -0
  25. data/lib/packaging/sign/dmg.rb +41 -0
  26. data/lib/packaging/sign/ips.rb +57 -0
  27. data/lib/packaging/sign/msi.rb +124 -0
  28. data/lib/packaging/sign/rpm.rb +115 -0
  29. data/lib/packaging/tar.rb +163 -0
  30. data/lib/packaging/util.rb +146 -0
  31. data/lib/packaging/util/date.rb +20 -0
  32. data/lib/packaging/util/execution.rb +85 -0
  33. data/lib/packaging/util/file.rb +125 -0
  34. data/lib/packaging/util/git.rb +174 -0
  35. data/lib/packaging/util/git_tags.rb +73 -0
  36. data/lib/packaging/util/gpg.rb +66 -0
  37. data/lib/packaging/util/jenkins.rb +95 -0
  38. data/lib/packaging/util/misc.rb +69 -0
  39. data/lib/packaging/util/net.rb +410 -0
  40. data/lib/packaging/util/os.rb +17 -0
  41. data/lib/packaging/util/platform.rb +40 -0
  42. data/lib/packaging/util/rake_utils.rb +112 -0
  43. data/lib/packaging/util/serialization.rb +19 -0
  44. data/lib/packaging/util/ship.rb +300 -0
  45. data/lib/packaging/util/tool.rb +41 -0
  46. data/lib/packaging/util/version.rb +334 -0
  47. data/spec/fixtures/config/ext/build_defaults.yaml +2 -0
  48. data/spec/fixtures/config/ext/project_data.yaml +2 -0
  49. data/spec/fixtures/configs/components/test_file.json +1 -0
  50. data/spec/fixtures/configs/components/test_file_2.json +0 -0
  51. data/spec/fixtures/configs/components/test_file_not_tagged.json +1 -0
  52. data/spec/fixtures/configs/components/test_file_wrong_ext.txt +0 -0
  53. data/spec/fixtures/configs/components/test_file_wrong_ext.wrong +0 -0
  54. data/spec/fixtures/util/pre_tasks.yaml +4 -0
  55. data/spec/lib/packaging/artifactory_spec.rb +221 -0
  56. data/spec/lib/packaging/config_spec.rb +576 -0
  57. data/spec/lib/packaging/deb/repo_spec.rb +157 -0
  58. data/spec/lib/packaging/deb_spec.rb +52 -0
  59. data/spec/lib/packaging/gem_spec.rb +86 -0
  60. data/spec/lib/packaging/paths_spec.rb +418 -0
  61. data/spec/lib/packaging/platforms_spec.rb +178 -0
  62. data/spec/lib/packaging/repo_spec.rb +135 -0
  63. data/spec/lib/packaging/retrieve_spec.rb +100 -0
  64. data/spec/lib/packaging/rpm/repo_spec.rb +133 -0
  65. data/spec/lib/packaging/sign_spec.rb +133 -0
  66. data/spec/lib/packaging/tar_spec.rb +116 -0
  67. data/spec/lib/packaging/util/execution_spec.rb +56 -0
  68. data/spec/lib/packaging/util/file_spec.rb +139 -0
  69. data/spec/lib/packaging/util/git_spec.rb +160 -0
  70. data/spec/lib/packaging/util/git_tag_spec.rb +36 -0
  71. data/spec/lib/packaging/util/gpg_spec.rb +64 -0
  72. data/spec/lib/packaging/util/jenkins_spec.rb +112 -0
  73. data/spec/lib/packaging/util/misc_spec.rb +31 -0
  74. data/spec/lib/packaging/util/net_spec.rb +259 -0
  75. data/spec/lib/packaging/util/os_spec.rb +31 -0
  76. data/spec/lib/packaging/util/rake_utils_spec.rb +70 -0
  77. data/spec/lib/packaging/util/ship_spec.rb +199 -0
  78. data/spec/lib/packaging/util/version_spec.rb +123 -0
  79. data/spec/lib/packaging_spec.rb +19 -0
  80. data/spec/spec_helper.rb +22 -0
  81. data/static_artifacts/PackageInfo.plist +3 -0
  82. data/tasks/00_utils.rake +214 -0
  83. data/tasks/30_metrics.rake +33 -0
  84. data/tasks/apple.rake +268 -0
  85. data/tasks/archive.rake +69 -0
  86. data/tasks/build.rake +12 -0
  87. data/tasks/clean.rake +5 -0
  88. data/tasks/config.rake +35 -0
  89. data/tasks/deb.rake +129 -0
  90. data/tasks/deb_repos.rake +28 -0
  91. data/tasks/deprecated.rake +130 -0
  92. data/tasks/doc.rake +20 -0
  93. data/tasks/education.rake +57 -0
  94. data/tasks/fetch.rake +60 -0
  95. data/tasks/gem.rake +159 -0
  96. data/tasks/jenkins.rake +538 -0
  97. data/tasks/jenkins_dynamic.rake +202 -0
  98. data/tasks/load_extras.rake +21 -0
  99. data/tasks/mock.rake +348 -0
  100. data/tasks/nightly_repos.rake +286 -0
  101. data/tasks/pe_deb.rake +12 -0
  102. data/tasks/pe_rpm.rake +13 -0
  103. data/tasks/pe_ship.rake +226 -0
  104. data/tasks/pe_sign.rake +13 -0
  105. data/tasks/pe_tar.rake +5 -0
  106. data/tasks/retrieve.rake +52 -0
  107. data/tasks/rpm.rake +66 -0
  108. data/tasks/rpm_repos.rake +29 -0
  109. data/tasks/ship.rake +692 -0
  110. data/tasks/sign.rake +154 -0
  111. data/tasks/tag.rake +8 -0
  112. data/tasks/tar.rake +28 -0
  113. data/tasks/update.rake +16 -0
  114. data/tasks/vanagon.rake +35 -0
  115. data/tasks/vendor_gems.rake +117 -0
  116. data/tasks/version.rake +33 -0
  117. data/tasks/z_data_dump.rake +65 -0
  118. data/templates/README +1 -0
  119. data/templates/downstream.xml.erb +47 -0
  120. data/templates/msi.xml.erb +197 -0
  121. data/templates/packaging.xml.erb +346 -0
  122. data/templates/repo.xml.erb +117 -0
  123. metadata +287 -0
@@ -0,0 +1,36 @@
1
+ # -*- ruby -*-
2
+ require 'spec_helper'
3
+
4
+ describe "Pkg::Util::Git_tag" do
5
+ context "parse_ref!" do
6
+ it "fails for a ref that doesn't exist'" do
7
+ expect { Pkg::Util::Git_tag.new("git://github.com/puppetlabs/leatherman.git", "garbagegarbage") }.to raise_error(RuntimeError, /ERROR : Not a ref or sha!/)
8
+ end
9
+ end
10
+
11
+ context "sha?" do
12
+ it "sets ref type as a sha when passed a sha" do
13
+ git_tag = Pkg::Util::Git_tag.new("git://github.com/puppetlabs/leatherman.git", "4eef05389ebf418b62af17406c7f9f13fa51f975")
14
+ expect(git_tag.sha?).to eq(true)
15
+ end
16
+ end
17
+
18
+ context "branch?" do
19
+ it "sets ref type as a branch when passed a branch" do
20
+ git_tag = Pkg::Util::Git_tag.new("git://github.com/puppetlabs/leatherman.git", "main")
21
+ expect(git_tag.branch?).to eq(true)
22
+ end
23
+ end
24
+
25
+ context "tag?" do
26
+ it "sets ref type as a tag when passed a tag" do
27
+ git_tag = Pkg::Util::Git_tag.new("git://github.com/puppetlabs/leatherman.git", "tags/0.6.2")
28
+ expect(git_tag.tag?).to eq(true)
29
+ end
30
+
31
+ it "sets ref type as a tag when passed a fully qualified tag" do
32
+ git_tag = Pkg::Util::Git_tag.new("git://github.com/puppetlabs/leatherman.git", "refs/tags/0.6.2")
33
+ expect(git_tag.tag?).to eq(true)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Pkg::Util::Gpg" do
4
+ let(:gpg) { "/local/bin/gpg" }
5
+ let(:keychain) { "/usr/local/bin/keychain" }
6
+ let(:gpg_key) { "abcd1234" }
7
+ let(:target_file) { "/tmp/file" }
8
+
9
+ before(:each) do
10
+ reset_env(['RPM_GPG_AGENT'])
11
+ Pkg::Config.gpg_key = gpg_key
12
+ end
13
+
14
+ describe '#key' do
15
+ it "fails if Pkg::Config.gpg_key isn't set" do
16
+ allow(Pkg::Config).to receive(:gpg_key).and_return(nil)
17
+ expect { Pkg::Util::Gpg.key }.to raise_error(RuntimeError)
18
+ end
19
+ it "fails if Pkg::Config.gpg_key is an empty string" do
20
+ allow(Pkg::Config).to receive(:gpg_key).and_return('')
21
+ expect { Pkg::Util::Gpg.key }.to raise_error(RuntimeError)
22
+ end
23
+ end
24
+
25
+ describe '#kill_keychain' do
26
+ it "doesn't reload the keychain if already loaded" do
27
+ Pkg::Util::Gpg.instance_variable_set("@keychain_loaded", true)
28
+ Pkg::Util::Gpg.should_receive(:kill_keychain).never
29
+ Pkg::Util::Gpg.should_receive(:start_keychain).never
30
+ Pkg::Util::Gpg.load_keychain
31
+ Pkg::Util::Gpg.instance_variable_set("@keychain_loaded", nil)
32
+ end
33
+
34
+ it "doesn't reload the keychain if ENV['RPM_GPG_AGENT'] is set" do
35
+ ENV['RPM_GPG_AGENT'] = 'blerg'
36
+ Pkg::Util::Gpg.should_receive(:kill_keychain).never
37
+ Pkg::Util::Gpg.should_receive(:start_keychain).never
38
+ Pkg::Util::Gpg.load_keychain
39
+ end
40
+
41
+ it 'kills and starts the keychain if not loaded already' do
42
+ Pkg::Util::Gpg.instance_variable_set("@keychain_loaded", nil)
43
+ Pkg::Util::Gpg.should_receive(:kill_keychain).once
44
+ Pkg::Util::Gpg.should_receive(:start_keychain).once
45
+ Pkg::Util::Gpg.load_keychain
46
+ end
47
+ end
48
+
49
+ describe '#sign_file' do
50
+ it 'adds special flags if RPM_GPG_AGENT is set' do
51
+ ENV['RPM_GPG_AGENT'] = 'blerg'
52
+ additional_flags = "--no-tty --use-agent"
53
+ Pkg::Util::Tool.should_receive(:find_tool).with('gpg').and_return(gpg)
54
+ Pkg::Util::Execution.should_receive(:capture3).with("#{gpg}\s#{additional_flags}\s--armor --detach-sign -u #{gpg_key} #{target_file}")
55
+ Pkg::Util::Gpg.sign_file(target_file)
56
+ end
57
+
58
+ it 'signs without extra flags when RPM_GPG_AGENT is not set' do
59
+ Pkg::Util::Tool.should_receive(:find_tool).with('gpg').and_return(gpg)
60
+ Pkg::Util::Execution.should_receive(:capture3).with("#{gpg}\s\s--armor --detach-sign -u #{gpg_key} #{target_file}")
61
+ Pkg::Util::Gpg.sign_file(target_file)
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,112 @@
1
+ # -*- ruby -*-
2
+ require 'spec_helper'
3
+
4
+ describe Pkg::Util::Jenkins do
5
+ let(:build_host) {"Jenkins-foo"}
6
+ let(:name) {"job-foo"}
7
+ around do |example|
8
+ old_build_host = Pkg::Config.jenkins_build_host
9
+ Pkg::Config.jenkins_build_host = build_host
10
+ example.run
11
+ Pkg::Config.jenkins_build_host = old_build_host
12
+ end
13
+
14
+ describe "#create_jenkins_job" do
15
+ let(:xml_file) {"bar.xml"}
16
+
17
+ it "should call curl_form_data with the correct arguments" do
18
+ Pkg::Util::Net.should_receive(:curl_form_data).with("http://#{build_host}/createItem?name=#{name}", ["-H", '"Content-Type: application/xml"', "--data-binary", "@#{xml_file}"])
19
+ Pkg::Util::Jenkins.create_jenkins_job(name, xml_file)
20
+ end
21
+ end
22
+
23
+ describe "#jenkins_job_exists?" do
24
+
25
+ it "should call curl_form_data with correct arguments" do
26
+ Pkg::Util::Net.should_receive(:curl_form_data).with("http://#{build_host}/job/#{name}/config.xml", ["--silent", "--fail"], :quiet => true).and_return(['output', 0])
27
+ Pkg::Util::Execution.should_receive(:success?).and_return(true)
28
+ Pkg::Util::Jenkins.jenkins_job_exists?(name)
29
+ end
30
+
31
+ it "should return false on job not existing" do
32
+ Pkg::Util::Net.should_receive(:curl_form_data).with("http://#{build_host}/job/#{name}/config.xml", ["--silent", "--fail"], :quiet => true).and_return(['output', 1])
33
+ Pkg::Util::Execution.should_receive(:success?).and_return(false)
34
+ Pkg::Util::Jenkins.jenkins_job_exists?(name).should be_false
35
+ end
36
+
37
+ it "should return false if curl_form_data raised a runtime error" do
38
+ Pkg::Util::Net.should_receive(:curl_form_data).with("http://#{build_host}/job/#{name}/config.xml", ["--silent", "--fail"], :quiet => true).and_return(false)
39
+ Pkg::Util::Jenkins.jenkins_job_exists?(name).should be_false
40
+ end
41
+
42
+ it "should return true when job exists" do
43
+ Pkg::Util::Net.should_receive(:curl_form_data).with("http://#{build_host}/job/#{name}/config.xml", ["--silent", "--fail"], :quiet => true).and_return(['output', 0])
44
+ Pkg::Util::Execution.should_receive(:success?).and_return(true)
45
+ Pkg::Util::Jenkins.jenkins_job_exists?(name).should be_true
46
+ end
47
+ end
48
+
49
+ describe '#poll_jenkins_job' do
50
+ let(:job_url) { "http://cat.meow/" }
51
+ let(:build_url) { "#{job_url}/1" }
52
+ let(:result) { "SUCCESS" }
53
+ let(:job_hash) { {'lastBuild' => { 'url' => build_url } }}
54
+ let(:build_hash) { {'result' => result, 'building' => false } }
55
+
56
+ before :each do
57
+ subject.stub(:get_jenkins_info).with(job_url).and_return(job_hash)
58
+ subject.stub(:wait_for_build).with(build_url).and_return(build_hash)
59
+ end
60
+
61
+ context "when polling the given url" do
62
+ it "return the resulting build_hash when build completes successfully" do
63
+ subject.poll_jenkins_job(job_url)
64
+ end
65
+ end
66
+ end
67
+
68
+ describe '#wait_for_build' do
69
+ let(:job_url) { "http://cat.meow/" }
70
+ let(:build_url) { "#{job_url}/1" }
71
+ let(:build_hash) { {'building' => false } }
72
+
73
+ context "when waiting for the given build to finish" do
74
+ it "return the resulting build_hash when build completes successfully" do
75
+ subject.should_receive(:get_jenkins_info).with(job_url).and_return(build_hash)
76
+ subject.wait_for_build(job_url)
77
+ end
78
+ end
79
+ end
80
+
81
+ describe '#get_jenkins_info' do
82
+ let(:url) { "http://cat.meow/" }
83
+ let(:uri) { URI(url) }
84
+ let(:response) { double }
85
+ let(:valid_json) { "{\"employees\":[
86
+ {\"firstName\":\"John\", \"lastName\":\"Doe\"},
87
+ {\"firstName\":\"Anna\", \"lastName\":\"Smith\"},
88
+ {\"firstName\":\"Peter\", \"lastName\":\"Jones\"} ]}" }
89
+
90
+ before :each do
91
+ response.stub(:body).and_return( valid_json )
92
+ response.stub(:code).and_return( '200' )
93
+ Pkg::Util::Jenkins.should_receive(:URI).and_return(uri)
94
+ end
95
+
96
+ context "when making HTTP GET request to given url" do
97
+ it "should return Hash of JSON contents when response is non-error" do
98
+ Net::HTTP.should_receive(:get_response).with(uri).and_return(response)
99
+ subject.get_jenkins_info(url)
100
+ end
101
+
102
+ it "should raise Runtime error when response is error" do
103
+ response.stub(:code).and_return( '400' )
104
+ Net::HTTP.should_receive(:get_response).with(uri).and_return(response)
105
+ expect{
106
+ subject.get_jenkins_info(url)
107
+ }.to raise_error(Exception, /Unable to query .*, please check that it is valid./)
108
+ end
109
+ end
110
+ end
111
+
112
+ end
@@ -0,0 +1,31 @@
1
+ # -*- ruby -*-
2
+ require 'spec_helper'
3
+
4
+ describe 'Pkg::Util::Misc' do
5
+ context "#search_and_replace" do
6
+ let(:orig_string) { "#!/bin/bash\necho '__REPO_NAME__'" }
7
+ let(:updated_string) { "#!/bin/bash\necho 'abcdefg'" }
8
+ let(:good_replacements) do
9
+ { __REPO_NAME__: Pkg::Paths.repo_name }
10
+ end
11
+ let(:warn_replacements) do
12
+ { __REPO_NAME__: nil }
13
+ end
14
+
15
+ it 'replaces the token with the Pkg::Config variable' do
16
+ Pkg::Config.config_from_hash({:project => "foo", :repo_name => 'abcdefg'})
17
+ Pkg::Util::Misc.search_and_replace(orig_string, good_replacements).should eq(updated_string)
18
+ end
19
+
20
+ it 'does no replacement if the Pkg::Config variable is not set' do
21
+ Pkg::Config.config_from_hash({:project => 'foo',})
22
+ Pkg::Util::Misc.search_and_replace(orig_string, good_replacements).should eq(orig_string)
23
+ end
24
+
25
+ it 'warns and continues if the Pkg::Config variable is unknown to packaging' do
26
+ Pkg::Config.config_from_hash({:project => 'foo',})
27
+ Pkg::Util::Misc.should_receive(:warn).with("replacement value for '#{warn_replacements.keys.first}' probably shouldn't be nil")
28
+ Pkg::Util::Misc.search_and_replace(orig_string, warn_replacements).should eq(orig_string)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,259 @@
1
+ require 'spec_helper'
2
+ require 'socket'
3
+ require 'open3'
4
+
5
+ describe "Pkg::Util::Net" do
6
+ let(:target) { "/tmp/placething" }
7
+ let(:target_uri) { "http://google.com" }
8
+ let(:content) { "stuff" }
9
+ let(:rsync) { "/bin/rsync" }
10
+ let(:ssh) { "/usr/local/bin/ssh" }
11
+ let(:s3cmd) { "/usr/local/bin/s3cmd" }
12
+
13
+ describe "#fetch_uri" do
14
+ context "given a target directory" do
15
+ it "does nothing if the directory isn't writable" do
16
+ File.stub(:writable?).with(File.dirname(target)) { false }
17
+ File.should_receive(:open).never
18
+ Pkg::Util::Net.fetch_uri(target_uri, target)
19
+ end
20
+
21
+ it "writes the content of the uri to a file if directory is writable" do
22
+ File.should_receive(:writable?).once.with(File.dirname(target)) { true }
23
+ File.should_receive(:open).once.with(target, 'w')
24
+ Pkg::Util::Net.fetch_uri(target_uri, target)
25
+ end
26
+ end
27
+ end
28
+
29
+ describe "hostname utils" do
30
+
31
+ describe "hostname" do
32
+ it "should return the hostname of the current host" do
33
+ Socket.stub(:gethostname) { "foo" }
34
+ Pkg::Util::Net.hostname.should eq("foo")
35
+ end
36
+ end
37
+
38
+ describe "check_host" do
39
+ context "with required :true" do
40
+ it "should raise an exception if the passed host does not match the current host" do
41
+ Socket.stub(:gethostname) { "foo" }
42
+ Pkg::Util::Net.should_receive(:check_host).and_raise(RuntimeError)
43
+ expect{ Pkg::Util::Net.check_host("bar", :required => true) }.to raise_error(RuntimeError)
44
+ end
45
+ end
46
+
47
+ context "with required :false" do
48
+ it "should return nil if the passed host does not match the current host" do
49
+ Socket.stub(:gethostname) { "foo" }
50
+ Pkg::Util::Net.check_host("bar", :required => false).should be_nil
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ describe "remote_ssh_cmd" do
57
+ it "should be able to call via deprecated shim" do
58
+ Pkg::Util::Tool.should_receive(:check_tool).with("ssh").and_return(ssh)
59
+ Pkg::Util::Execution.should_receive(:capture3).with("#{ssh} -t foo 'set -e;bar'")
60
+ Pkg::Util::Execution.should_receive(:success?).and_return(true)
61
+ Pkg::Util::Net.remote_ssh_cmd("foo", "bar", true)
62
+ end
63
+ end
64
+
65
+ describe "remote_execute" do
66
+ it "should fail if ssh is not present" do
67
+ Pkg::Util::Tool.stub(:find_tool).with("ssh") { fail }
68
+ Pkg::Util::Tool.should_receive(:check_tool).with("ssh").and_raise(RuntimeError)
69
+ expect{ Pkg::Util::Net.remote_execute("foo", "bar") }.to raise_error(RuntimeError)
70
+ end
71
+
72
+ it "should be able to not fail fast" do
73
+ Pkg::Util::Tool.should_receive(:check_tool).with("ssh").and_return(ssh)
74
+ Kernel.should_receive(:system).with("#{ssh} -t foo 'bar'")
75
+ Pkg::Util::Execution.should_receive(:success?).and_return(true)
76
+ Pkg::Util::Net.remote_execute(
77
+ "foo", "bar", capture_output: false, extra_options: '', fail_fast: false)
78
+ end
79
+
80
+ it "should be able to trace output" do
81
+ Pkg::Util::Tool.should_receive(:check_tool).with("ssh").and_return(ssh)
82
+ Kernel.should_receive(:system).with("#{ssh} -t foo 'set -x;bar'")
83
+ Pkg::Util::Execution.should_receive(:success?).and_return(true)
84
+ Pkg::Util::Net.remote_execute(
85
+ "foo", "bar", capture_output: false, fail_fast: false, trace: true)
86
+ end
87
+
88
+ context "without output captured" do
89
+ it "should execute a command :foo on a host :bar using Kernel" do
90
+ Pkg::Util::Tool.should_receive(:check_tool).with("ssh").and_return(ssh)
91
+ Kernel.should_receive(:system).with("#{ssh} -t foo 'set -e;bar'")
92
+ Pkg::Util::Execution.should_receive(:success?).and_return(true)
93
+ Pkg::Util::Net.remote_execute("foo", "bar")
94
+ end
95
+
96
+ it "should escape single quotes in the command" do
97
+ Pkg::Util::Tool.should_receive(:check_tool).with("ssh").and_return(ssh)
98
+ Kernel.should_receive(:system).with("#{ssh} -t foo 'set -e;b'\\''ar'")
99
+ Pkg::Util::Execution.should_receive(:success?).and_return(true)
100
+ Pkg::Util::Net.remote_execute("foo", "b'ar")
101
+ end
102
+
103
+ it "should raise an error if ssh fails" do
104
+ Pkg::Util::Tool.should_receive(:check_tool).with("ssh").and_return(ssh)
105
+ Kernel.should_receive(:system).with("#{ssh} -t foo 'set -e;bar'")
106
+ Pkg::Util::Execution.should_receive(:success?).and_return(false)
107
+ expect{ Pkg::Util::Net.remote_execute("foo", "bar") }
108
+ .to raise_error(RuntimeError, /failed./)
109
+ end
110
+ end
111
+
112
+ context "with output captured" do
113
+ it "should execute a command :foo on a host :bar using Pkg::Util::Execution.capture3" do
114
+ Pkg::Util::Tool.should_receive(:check_tool).with("ssh").and_return(ssh)
115
+ Pkg::Util::Execution.should_receive(:capture3).with("#{ssh} -t foo 'set -e;bar'")
116
+ Pkg::Util::Execution.should_receive(:success?).and_return(true)
117
+ Pkg::Util::Net.remote_execute("foo", "bar", capture_output: true)
118
+ end
119
+
120
+ it "should escape single quotes in the command" do
121
+ Pkg::Util::Tool.should_receive(:check_tool).with("ssh").and_return(ssh)
122
+ Pkg::Util::Execution.should_receive(:capture3).with("#{ssh} -t foo 'set -e;b'\\''ar'")
123
+ Pkg::Util::Execution.should_receive(:success?).and_return(true)
124
+ Pkg::Util::Net.remote_execute("foo", "b'ar", capture_output: true)
125
+ end
126
+
127
+ it "should raise an error if ssh fails" do
128
+ Pkg::Util::Tool.should_receive(:check_tool).with("ssh").and_return(ssh)
129
+ Pkg::Util::Execution.should_receive(:capture3).with("#{ssh} -t foo 'set -e;bar'")
130
+ Pkg::Util::Execution.should_receive(:success?).and_return(false)
131
+ expect{ Pkg::Util::Net.remote_execute("foo", "bar", capture_output: true) }
132
+ .to raise_error(RuntimeError, /failed./)
133
+ end
134
+ end
135
+ end
136
+
137
+ describe "#rsync_to" do
138
+ defaults = "--recursive --hard-links --links --verbose --omit-dir-times --no-perms --no-owner --no-group"
139
+ it "should fail if rsync is not present" do
140
+ Pkg::Util::Tool.stub(:find_tool).with("rsync") { fail }
141
+ Pkg::Util::Tool.should_receive(:check_tool).with("rsync").and_raise(RuntimeError)
142
+ expect{ Pkg::Util::Net.rsync_to("foo", "bar", "boo") }.to raise_error(RuntimeError)
143
+ end
144
+
145
+ it "should rsync 'thing' to 'foo@bar:/home/foo' with flags '#{defaults} --ignore-existing'" do
146
+ Pkg::Util::Tool.should_receive(:check_tool).with("rsync").and_return(rsync)
147
+ Pkg::Util::Execution.should_receive(:capture3).with("#{rsync} #{defaults} --ignore-existing thing foo@bar:/home/foo", true)
148
+ Pkg::Util::Net.rsync_to("thing", "foo@bar", "/home/foo")
149
+ end
150
+
151
+ it "rsyncs 'thing' to 'foo@bar:/home/foo' with flags that don't include --ignore-existing" do
152
+ Pkg::Util::Tool.should_receive(:check_tool).with("rsync").and_return(rsync)
153
+ Pkg::Util::Execution.should_receive(:capture3).with("#{rsync} #{defaults} thing foo@bar:/home/foo", true)
154
+ Pkg::Util::Net.rsync_to("thing", "foo@bar", "/home/foo", extra_flags: [])
155
+ end
156
+
157
+ it "rsyncs 'thing' to 'foo@bar:/home/foo' with flags that don't include arbitrary flags" do
158
+ Pkg::Util::Tool.should_receive(:check_tool).with("rsync").and_return(rsync)
159
+ Pkg::Util::Execution.should_receive(:capture3).with("#{rsync} #{defaults} --foo-bar --and-another-flag thing foo@bar:/home/foo", true)
160
+ Pkg::Util::Net.rsync_to("thing", "foo@bar", "/home/foo", extra_flags: ["--foo-bar", "--and-another-flag"])
161
+ end
162
+ end
163
+
164
+ describe "#s3sync_to" do
165
+ it "should fail if s3cmd is not present" do
166
+ Pkg::Util::Tool.should_receive(:find_tool).with('s3cmd', :required => true).and_raise(RuntimeError)
167
+ Pkg::Util::Execution.should_not_receive(:capture3).with("#{s3cmd} sync 'foo' s3://bar/boo/")
168
+ expect{ Pkg::Util::Net.s3sync_to("foo", "bar", "boo") }.to raise_error(RuntimeError)
169
+ end
170
+
171
+ it "should fail if ~/.s3cfg is not present" do
172
+ Pkg::Util::Tool.should_receive(:check_tool).with("s3cmd").and_return(s3cmd)
173
+ Pkg::Util::File.should_receive(:file_exists?).with(File.join(ENV['HOME'], '.s3cfg')).and_return(false)
174
+ expect{ Pkg::Util::Net.s3sync_to("foo", "bar", "boo") }.to raise_error(RuntimeError, /does not exist/)
175
+ end
176
+
177
+ it "should s3 sync 'thing' to 's3://foo@bar/home/foo/' with no flags" do
178
+ Pkg::Util::Tool.should_receive(:check_tool).with("s3cmd").and_return(s3cmd)
179
+ Pkg::Util::File.should_receive(:file_exists?).with(File.join(ENV['HOME'], '.s3cfg')).and_return(true)
180
+ Pkg::Util::Execution.should_receive(:capture3).with("#{s3cmd} sync 'thing' s3://foo@bar/home/foo/")
181
+ Pkg::Util::Net.s3sync_to("thing", "foo@bar", "home/foo")
182
+ end
183
+
184
+ it "should s3 sync 'thing' to 's3://foo@bar/home/foo/' with --delete-removed and --acl-public" do
185
+ Pkg::Util::Tool.should_receive(:check_tool).with("s3cmd").and_return(s3cmd)
186
+ Pkg::Util::File.should_receive(:file_exists?).with(File.join(ENV['HOME'], '.s3cfg')).and_return(true)
187
+ Pkg::Util::Execution.should_receive(:capture3).with("#{s3cmd} sync --delete-removed --acl-public 'thing' s3://foo@bar/home/foo/")
188
+ Pkg::Util::Net.s3sync_to("thing", "foo@bar", "home/foo", ["--delete-removed", "--acl-public"])
189
+ end
190
+ end
191
+
192
+ describe "#rsync_from" do
193
+ defaults = "--recursive --hard-links --links --verbose --omit-dir-times --no-perms --no-owner --no-group"
194
+ it "should fail if rsync is not present" do
195
+ Pkg::Util::Tool.stub(:find_tool).with("rsync") { fail }
196
+ Pkg::Util::Tool.should_receive(:check_tool).with("rsync").and_raise(RuntimeError)
197
+ expect{ Pkg::Util::Net.rsync_from("foo", "bar", "boo") }.to raise_error(RuntimeError)
198
+ end
199
+
200
+ it "should not include the flags '--ignore-existing' by default" do
201
+ Pkg::Util::Tool.should_receive(:check_tool).with("rsync").and_return(rsync)
202
+ Pkg::Util::Execution.should_receive(:capture3).with("#{rsync} #{defaults} foo@bar:thing /home/foo", true)
203
+ Pkg::Util::Net.rsync_from("thing", "foo@bar", "/home/foo")
204
+ end
205
+
206
+ it "should rsync 'thing' from 'foo@bar' to '/home/foo' with flags '#{defaults}'" do
207
+ Pkg::Util::Tool.should_receive(:check_tool).with("rsync").and_return(rsync)
208
+ Pkg::Util::Execution.should_receive(:capture3).with("#{rsync} #{defaults} foo@bar:thing /home/foo", true)
209
+ Pkg::Util::Net.rsync_from("thing", "foo@bar", "/home/foo")
210
+ end
211
+
212
+ it "rsyncs 'thing' from 'foo@bar:/home/foo' with flags that don't include arbitrary flags" do
213
+ Pkg::Util::Tool.should_receive(:check_tool).with("rsync").and_return(rsync)
214
+ Pkg::Util::Execution.should_receive(:capture3).with("#{rsync} #{defaults} --foo-bar --and-another-flag foo@bar:thing /home/foo", true)
215
+ Pkg::Util::Net.rsync_from("thing", "foo@bar", "/home/foo", extra_flags: ["--foo-bar", "--and-another-flag"])
216
+ end
217
+ end
218
+
219
+ describe "#curl_form_data" do
220
+ let(:curl) {"/bin/curl"}
221
+ let(:form_data) {["name=FOO"]}
222
+ let(:options) { {:quiet => true} }
223
+
224
+ it "should return false on failure" do
225
+ Pkg::Util::Tool.should_receive(:check_tool).with("curl").and_return(curl)
226
+ Pkg::Util::Execution.should_receive(:capture3).with("#{curl} -i '#{target_uri}'").and_return(['stdout', 'stderr', 1])
227
+ Pkg::Util::Net.curl_form_data(target_uri).should eq(['stdout', 1])
228
+ end
229
+
230
+
231
+ it "should curl with just the uri" do
232
+ Pkg::Util::Tool.should_receive(:check_tool).with("curl").and_return(curl)
233
+ Pkg::Util::Execution.should_receive(:capture3).with("#{curl} -i '#{target_uri}'")
234
+ Pkg::Util::Net.curl_form_data(target_uri)
235
+ end
236
+
237
+ it "should curl with the form data and uri" do
238
+ Pkg::Util::Tool.should_receive(:check_tool).with("curl").and_return(curl)
239
+ Pkg::Util::Execution.should_receive(:capture3).with("#{curl} -i #{form_data[0]} '#{target_uri}'")
240
+ Pkg::Util::Net.curl_form_data(target_uri, form_data)
241
+ end
242
+
243
+ it "should curl with form data, uri, and be quiet" do
244
+ Pkg::Util::Tool.should_receive(:check_tool).with("curl").and_return(curl)
245
+ Pkg::Util::Execution.should_receive(:capture3).with("#{curl} -i #{form_data[0]} '#{target_uri}'").and_return(['stdout', 'stderr', 0])
246
+ Pkg::Util::Net.curl_form_data(target_uri, form_data, options).should eq(['', 0])
247
+ end
248
+
249
+ end
250
+
251
+ describe "#print_url_info" do
252
+ it "should output correct formatting" do
253
+ Pkg::Util::Net.should_receive(:puts).with("\n////////////////////////////////////////////////////////////////////////////////\n\n
254
+ Build submitted. To view your build progress, go to\n#{target_uri}\n\n
255
+ ////////////////////////////////////////////////////////////////////////////////\n\n")
256
+ Pkg::Util::Net.print_url_info(target_uri)
257
+ end
258
+ end
259
+ end