packaging 0.88.77
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +17 -0
- data/README-Solaris.md +117 -0
- data/README.md +977 -0
- data/lib/packaging.rb +32 -0
- data/lib/packaging/archive.rb +126 -0
- data/lib/packaging/artifactory.rb +651 -0
- data/lib/packaging/artifactory/extensions.rb +94 -0
- data/lib/packaging/config.rb +492 -0
- data/lib/packaging/config/params.rb +387 -0
- data/lib/packaging/config/validations.rb +13 -0
- data/lib/packaging/deb.rb +28 -0
- data/lib/packaging/deb/repo.rb +264 -0
- data/lib/packaging/gem.rb +70 -0
- data/lib/packaging/metrics.rb +15 -0
- data/lib/packaging/nuget.rb +39 -0
- data/lib/packaging/paths.rb +376 -0
- data/lib/packaging/platforms.rb +507 -0
- data/lib/packaging/repo.rb +155 -0
- data/lib/packaging/retrieve.rb +75 -0
- data/lib/packaging/rpm.rb +5 -0
- data/lib/packaging/rpm/repo.rb +254 -0
- data/lib/packaging/sign.rb +8 -0
- data/lib/packaging/sign/deb.rb +9 -0
- data/lib/packaging/sign/dmg.rb +41 -0
- data/lib/packaging/sign/ips.rb +57 -0
- data/lib/packaging/sign/msi.rb +124 -0
- data/lib/packaging/sign/rpm.rb +115 -0
- data/lib/packaging/tar.rb +163 -0
- data/lib/packaging/util.rb +146 -0
- data/lib/packaging/util/date.rb +20 -0
- data/lib/packaging/util/execution.rb +85 -0
- data/lib/packaging/util/file.rb +125 -0
- data/lib/packaging/util/git.rb +174 -0
- data/lib/packaging/util/git_tags.rb +73 -0
- data/lib/packaging/util/gpg.rb +66 -0
- data/lib/packaging/util/jenkins.rb +95 -0
- data/lib/packaging/util/misc.rb +69 -0
- data/lib/packaging/util/net.rb +410 -0
- data/lib/packaging/util/os.rb +17 -0
- data/lib/packaging/util/platform.rb +40 -0
- data/lib/packaging/util/rake_utils.rb +112 -0
- data/lib/packaging/util/serialization.rb +19 -0
- data/lib/packaging/util/ship.rb +300 -0
- data/lib/packaging/util/tool.rb +41 -0
- data/lib/packaging/util/version.rb +334 -0
- data/spec/fixtures/config/ext/build_defaults.yaml +2 -0
- data/spec/fixtures/config/ext/project_data.yaml +2 -0
- data/spec/fixtures/configs/components/test_file.json +1 -0
- data/spec/fixtures/configs/components/test_file_2.json +0 -0
- data/spec/fixtures/configs/components/test_file_not_tagged.json +1 -0
- data/spec/fixtures/configs/components/test_file_wrong_ext.txt +0 -0
- data/spec/fixtures/configs/components/test_file_wrong_ext.wrong +0 -0
- data/spec/fixtures/util/pre_tasks.yaml +4 -0
- data/spec/lib/packaging/artifactory_spec.rb +221 -0
- data/spec/lib/packaging/config_spec.rb +576 -0
- data/spec/lib/packaging/deb/repo_spec.rb +157 -0
- data/spec/lib/packaging/deb_spec.rb +52 -0
- data/spec/lib/packaging/gem_spec.rb +86 -0
- data/spec/lib/packaging/paths_spec.rb +418 -0
- data/spec/lib/packaging/platforms_spec.rb +178 -0
- data/spec/lib/packaging/repo_spec.rb +135 -0
- data/spec/lib/packaging/retrieve_spec.rb +100 -0
- data/spec/lib/packaging/rpm/repo_spec.rb +133 -0
- data/spec/lib/packaging/sign_spec.rb +133 -0
- data/spec/lib/packaging/tar_spec.rb +116 -0
- data/spec/lib/packaging/util/execution_spec.rb +56 -0
- data/spec/lib/packaging/util/file_spec.rb +139 -0
- data/spec/lib/packaging/util/git_spec.rb +160 -0
- data/spec/lib/packaging/util/git_tag_spec.rb +36 -0
- data/spec/lib/packaging/util/gpg_spec.rb +64 -0
- data/spec/lib/packaging/util/jenkins_spec.rb +112 -0
- data/spec/lib/packaging/util/misc_spec.rb +31 -0
- data/spec/lib/packaging/util/net_spec.rb +259 -0
- data/spec/lib/packaging/util/os_spec.rb +31 -0
- data/spec/lib/packaging/util/rake_utils_spec.rb +70 -0
- data/spec/lib/packaging/util/ship_spec.rb +199 -0
- data/spec/lib/packaging/util/version_spec.rb +123 -0
- data/spec/lib/packaging_spec.rb +19 -0
- data/spec/spec_helper.rb +22 -0
- data/static_artifacts/PackageInfo.plist +3 -0
- data/tasks/00_utils.rake +214 -0
- data/tasks/30_metrics.rake +33 -0
- data/tasks/apple.rake +268 -0
- data/tasks/archive.rake +69 -0
- data/tasks/build.rake +12 -0
- data/tasks/clean.rake +5 -0
- data/tasks/config.rake +35 -0
- data/tasks/deb.rake +129 -0
- data/tasks/deb_repos.rake +28 -0
- data/tasks/deprecated.rake +130 -0
- data/tasks/doc.rake +20 -0
- data/tasks/education.rake +57 -0
- data/tasks/fetch.rake +60 -0
- data/tasks/gem.rake +159 -0
- data/tasks/jenkins.rake +538 -0
- data/tasks/jenkins_dynamic.rake +202 -0
- data/tasks/load_extras.rake +21 -0
- data/tasks/mock.rake +348 -0
- data/tasks/nightly_repos.rake +286 -0
- data/tasks/pe_deb.rake +12 -0
- data/tasks/pe_rpm.rake +13 -0
- data/tasks/pe_ship.rake +226 -0
- data/tasks/pe_sign.rake +13 -0
- data/tasks/pe_tar.rake +5 -0
- data/tasks/retrieve.rake +52 -0
- data/tasks/rpm.rake +66 -0
- data/tasks/rpm_repos.rake +29 -0
- data/tasks/ship.rake +692 -0
- data/tasks/sign.rake +154 -0
- data/tasks/tag.rake +8 -0
- data/tasks/tar.rake +28 -0
- data/tasks/update.rake +16 -0
- data/tasks/vanagon.rake +35 -0
- data/tasks/vendor_gems.rake +117 -0
- data/tasks/version.rake +33 -0
- data/tasks/z_data_dump.rake +65 -0
- data/templates/README +1 -0
- data/templates/downstream.xml.erb +47 -0
- data/templates/msi.xml.erb +197 -0
- data/templates/packaging.xml.erb +346 -0
- data/templates/repo.xml.erb +117 -0
- metadata +287 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'packaging/sign'
|
|
3
|
+
|
|
4
|
+
describe 'Pkg::Sign' do
|
|
5
|
+
describe 'Pkg::Sign::Rpm' do
|
|
6
|
+
|
|
7
|
+
before :each do
|
|
8
|
+
allow(Pkg::Config).to receive(:gpg_key).and_return('7F438280EF8D349F')
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
describe '#has_sig?' do
|
|
12
|
+
let(:rpm) { 'foo.rpm' }
|
|
13
|
+
let(:el7_signed_response) { <<-DOC
|
|
14
|
+
Header V4 RSA/SHA256 Signature, key ID ef8d349f: NOKEY
|
|
15
|
+
Header SHA1 digest: OK (3cb7e9861e8bc09783a1b6c8d88243a3c16daa81)
|
|
16
|
+
V4 RSA/SHA256 Signature, key ID ef8d349f: NOKEY
|
|
17
|
+
MD5 digest: OK (d5f06ba2a9053de532326d0659ec0d11)
|
|
18
|
+
DOC
|
|
19
|
+
}
|
|
20
|
+
let(:el5_signed_response) { <<-DOC
|
|
21
|
+
Header V3 RSA/SHA1 signature: NOKEY, key ID ef8d349f
|
|
22
|
+
Header SHA1 digest: OK (12ea7bd578097a3aecc5deb8ada6aca6147d68e3)
|
|
23
|
+
V3 RSA/SHA1 signature: NOKEY, key ID ef8d349f
|
|
24
|
+
MD5 digest: OK (27353c6153068a3c9902fcb4ad5b8b92)
|
|
25
|
+
DOC
|
|
26
|
+
}
|
|
27
|
+
let(:sles12_signed_response) { <<-DOC
|
|
28
|
+
Header V4 RSA/SHA256 Signature, key ID ef8d349f: NOKEY
|
|
29
|
+
Header SHA1 digest: OK (e713487cf21ebeb933aefd5ec9211a34603233d2)
|
|
30
|
+
V4 RSA/SHA256 Signature, key ID ef8d349f: NOKEY
|
|
31
|
+
MD5 digest: OK (3093a09ac39bc17751f913e19ca74432)
|
|
32
|
+
DOC
|
|
33
|
+
}
|
|
34
|
+
let(:unsigned_response) { <<-DOC
|
|
35
|
+
Header SHA1 digest: OK (f9404cc95f200568c2dbb1fd24e1119e3e4a40a9)
|
|
36
|
+
MD5 digest: OK (816095f3cee145091c3fa07a0915ce85)
|
|
37
|
+
DOC
|
|
38
|
+
}
|
|
39
|
+
it 'returns true if rpm has been signed (el7)' do
|
|
40
|
+
allow(Pkg::Sign::Rpm).to receive(:`).and_return(el7_signed_response)
|
|
41
|
+
expect(Pkg::Sign::Rpm.has_sig?(rpm)).to be true
|
|
42
|
+
end
|
|
43
|
+
it 'returns true if rpm has been signed (el5)' do
|
|
44
|
+
allow(Pkg::Sign::Rpm).to receive(:`).and_return(el5_signed_response)
|
|
45
|
+
expect(Pkg::Sign::Rpm.has_sig?(rpm)).to be true
|
|
46
|
+
end
|
|
47
|
+
it 'returns true if rpm has been signed (sles12)' do
|
|
48
|
+
allow(Pkg::Sign::Rpm).to receive(:`).and_return(sles12_signed_response)
|
|
49
|
+
expect(Pkg::Sign::Rpm.has_sig?(rpm)).to be true
|
|
50
|
+
end
|
|
51
|
+
it 'returns false if rpm has not been signed' do
|
|
52
|
+
allow(Pkg::Sign::Rpm).to receive(:`).and_return(unsigned_response)
|
|
53
|
+
expect(Pkg::Sign::Rpm.has_sig?(rpm)).to be false
|
|
54
|
+
end
|
|
55
|
+
it 'fails with unexpected output' do
|
|
56
|
+
allow(Pkg::Sign::Rpm).to receive(:`).and_return('something that is definitely not a normal response')
|
|
57
|
+
expect { Pkg::Sign::Rpm.has_sig?(rpm) }.to raise_error(RuntimeError, /Something went wrong checking the signature/)
|
|
58
|
+
end
|
|
59
|
+
it 'fails if gpg_key is not set' do
|
|
60
|
+
allow(Pkg::Config).to receive(:gpg_key).and_return(nil)
|
|
61
|
+
expect { Pkg::Sign::Rpm.has_sig?(rpm) }.to raise_error(RuntimeError, /You need to set `gpg_key` in your build defaults./)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
describe '#sign_all' do
|
|
66
|
+
let(:rpm_directory) { 'foo' }
|
|
67
|
+
let(:rpms_not_to_sign) { [
|
|
68
|
+
"#{rpm_directory}/aix/7.1/PC1/ppc/puppet-agent-5.5.3-1.aix7.1.ppc.rpm",
|
|
69
|
+
] }
|
|
70
|
+
let(:v3_rpms) { [
|
|
71
|
+
"#{rpm_directory}/el/5/PC1/i386/puppet-agent-5.5.3-1.el5.i386.rpm",
|
|
72
|
+
"#{rpm_directory}/sles/11/PC1/x86_64/puppet-agent-5.5.3-1.sles11.x86_64.rpm",
|
|
73
|
+
] }
|
|
74
|
+
let(:v4_rpms) { [
|
|
75
|
+
"#{rpm_directory}/el/7/PC1/aarch64/puppet-agent-5.5.3-1.el7.aarch64.rpm",
|
|
76
|
+
] }
|
|
77
|
+
let(:rpms) { rpms_not_to_sign + v3_rpms + v4_rpms }
|
|
78
|
+
let(:already_signed_rpms) { [
|
|
79
|
+
"#{rpm_directory}/el/6/PC1/x86_64/puppet-agent-5.5.3-1.el6.x86_64.rpm",
|
|
80
|
+
] }
|
|
81
|
+
let(:noarch_rpms) { [
|
|
82
|
+
"#{rpm_directory}/el/6/puppet5/i386/puppetserver-5.3.3-1.el6.noarch.rpm",
|
|
83
|
+
"#{rpm_directory}/el/6/puppet5/x86_64/puppetserver-5.3.3-1.el6.noarch.rpm",
|
|
84
|
+
"#{rpm_directory}/el/7/puppet5/i386/puppetserver-5.3.3-1.el7.noarch.rpm",
|
|
85
|
+
"#{rpm_directory}/el/7/puppet5/x86_64/puppetserver-5.3.3-1.el7.noarch.rpm",
|
|
86
|
+
"#{rpm_directory}/sles/12/puppet5/i386/puppetserver-5.3.3-1.sles12.noarch.rpm",
|
|
87
|
+
"#{rpm_directory}/sles/12/puppet5/x86_64/puppetserver-5.3.3-1.sles12.noarch.rpm"
|
|
88
|
+
] }
|
|
89
|
+
|
|
90
|
+
it 'signs both v3 and v4 rpms' do
|
|
91
|
+
allow(Dir).to receive(:[]).with("#{rpm_directory}/**/*.rpm").and_return(rpms)
|
|
92
|
+
rpms.each do |rpm|
|
|
93
|
+
allow(Pkg::Sign::Rpm).to receive(:has_sig?).and_return(false)
|
|
94
|
+
end
|
|
95
|
+
expect(Pkg::Sign::Rpm).to receive(:legacy_sign).with(v3_rpms.join(' '))
|
|
96
|
+
expect(Pkg::Sign::Rpm).to receive(:sign).with(v4_rpms.join(' '))
|
|
97
|
+
Pkg::Sign::Rpm.sign_all(rpm_directory)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
it 'does not sign AIX rpms' do
|
|
101
|
+
allow(Dir).to receive(:[]).with("#{rpm_directory}/**/*.rpm").and_return(rpms_not_to_sign)
|
|
102
|
+
allow(Pkg::Sign::Rpm).to receive(:has_sig?)
|
|
103
|
+
expect(Pkg::Sign::Rpm).to_not receive(:legacy_sign)
|
|
104
|
+
expect(Pkg::Sign::Rpm).to_not receive(:sign)
|
|
105
|
+
Pkg::Sign::Rpm.sign_all(rpm_directory)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
it 'does not sign already-signed rpms' do
|
|
109
|
+
allow(Dir).to receive(:[]).with("#{rpm_directory}/**/*.rpm").and_return(already_signed_rpms)
|
|
110
|
+
already_signed_rpms.each do |rpm|
|
|
111
|
+
allow(Pkg::Sign::Rpm).to receive(:has_sig?).and_return(true)
|
|
112
|
+
end
|
|
113
|
+
expect(Pkg::Sign::Rpm).to_not receive(:legacy_sign)
|
|
114
|
+
expect(Pkg::Sign::Rpm).to_not receive(:sign)
|
|
115
|
+
Pkg::Sign::Rpm.sign_all(rpm_directory)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
it 'deletes and relinks rpms with the same basename' do
|
|
119
|
+
allow(Dir).to receive(:[]).with("#{rpm_directory}/**/*.rpm").and_return(noarch_rpms)
|
|
120
|
+
allow(Pkg::Sign::Rpm).to receive(:sign)
|
|
121
|
+
allow(Pkg::Sign::Rpm).to receive(:has_sig?)
|
|
122
|
+
expect(FileUtils).to receive(:rm).exactly(noarch_rpms.count/2).times
|
|
123
|
+
expect(FileUtils).to receive(:ln).exactly(noarch_rpms.count/2).times
|
|
124
|
+
Pkg::Sign::Rpm.sign_all(rpm_directory)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
it 'does not fail if there are no rpms to sign' do
|
|
128
|
+
allow(Dir).to receive(:[]).with("#{rpm_directory}/**/*.rpm").and_return([])
|
|
129
|
+
expect(Pkg::Sign::Rpm.sign_all(rpm_directory)).to_not raise_error
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
end
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# -*- ruby -*-
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
describe "tar.rb" do
|
|
5
|
+
let(:project) { "packaging" }
|
|
6
|
+
let(:version) { "1.2.3" }
|
|
7
|
+
let(:files) { [ "a", "b", "c" ] }
|
|
8
|
+
let(:templates) do
|
|
9
|
+
[
|
|
10
|
+
"ext/redhat/spec.erb",
|
|
11
|
+
{ "source" => "ext/debian/control.erb", "target" => "ext/debian/not-a-control-file" },
|
|
12
|
+
"ext/debian/changelog.erb",
|
|
13
|
+
"ext/packaging/thing.erb"
|
|
14
|
+
]
|
|
15
|
+
end
|
|
16
|
+
let(:expanded_templates) do
|
|
17
|
+
[
|
|
18
|
+
"#{PROJECT_ROOT}/ext/redhat/spec.erb",
|
|
19
|
+
{ "source" => "ext/debian/control.erb", "target" => "ext/debian/not-a-control-file" },
|
|
20
|
+
"#{PROJECT_ROOT}/ext/debian/changelog.erb"
|
|
21
|
+
]
|
|
22
|
+
end
|
|
23
|
+
before(:each) do
|
|
24
|
+
Pkg::Config.config_from_hash(
|
|
25
|
+
{
|
|
26
|
+
:templates => templates,
|
|
27
|
+
:project => project,
|
|
28
|
+
:version => version,
|
|
29
|
+
:files => files,
|
|
30
|
+
:project_root => PROJECT_ROOT,
|
|
31
|
+
:packaging_root => "ext/packaging"
|
|
32
|
+
})
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
describe '#initialize' do
|
|
36
|
+
it 'should always mark ext/packaging and pkg directories as excluded files' do
|
|
37
|
+
Pkg::Config.tar_excludes = ['foo']
|
|
38
|
+
expect(Pkg::Tar.new.excludes).to eql(['foo', 'pkg', 'ext/packaging'])
|
|
39
|
+
|
|
40
|
+
Pkg::Config.tar_excludes = []
|
|
41
|
+
expect(Pkg::Tar.new.excludes).to eql(['pkg', 'ext/packaging'])
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it 'should archive the entire project directory by default' do
|
|
45
|
+
Pkg::Config.files = nil
|
|
46
|
+
expect(Pkg::Tar.new.files).to eql(Dir.glob('*'))
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it 'should archive the user-specified list of files' do
|
|
50
|
+
expect(Pkg::Tar.new.files).to eql(files)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
describe "#expand_templates" do
|
|
55
|
+
it "should be invoked when Pkg::Config.templates is set" do
|
|
56
|
+
Pkg::Tar.any_instance.should_receive(:expand_templates)
|
|
57
|
+
Pkg::Tar.new
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "packaging templates should be filtered and paths should be expanded" do
|
|
61
|
+
templates.each do |temp|
|
|
62
|
+
if temp.is_a?(String)
|
|
63
|
+
Dir.stub(:glob).with(File.join(PROJECT_ROOT, temp)).and_return(File.join(PROJECT_ROOT, temp))
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
tar = Pkg::Tar.new
|
|
68
|
+
tar.templates = templates
|
|
69
|
+
tar.expand_templates
|
|
70
|
+
tar.templates.should eq expanded_templates
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
describe "#template" do
|
|
75
|
+
before(:each) do
|
|
76
|
+
Pkg::Config.templates = expanded_templates
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it "should handle hashes and strings correctly" do
|
|
80
|
+
# Set up correct stubs and expectations
|
|
81
|
+
expanded_templates.each do |temp|
|
|
82
|
+
if temp.is_a?(String)
|
|
83
|
+
full_path_temp = File.join(PROJECT_ROOT, temp)
|
|
84
|
+
target = full_path_temp.sub(File.extname(full_path_temp), "")
|
|
85
|
+
elsif temp.is_a?(Hash)
|
|
86
|
+
full_path_temp = File.join(PROJECT_ROOT, temp["source"])
|
|
87
|
+
target = File.join(PROJECT_ROOT, temp["target"])
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
Dir.stub(:glob).with(full_path_temp).and_return(full_path_temp)
|
|
91
|
+
File.stub(:exist?).with(full_path_temp).and_return(true)
|
|
92
|
+
Pkg::Util::File.should_receive(:erb_file).with(full_path_temp, target, true, :binding => an_instance_of(Binding))
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
Pkg::Tar.new.template
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
it "should raise an error if the template source can't be found" do
|
|
99
|
+
# Set up correct stubs and expectations
|
|
100
|
+
expanded_templates.each do |temp|
|
|
101
|
+
if temp.is_a?(String)
|
|
102
|
+
full_path_temp = File.join(PROJECT_ROOT, temp)
|
|
103
|
+
target = full_path_temp.sub(File.extname(full_path_temp), "")
|
|
104
|
+
elsif temp.is_a?(Hash)
|
|
105
|
+
full_path_temp = File.join(PROJECT_ROOT, temp["source"])
|
|
106
|
+
target = File.join(PROJECT_ROOT, temp["target"])
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
Dir.stub(:glob).with(full_path_temp).and_return(full_path_temp)
|
|
110
|
+
File.stub(:exist?).with(full_path_temp).and_return(false)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
expect { Pkg::Tar.new.template }.to raise_error RuntimeError
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe "Pkg::Util::Execution" do
|
|
4
|
+
let(:command) { "/usr/bin/do-something-important --arg1=thing2" }
|
|
5
|
+
let(:output) { "the command returns some really cool stuff that may be useful later" }
|
|
6
|
+
|
|
7
|
+
describe "#success?" do
|
|
8
|
+
it "should return false on failure" do
|
|
9
|
+
%x{false}
|
|
10
|
+
Pkg::Util::Execution.success?.should be_false
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "should return true on success" do
|
|
14
|
+
%x{true}
|
|
15
|
+
Pkg::Util::Execution.success?.should be_true
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "should return false when passed an exitstatus object from a failure" do
|
|
19
|
+
%x{false}
|
|
20
|
+
Pkg::Util::Execution.success?($?).should be_false
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "should return true when passed and exitstatus object from a success" do
|
|
24
|
+
%x{true}
|
|
25
|
+
Pkg::Util::Execution.success?($?).should be_true
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
describe "#ex" do
|
|
30
|
+
it "should raise an error if the command fails" do
|
|
31
|
+
Pkg::Util::Execution.should_receive(:`).with(command).and_return(true)
|
|
32
|
+
Pkg::Util::Execution.should_receive(:success?).and_return(false)
|
|
33
|
+
expect{ Pkg::Util::Execution.ex(command) }.to raise_error(RuntimeError)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "should return the output of the command for success" do
|
|
37
|
+
Pkg::Util::Execution.should_receive(:`).with(command).and_return(output)
|
|
38
|
+
Pkg::Util::Execution.should_receive(:success?).and_return(true)
|
|
39
|
+
Pkg::Util::Execution.ex(command).should == output
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
describe "#capture3" do
|
|
44
|
+
it "should raise an error if the command fails" do
|
|
45
|
+
Open3.should_receive(:capture3).with(command).and_return([output, '', 1])
|
|
46
|
+
Pkg::Util::Execution.should_receive(:success?).with(1).and_return(false)
|
|
47
|
+
expect{ Pkg::Util::Execution.capture3(command) }.to raise_error(RuntimeError, /#{output}/)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "should return the output of the command for success" do
|
|
51
|
+
Open3.should_receive(:capture3).with(command).and_return([output, '', 0])
|
|
52
|
+
Pkg::Util::Execution.should_receive(:success?).with(0).and_return(true)
|
|
53
|
+
Pkg::Util::Execution.capture3(command).should == [output, '', 0]
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe "Pkg::Util::File" do
|
|
4
|
+
let(:source) { "/tmp/placething.tar.gz" }
|
|
5
|
+
let(:target) { "/tmp" }
|
|
6
|
+
let(:options) { "--thing-for-tar" }
|
|
7
|
+
let(:tar) { "/usr/bin/tar" }
|
|
8
|
+
let(:files) { ["foo.rb", "foo/bar.rb"] }
|
|
9
|
+
let(:symlinks) { ["bar.rb"] }
|
|
10
|
+
let(:dirs) { ["foo"] }
|
|
11
|
+
let(:empty_dirs) { ["bar"] }
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
describe "#untar_into" do
|
|
15
|
+
before :each do
|
|
16
|
+
Pkg::Util::Tool.stub(:find_tool).with('tar', :required => true) { tar }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "raises an exception if the source doesn't exist" do
|
|
20
|
+
Pkg::Util::File.should_receive(:file_exists?).with(source, {:required => true}).and_raise(RuntimeError)
|
|
21
|
+
Pkg::Util::Execution.should_not_receive(:capture3)
|
|
22
|
+
expect { Pkg::Util::File.untar_into(source) }.to raise_error(RuntimeError)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "unpacks the tarball to the current directory if no target is passed" do
|
|
26
|
+
Pkg::Util::File.should_receive(:file_exists?).with(source, {:required => true}) { true }
|
|
27
|
+
Pkg::Util::Execution.should_receive(:capture3).with("#{tar} -xf #{source}")
|
|
28
|
+
Pkg::Util::File.untar_into(source)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "unpacks the tarball to the current directory with options if no target is passed" do
|
|
32
|
+
Pkg::Util::File.should_receive(:file_exists?).with(source, {:required => true}) { true }
|
|
33
|
+
Pkg::Util::Execution.should_receive(:capture3).with("#{tar} #{options} -xf #{source}")
|
|
34
|
+
Pkg::Util::File.untar_into(source, nil, options)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "unpacks the tarball into the target" do
|
|
38
|
+
File.stub(:capture3ist?).with(source) { true }
|
|
39
|
+
Pkg::Util::File.should_receive(:file_exists?).with(source, {:required => true}) { true }
|
|
40
|
+
Pkg::Util::File.should_receive(:file_writable?).with(target) { true }
|
|
41
|
+
Pkg::Util::Execution.should_receive(:capture3).with("#{tar} -C #{target} -xf #{source}")
|
|
42
|
+
Pkg::Util::File.untar_into(source, target)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "unpacks the tarball into the target with options passed" do
|
|
46
|
+
File.stub(:capture3ist?).with(source) { true }
|
|
47
|
+
Pkg::Util::File.should_receive(:file_exists?).with(source, {:required => true}) { true }
|
|
48
|
+
Pkg::Util::File.should_receive(:file_writable?).with(target) { true }
|
|
49
|
+
Pkg::Util::Execution.should_receive(:capture3).with("#{tar} #{options} -C #{target} -xf #{source}")
|
|
50
|
+
Pkg::Util::File.untar_into(source, target, options)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
describe "#files_with_ext" do
|
|
55
|
+
it "returns nothing if there are no files with that extension" do
|
|
56
|
+
Pkg::Util::File.files_with_ext("./spec/fixtures/configs/components", ".fake").should be_empty
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it "returns only the files with that extension" do
|
|
60
|
+
expect(Pkg::Util::File.files_with_ext("./spec/fixtures/configs/components", ".json")).to include("./spec/fixtures/configs/components/test_file.json")
|
|
61
|
+
expect(Pkg::Util::File.files_with_ext("./spec/fixtures/configs/components", ".json")).to include("./spec/fixtures/configs/components/test_file_2.json")
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
describe "#install_files_into_dir" do
|
|
66
|
+
it "selects the correct files to install" do
|
|
67
|
+
Pkg::Config.load_defaults
|
|
68
|
+
workdir = Pkg::Util::File.mktemp
|
|
69
|
+
patterns = []
|
|
70
|
+
|
|
71
|
+
# Set up a bunch of default settings for these to avoid a lot more stubbing in each section below
|
|
72
|
+
File.stub(:file?) { false }
|
|
73
|
+
File.stub(:symlink?) { false }
|
|
74
|
+
File.stub(:directory?) { false }
|
|
75
|
+
Pkg::Util::File.stub(:empty_dir?) { false }
|
|
76
|
+
|
|
77
|
+
# Files should have the path made and should be copied
|
|
78
|
+
files.each do |file|
|
|
79
|
+
File.stub(:file?).with(file).and_return(true)
|
|
80
|
+
Dir.stub(:[]).with(file).and_return(file)
|
|
81
|
+
FileUtils.should_receive(:mkpath).with(File.dirname(File.join(workdir, file)), :verbose => false)
|
|
82
|
+
FileUtils.should_receive(:cp).with(file, File.join(workdir, file), :verbose => false, :preserve => true)
|
|
83
|
+
patterns << file
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# Symlinks should have the path made and should be copied
|
|
87
|
+
symlinks.each do |file|
|
|
88
|
+
File.stub(:symlink?).with(file).and_return(true)
|
|
89
|
+
Dir.stub(:[]).with(file).and_return(file)
|
|
90
|
+
FileUtils.should_receive(:mkpath).with(File.dirname(File.join(workdir, file)), :verbose => false)
|
|
91
|
+
FileUtils.should_receive(:cp).with(file, File.join(workdir, file), :verbose => false, :preserve => true)
|
|
92
|
+
patterns << file
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# Dirs should be added to patterns but no acted upon
|
|
96
|
+
dirs.each do |dir|
|
|
97
|
+
File.stub(:directory?).with(dir).and_return(true)
|
|
98
|
+
Dir.stub(:[]).with("#{dir}/**/*").and_return(dir)
|
|
99
|
+
FileUtils.should_not_receive(:mkpath).with(File.dirname(File.join(workdir, dir)), :verbose => false)
|
|
100
|
+
FileUtils.should_not_receive(:cp).with(dir, File.join(workdir, dir), :verbose => false, :preserve => true)
|
|
101
|
+
patterns << dir
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# Empty dirs should have the path created and nothing copied
|
|
105
|
+
empty_dirs.each do |dir|
|
|
106
|
+
Pkg::Util::File.stub(:empty_dir?).with(dir).and_return(true)
|
|
107
|
+
Dir.stub(:[]).with(dir).and_return(dir)
|
|
108
|
+
FileUtils.should_receive(:mkpath).with(File.join(workdir, dir), :verbose => false)
|
|
109
|
+
FileUtils.should_not_receive(:cp).with(dir, File.join(workdir, dir), :verbose => false, :preserve => true)
|
|
110
|
+
patterns << dir
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
Pkg::Util::File.install_files_into_dir(patterns, workdir)
|
|
114
|
+
FileUtils.rm_rf workdir
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
describe "#directories" do
|
|
119
|
+
it "returns nil if there is no directory" do
|
|
120
|
+
File.should_receive(:directory?).with("/tmp").and_return(false)
|
|
121
|
+
Pkg::Util::File.directories("/tmp").should be_nil
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
it "returns the empty array if there are no dirs in the directory" do
|
|
125
|
+
File.should_receive(:directory?).with("/tmp").and_return(true)
|
|
126
|
+
Dir.should_receive(:glob).with("*").and_return([])
|
|
127
|
+
Pkg::Util::File.directories("/tmp").should be_empty
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
it "returns an array of the top level directories inside a directory" do
|
|
131
|
+
File.stub(:directory?) { false }
|
|
132
|
+
["/tmp", "/tmp/dir", "/tmp/other_dir"].each do |dir|
|
|
133
|
+
File.should_receive(:directory?).with(dir).and_return(true)
|
|
134
|
+
end
|
|
135
|
+
Dir.should_receive(:glob).with("*").and_return(["/tmp/file", "/tmp/dir", "/tmp/other_dir"])
|
|
136
|
+
Pkg::Util::File.directories("/tmp").should eq(["/tmp/dir", "/tmp/other_dir"])
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# -*- ruby -*-
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
require 'packaging/util/git'
|
|
4
|
+
|
|
5
|
+
# rubocop:disable Metrics/BlockLength
|
|
6
|
+
describe 'Pkg::Util::Git' do
|
|
7
|
+
context '#commit_file' do
|
|
8
|
+
let(:file) { 'thing.txt' }
|
|
9
|
+
let(:message) { 'foo' }
|
|
10
|
+
|
|
11
|
+
it 'should commit a file with no message, giving changes as the message instead' do
|
|
12
|
+
allow(Pkg::Util::Git).to receive(:fail_unless_repo)
|
|
13
|
+
expect(Pkg::Util::Execution).to receive(:capture3).with("#{Pkg::Util::Tool::GIT} diff HEAD #{file}")
|
|
14
|
+
expect(Pkg::Util::Execution).to receive(:capture3).with("#{Pkg::Util::Tool::GIT} commit #{file} -m \"Commit changes in #{file}\" &> /dev/null")
|
|
15
|
+
Pkg::Util::Git.commit_file(file)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it 'should commit a file with foo as message' do
|
|
19
|
+
allow(Pkg::Util::Git).to receive(:fail_unless_repo)
|
|
20
|
+
expect(Pkg::Util::Execution).to receive(:capture3).with("#{Pkg::Util::Tool::GIT} diff HEAD #{file}")
|
|
21
|
+
expect(Pkg::Util::Execution).to receive(:capture3).with("#{Pkg::Util::Tool::GIT} commit #{file} -m \"Commit #{message} in #{file}\" &> /dev/null")
|
|
22
|
+
Pkg::Util::Git.commit_file(file, message)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
context '#tag' do
|
|
27
|
+
let(:version) { '1.2.3' }
|
|
28
|
+
let(:gpg_key) { '1231242354asdfawd' }
|
|
29
|
+
around do |example|
|
|
30
|
+
prev_gpg_key = Pkg::Config.gpg_key
|
|
31
|
+
Pkg::Config.gpg_key = gpg_key
|
|
32
|
+
example.run
|
|
33
|
+
Pkg::Config.gpg_key = prev_gpg_key
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it 'should not fail' do
|
|
37
|
+
allow(Pkg::Util::Git).to receive(:fail_unless_repo)
|
|
38
|
+
expect(Pkg::Util::Execution).to receive(:capture3).with("#{Pkg::Util::Tool::GIT} tag -s -u #{gpg_key} -m '#{version}' #{version}")
|
|
39
|
+
Pkg::Util::Git.tag(version)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
context '#bundle' do
|
|
44
|
+
let(:treeish) { 'foo' }
|
|
45
|
+
let(:appendix) { 'append' }
|
|
46
|
+
let(:output_dir) { '/path/to/place' }
|
|
47
|
+
let(:version) { '1.2.3' }
|
|
48
|
+
let(:project) { 'fooproj' }
|
|
49
|
+
let(:string) { 'bar' }
|
|
50
|
+
let(:temp) { '/other/path/to/place' }
|
|
51
|
+
around do |example|
|
|
52
|
+
prev_project = Pkg::Config.project
|
|
53
|
+
prev_version = Pkg::Config.version
|
|
54
|
+
Pkg::Config.project = project
|
|
55
|
+
Pkg::Config.version = version
|
|
56
|
+
example.run
|
|
57
|
+
Pkg::Config.project = prev_project
|
|
58
|
+
Pkg::Config.version = prev_version
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it 'should create a git bundle with random appendix and random output directory' do
|
|
62
|
+
allow(Pkg::Util::Git).to receive(:fail_unless_repo)
|
|
63
|
+
allow(Pkg::Util::File).to receive(:mktemp) { temp }
|
|
64
|
+
allow(Pkg::Util).to receive(:rand_string) { string }
|
|
65
|
+
expect(Pkg::Util::Execution).to receive(:capture3).with("#{Pkg::Util::Tool::GIT} bundle create #{temp}/#{project}-#{version}-#{string} #{treeish} --tags")
|
|
66
|
+
expect(Dir).to receive(:chdir).with(temp)
|
|
67
|
+
Pkg::Util::Git.bundle(treeish)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it 'should create a git bundle with random output directory' do
|
|
71
|
+
allow(Pkg::Util::Git).to receive(:fail_unless_repo)
|
|
72
|
+
allow(Pkg::Util::File).to receive(:mktemp) { temp }
|
|
73
|
+
expect(Pkg::Util::Execution).to receive(:capture3).with("#{Pkg::Util::Tool::GIT} bundle create #{temp}/#{project}-#{version}-#{appendix} #{treeish} --tags")
|
|
74
|
+
expect(Dir).to receive(:chdir).with(temp)
|
|
75
|
+
Pkg::Util::Git.bundle(treeish, appendix)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
it 'should create a git bundle' do
|
|
79
|
+
allow(Pkg::Util::Git).to receive(:fail_unless_repo)
|
|
80
|
+
expect(Pkg::Util::Execution).to receive(:capture3).with("#{Pkg::Util::Tool::GIT} bundle create #{output_dir}/#{project}-#{version}-#{appendix} #{treeish} --tags")
|
|
81
|
+
expect(Dir).to receive(:chdir).with(output_dir)
|
|
82
|
+
Pkg::Util::Git.bundle(treeish, appendix, output_dir)
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
context '#pull' do
|
|
87
|
+
let(:remote) { 'rand.url' }
|
|
88
|
+
let(:branch) { 'foo' }
|
|
89
|
+
|
|
90
|
+
it 'should pull the branch' do
|
|
91
|
+
allow(Pkg::Util::Git).to receive(:fail_unless_repo)
|
|
92
|
+
expect(Pkg::Util::Execution).to receive(:capture3).with("#{Pkg::Util::Tool::GIT} pull #{remote} #{branch}")
|
|
93
|
+
Pkg::Util::Git.pull(remote, branch)
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
context '#describe' do
|
|
98
|
+
before(:each) do
|
|
99
|
+
@project_root = Dir.pwd
|
|
100
|
+
Pkg::Config.project_root = @project_root
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
let(:describe) { '0.5.0-25-g746e755-dirty' }
|
|
104
|
+
let(:describe_no_dirty) { '0.5.0-25-g746e755' }
|
|
105
|
+
|
|
106
|
+
it 'should default to --tags --dirty' do
|
|
107
|
+
expect(Pkg::Util::Execution).to receive(:capture3).with("#{Pkg::Util::Tool::GIT} describe --tags --dirty").and_return([describe, '', 0])
|
|
108
|
+
expect(Pkg::Util::Execution).to receive(:success?).with(0).and_return(true)
|
|
109
|
+
Pkg::Util::Git.describe
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
it 'should allow you to pass no arguments to describe' do
|
|
113
|
+
expect(Pkg::Util::Execution).to receive(:capture3).with("#{Pkg::Util::Tool::GIT} describe ").and_return([describe_no_dirty, '', 0])
|
|
114
|
+
expect(Pkg::Util::Execution).to receive(:success?).with(0).and_return(true)
|
|
115
|
+
Pkg::Util::Git.describe('')
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
context '#sha_or_tag' do
|
|
120
|
+
let(:sha) { '20a338b33e2fc1cbaee27b69de5eb2d06637a7c4' }
|
|
121
|
+
let(:tag) { '2.0.4' }
|
|
122
|
+
|
|
123
|
+
it 'returns a sha if the repo is not tagged' do
|
|
124
|
+
allow(Pkg::Util::Git).to receive(:ref_type) { 'sha' }
|
|
125
|
+
allow(Pkg::Util::Git).to receive(:sha) { sha }
|
|
126
|
+
expect(Pkg::Util::Git.sha_or_tag).to eq sha
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
it 'returns a tag if the repo is tagged' do
|
|
130
|
+
allow(Pkg::Util::Git).to receive(:ref_type) { 'tag' }
|
|
131
|
+
allow(Pkg::Util::Git).to receive(:describe) { tag }
|
|
132
|
+
expect(Pkg::Util::Git.sha_or_tag).to eq tag
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
context '#tagged?' do
|
|
137
|
+
let(:sha) { '20a338b33e2fc1cbaee27b69de5eb2d06637a7c4' }
|
|
138
|
+
let(:tag) { '2.0.4' }
|
|
139
|
+
|
|
140
|
+
it 'returns false if we are working on a sha' do
|
|
141
|
+
allow(Pkg::Util::Git).to receive(:ref_type) { 'tag' }
|
|
142
|
+
expect(Pkg::Util::Git.tagged?).to be true
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
it 'returns true if we are working on a tag' do
|
|
146
|
+
allow(Pkg::Util::Git).to receive(:ref_type) { 'sha' }
|
|
147
|
+
expect(Pkg::Util::Git.tagged?).to be false
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
context '#remote_tagged?' do
|
|
152
|
+
it 'reports Yes on tagged component' do
|
|
153
|
+
expect(Pkg::Util::Git.remote_tagged?('git://github.com/puppetlabs/leatherman.git', 'refs/tags/0.6.2')).to be(true)
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
it 'reports No on non-tagged component' do
|
|
157
|
+
expect(Pkg::Util::Git.remote_tagged?('git://github.com/puppetlabs/leatherman.git', '4eef05389ebf418b62af17406c7f9f13fa51f975')).to be(false)
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
end
|