packaging 0.108.2 → 0.109.0
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 +4 -4
- data/README.md +0 -2
- data/lib/packaging/artifactory.rb +15 -10
- data/lib/packaging/config/validations.rb +1 -1
- data/lib/packaging/config.rb +5 -5
- data/lib/packaging/deb/repo.rb +4 -4
- data/lib/packaging/nuget.rb +1 -1
- data/lib/packaging/paths.rb +4 -3
- data/lib/packaging/sign/msi.rb +6 -8
- data/lib/packaging/util/execution.rb +1 -1
- data/lib/packaging/util/ezbake.rb +1 -1
- data/lib/packaging/util/file.rb +4 -6
- data/lib/packaging/util/net.rb +8 -12
- data/lib/packaging/util/ship.rb +17 -7
- data/lib/packaging/util/tool.rb +1 -1
- data/lib/packaging/util/version.rb +7 -5
- data/spec/lib/packaging/config_spec.rb +300 -279
- data/spec/lib/packaging/deb/repo_spec.rb +138 -76
- data/spec/lib/packaging/deb_spec.rb +28 -25
- data/spec/lib/packaging/repo_spec.rb +52 -31
- data/spec/lib/packaging/rpm/repo_spec.rb +18 -37
- data/spec/lib/packaging/sign_spec.rb +22 -43
- data/spec/lib/packaging/tar_spec.rb +48 -44
- data/spec/lib/packaging/util/execution_spec.rb +32 -32
- data/spec/lib/packaging/util/file_spec.rb +112 -75
- data/spec/lib/packaging/util/gpg_spec.rb +24 -19
- data/spec/lib/packaging/util/jenkins_spec.rb +79 -48
- data/spec/lib/packaging/util/misc_spec.rb +13 -8
- data/spec/lib/packaging/util/net_spec.rb +193 -152
- data/spec/lib/packaging/util/rake_utils_spec.rb +24 -18
- data/spec/lib/packaging_spec.rb +7 -9
- data/tasks/apple.rake +7 -8
- data/tasks/deb.rake +1 -1
- data/tasks/fetch.rake +2 -2
- data/tasks/mock.rake +3 -3
- data/tasks/nightly_repos.rake +11 -9
- data/tasks/rpm.rake +2 -3
- data/tasks/ship.rake +4 -2
- data/tasks/sign.rake +8 -10
- data/tasks/z_data_dump.rake +3 -3
- metadata +46 -33
@@ -7,7 +7,7 @@ describe 'Pkg::Sign' do
|
|
7
7
|
allow(Pkg::Config).to receive(:gpg_key).and_return('7F438280EF8D349F')
|
8
8
|
end
|
9
9
|
|
10
|
-
describe '#
|
10
|
+
describe '#has_sig?' do
|
11
11
|
let(:rpm) { 'foo.rpm' }
|
12
12
|
let(:el7_signed_response) do
|
13
13
|
<<~DOC
|
@@ -17,7 +17,6 @@ describe 'Pkg::Sign' do
|
|
17
17
|
MD5 digest: OK (d5f06ba2a9053de532326d0659ec0d11)
|
18
18
|
DOC
|
19
19
|
end
|
20
|
-
|
21
20
|
let(:sles12_signed_response) do
|
22
21
|
<<~DOC
|
23
22
|
Header V4 RSA/SHA256 Signature, key ID ef8d349f: NOKEY
|
@@ -26,36 +25,34 @@ describe 'Pkg::Sign' do
|
|
26
25
|
MD5 digest: OK (3093a09ac39bc17751f913e19ca74432)
|
27
26
|
DOC
|
28
27
|
end
|
29
|
-
|
30
28
|
let(:unsigned_response) do
|
31
29
|
<<~DOC
|
32
30
|
Header SHA1 digest: OK (f9404cc95f200568c2dbb1fd24e1119e3e4a40a9)
|
33
31
|
MD5 digest: OK (816095f3cee145091c3fa07a0915ce85)
|
34
32
|
DOC
|
35
33
|
end
|
36
|
-
|
37
34
|
it 'returns true if rpm has been signed (el7)' do
|
38
35
|
allow(Pkg::Sign::Rpm).to receive(:`).and_return(el7_signed_response)
|
39
|
-
expect(Pkg::Sign::Rpm.
|
36
|
+
expect(Pkg::Sign::Rpm.has_sig?(rpm)).to be true
|
40
37
|
end
|
41
38
|
it 'returns true if rpm has been signed (sles12)' do
|
42
39
|
allow(Pkg::Sign::Rpm).to receive(:`).and_return(sles12_signed_response)
|
43
|
-
expect(Pkg::Sign::Rpm.
|
40
|
+
expect(Pkg::Sign::Rpm.has_sig?(rpm)).to be true
|
44
41
|
end
|
45
42
|
it 'returns false if rpm has not been signed' do
|
46
43
|
allow(Pkg::Sign::Rpm).to receive(:`).and_return(unsigned_response)
|
47
|
-
expect(Pkg::Sign::Rpm.
|
44
|
+
expect(Pkg::Sign::Rpm.has_sig?(rpm)).to be false
|
48
45
|
end
|
49
46
|
it 'fails with unexpected output' do
|
50
47
|
allow(Pkg::Sign::Rpm)
|
51
48
|
.to receive(:`)
|
52
49
|
.and_return('something that is definitely not a normal response')
|
53
|
-
expect { Pkg::Sign::Rpm.
|
50
|
+
expect { Pkg::Sign::Rpm.has_sig?(rpm) }
|
54
51
|
.to raise_error(RuntimeError, /Something went wrong checking the signature/)
|
55
52
|
end
|
56
53
|
it 'fails if gpg_key is not set' do
|
57
54
|
allow(Pkg::Config).to receive(:gpg_key).and_return(nil)
|
58
|
-
expect { Pkg::Sign::Rpm.
|
55
|
+
expect { Pkg::Sign::Rpm.has_sig?(rpm) }
|
59
56
|
.to raise_error(RuntimeError, /You need to set `gpg_key` in your build defaults./)
|
60
57
|
end
|
61
58
|
end
|
@@ -63,59 +60,41 @@ describe 'Pkg::Sign' do
|
|
63
60
|
describe '#sign_all' do
|
64
61
|
let(:rpm_directory) { Dir.mktmpdir }
|
65
62
|
let(:rpms_not_to_sign) do
|
66
|
-
[
|
63
|
+
%W[#{rpm_directory}/aix/7.1/PC1/ppc/puppet-agent-5.5.3-1.aix7.1.ppc.rpm]
|
67
64
|
end
|
68
|
-
|
69
65
|
let(:v3_rpms) do
|
70
|
-
[
|
66
|
+
%W[#{rpm_directory}/sles/11/PC1/x86_64/puppet-agent-5.5.3-1.sles11.x86_64.rpm]
|
71
67
|
end
|
72
|
-
|
73
68
|
let(:v4_rpms) do
|
74
|
-
[
|
69
|
+
%W[%#{rpm_directory}/el/7/PC1/aarch64/puppet-agent-5.5.3-1.el7.aarch64.rpm]
|
75
70
|
end
|
76
|
-
|
77
71
|
let(:rpms) { rpms_not_to_sign + v3_rpms + v4_rpms }
|
78
|
-
|
79
72
|
let(:already_signed_rpms) do
|
80
|
-
[
|
73
|
+
%W[#{rpm_directory}/el/6/PC1/x86_64/puppet-agent-5.5.3-1.el6.x86_64.rpm]
|
81
74
|
end
|
82
|
-
|
83
75
|
let(:noarch_rpms) do
|
84
|
-
[
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
76
|
+
%W[
|
77
|
+
#{rpm_directory}/el/6/puppet5/i386/puppetserver-5.3.3-1.el6.noarch.rpm
|
78
|
+
#{rpm_directory}/el/6/puppet5/x86_64/puppetserver-5.3.3-1.el6.noarch.rpm
|
79
|
+
#{rpm_directory}/el/7/puppet5/i386/puppetserver-5.3.3-1.el7.noarch.rpm
|
80
|
+
#{rpm_directory}/el/7/puppet5/x86_64/puppetserver-5.3.3-1.el7.noarch.rpm
|
81
|
+
#{rpm_directory}/sles/12/puppet5/i386/puppetserver-5.3.3-1.sles12.noarch.rpm
|
82
|
+
#{rpm_directory}/sles/12/puppet5/x86_64/puppetserver-5.3.3-1.sles12.noarch.rpm
|
91
83
|
]
|
92
84
|
end
|
93
|
-
|
94
85
|
it 'signs both v3 and v4 rpms' do
|
95
86
|
allow(Dir).to receive(:[]).with("#{rpm_directory}/**/*.rpm").and_return(rpms)
|
96
87
|
rpms.each do |rpm|
|
97
88
|
allow(Pkg::Sign::Rpm).to receive(:signed?).and_return(false)
|
98
89
|
end
|
99
|
-
|
100
|
-
|
101
|
-
v4_items = v4_rpms.length
|
102
|
-
|
103
|
-
expect(Pkg::Sign::Rpm)
|
104
|
-
.to receive(:sign)
|
105
|
-
.with(v3_rpms.join(' '), :v3)
|
106
|
-
.exactly(v3_items).times
|
107
|
-
expect(Pkg::Sign::Rpm)
|
108
|
-
.to receive(:sign)
|
109
|
-
.with(v4_rpms.join(' '), :v4)
|
110
|
-
.exactly(v4_items).times
|
111
|
-
|
90
|
+
expect(Pkg::Sign::Rpm).to receive(:sign).with(v3_rpms.join(' '), :v3)
|
91
|
+
expect(Pkg::Sign::Rpm).to receive(:sign).with(v4_rpms.join(' '), :v4)
|
112
92
|
Pkg::Sign::Rpm.sign_all(rpm_directory)
|
113
93
|
end
|
114
94
|
|
115
95
|
it 'does not sign AIX rpms' do
|
116
96
|
allow(Dir).to receive(:[]).with("#{rpm_directory}/**/*.rpm").and_return(rpms_not_to_sign)
|
117
|
-
allow(Pkg::Sign::Rpm).to receive(:signed?)
|
118
|
-
expect(Pkg::Sign::Rpm).to_not receive(:legacy_sign)
|
97
|
+
allow(Pkg::Sign::Rpm).to receive(:signed?).and_return(false)
|
119
98
|
expect(Pkg::Sign::Rpm).to_not receive(:sign)
|
120
99
|
Pkg::Sign::Rpm.sign_all(rpm_directory)
|
121
100
|
end
|
@@ -133,7 +112,7 @@ describe 'Pkg::Sign' do
|
|
133
112
|
it 'deletes and relinks rpms with the same basename' do
|
134
113
|
allow(Dir).to receive(:[]).with("#{rpm_directory}/**/*.rpm").and_return(noarch_rpms)
|
135
114
|
allow(Pkg::Sign::Rpm).to receive(:sign)
|
136
|
-
allow(Pkg::Sign::Rpm).to receive(:signed?)
|
115
|
+
allow(Pkg::Sign::Rpm).to receive(:signed?).and_return(false)
|
137
116
|
expect(FileUtils).to receive(:rm).exactly(noarch_rpms.count / 2).times
|
138
117
|
expect(FileUtils).to receive(:ln).exactly(noarch_rpms.count / 2).times
|
139
118
|
Pkg::Sign::Rpm.sign_all(rpm_directory)
|
@@ -141,7 +120,7 @@ describe 'Pkg::Sign' do
|
|
141
120
|
|
142
121
|
it 'does not fail if there are no rpms to sign' do
|
143
122
|
allow(Dir).to receive(:[]).with("#{rpm_directory}/**/*.rpm").and_return([])
|
144
|
-
expect
|
123
|
+
expect { Pkg::Sign::Rpm.sign_all(rpm_directory) }.to_not raise_error
|
145
124
|
end
|
146
125
|
end
|
147
126
|
end
|
@@ -1,35 +1,36 @@
|
|
1
1
|
# -*- ruby -*-
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
describe
|
5
|
-
let(:project) {
|
6
|
-
let(:version) {
|
7
|
-
let(:files) { [
|
4
|
+
describe 'tar.rb' do
|
5
|
+
let(:project) { 'packaging' }
|
6
|
+
let(:version) { '1.2.3' }
|
7
|
+
let(:files) { %w[a b c] }
|
8
8
|
let(:templates) do
|
9
9
|
[
|
10
|
-
|
11
|
-
{
|
12
|
-
|
13
|
-
|
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
14
|
]
|
15
15
|
end
|
16
16
|
let(:expanded_templates) do
|
17
17
|
[
|
18
18
|
"#{PROJECT_ROOT}/ext/redhat/spec.erb",
|
19
|
-
{
|
19
|
+
{ 'source' => 'ext/debian/control.erb', 'target' => 'ext/debian/not-a-control-file' },
|
20
20
|
"#{PROJECT_ROOT}/ext/debian/changelog.erb"
|
21
21
|
]
|
22
22
|
end
|
23
23
|
before(:each) do
|
24
24
|
Pkg::Config.config_from_hash(
|
25
25
|
{
|
26
|
-
:
|
27
|
-
:
|
28
|
-
:
|
29
|
-
:
|
30
|
-
:
|
31
|
-
:
|
32
|
-
}
|
26
|
+
templates: templates,
|
27
|
+
project: project,
|
28
|
+
version: version,
|
29
|
+
files: files,
|
30
|
+
project_root: PROJECT_ROOT,
|
31
|
+
packaging_root: 'ext/packaging'
|
32
|
+
}
|
33
|
+
)
|
33
34
|
end
|
34
35
|
|
35
36
|
describe '#initialize' do
|
@@ -51,63 +52,66 @@ describe "tar.rb" do
|
|
51
52
|
end
|
52
53
|
end
|
53
54
|
|
54
|
-
describe
|
55
|
-
it
|
56
|
-
Pkg::Tar.
|
55
|
+
describe '#expand_templates' do
|
56
|
+
it 'should be invoked when Pkg::Config.templates is set' do
|
57
|
+
expect_any_instance_of(Pkg::Tar).to receive(:expand_templates)
|
57
58
|
Pkg::Tar.new
|
58
59
|
end
|
59
60
|
|
60
|
-
it
|
61
|
+
it 'packaging templates should be filtered and paths should be expanded' do
|
61
62
|
templates.each do |temp|
|
62
63
|
if temp.is_a?(String)
|
63
|
-
Dir
|
64
|
+
allow(Dir)
|
65
|
+
.to receive(:glob)
|
66
|
+
.with(File.join(PROJECT_ROOT, temp))
|
67
|
+
.and_return(File.join(PROJECT_ROOT, temp))
|
64
68
|
end
|
65
69
|
end
|
66
70
|
|
67
71
|
tar = Pkg::Tar.new
|
68
72
|
tar.templates = templates
|
69
73
|
tar.expand_templates
|
70
|
-
tar.templates.
|
74
|
+
expect(tar.templates).to eq(expanded_templates)
|
71
75
|
end
|
72
76
|
end
|
73
77
|
|
74
|
-
describe
|
78
|
+
describe '#template' do
|
75
79
|
before(:each) do
|
76
80
|
Pkg::Config.templates = expanded_templates
|
77
81
|
end
|
78
82
|
|
79
|
-
it
|
80
|
-
# Set up correct stubs and expectations
|
83
|
+
it 'should handle hashes and strings correctly' do
|
81
84
|
expanded_templates.each do |temp|
|
82
|
-
|
85
|
+
case temp
|
86
|
+
when String
|
83
87
|
full_path_temp = File.join(PROJECT_ROOT, temp)
|
84
|
-
target = full_path_temp.sub(File.extname(full_path_temp),
|
85
|
-
|
86
|
-
full_path_temp = File.join(PROJECT_ROOT, temp[
|
87
|
-
target = File.join(PROJECT_ROOT, temp[
|
88
|
+
target = full_path_temp.sub(File.extname(full_path_temp), '')
|
89
|
+
when Hash
|
90
|
+
full_path_temp = File.join(PROJECT_ROOT, temp['source'])
|
91
|
+
target = File.join(PROJECT_ROOT, temp['target'])
|
88
92
|
end
|
89
93
|
|
90
|
-
Dir.
|
91
|
-
File.
|
92
|
-
Pkg::Util::File
|
94
|
+
allow(Dir).to receive(:glob).with(full_path_temp).and_return(full_path_temp)
|
95
|
+
allow(File).to receive(:exist?).with(full_path_temp).and_return(true)
|
96
|
+
expect(Pkg::Util::File)
|
97
|
+
.to receive(:erb_file)
|
98
|
+
.with(full_path_temp, target, true, binding: an_instance_of(Binding))
|
93
99
|
end
|
94
100
|
|
95
101
|
Pkg::Tar.new.template
|
96
102
|
end
|
97
103
|
|
98
|
-
it
|
99
|
-
# Set up correct stubs and expectations
|
104
|
+
it 'should raise an error if the template source can\'t be found' do
|
100
105
|
expanded_templates.each do |temp|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
end
|
106
|
+
full_path_temp = case temp
|
107
|
+
when String
|
108
|
+
File.join(PROJECT_ROOT, temp)
|
109
|
+
when Hash
|
110
|
+
File.join(PROJECT_ROOT, temp['source'])
|
111
|
+
end
|
108
112
|
|
109
|
-
Dir.
|
110
|
-
File.
|
113
|
+
allow(Dir).to receive(:glob).with(full_path_temp).and_return(full_path_temp)
|
114
|
+
allow(File).to receive(:exist?).with(full_path_temp).and_return(false)
|
111
115
|
end
|
112
116
|
|
113
117
|
expect { Pkg::Tar.new.template }.to raise_error RuntimeError
|
@@ -1,56 +1,56 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
4
|
-
let(:command)
|
5
|
-
let(:output)
|
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
6
|
|
7
7
|
describe "#success?" do
|
8
|
-
it
|
9
|
-
%x
|
10
|
-
Pkg::Util::Execution.success
|
8
|
+
it 'should return false on failure' do
|
9
|
+
%x(false)
|
10
|
+
expect(Pkg::Util::Execution.success?).to be false
|
11
11
|
end
|
12
12
|
|
13
|
-
it
|
14
|
-
%x
|
15
|
-
Pkg::Util::Execution.success
|
13
|
+
it 'should return true on success' do
|
14
|
+
%x(true)
|
15
|
+
expect(Pkg::Util::Execution.success?).to be true
|
16
16
|
end
|
17
17
|
|
18
|
-
it
|
19
|
-
%x
|
20
|
-
Pkg::Util::Execution.success?($?).
|
18
|
+
it 'should return false when passed an exitstatus object from a failure' do
|
19
|
+
%x(false)
|
20
|
+
expect(Pkg::Util::Execution.success?($?)).to be false
|
21
21
|
end
|
22
22
|
|
23
|
-
it
|
24
|
-
%x
|
25
|
-
Pkg::Util::Execution.success?($?).
|
23
|
+
it 'should return true when passed and exitstatus object from a success' do
|
24
|
+
%x(true)
|
25
|
+
expect(Pkg::Util::Execution.success?($?)).to be true
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
describe
|
30
|
-
it
|
31
|
-
Pkg::Util::Execution.
|
32
|
-
Pkg::Util::Execution.
|
33
|
-
expect{ Pkg::Util::Execution.ex(command) }.to raise_error(RuntimeError)
|
29
|
+
describe '#ex' do
|
30
|
+
it 'should raise an error if the command fails' do
|
31
|
+
expect(Pkg::Util::Execution).to receive(:`).with(command).and_return(true)
|
32
|
+
expect(Pkg::Util::Execution).to receive(:success?).and_return(false)
|
33
|
+
expect { Pkg::Util::Execution.ex(command) }.to raise_error(RuntimeError)
|
34
34
|
end
|
35
35
|
|
36
|
-
it
|
37
|
-
Pkg::Util::Execution.
|
38
|
-
Pkg::Util::Execution.
|
39
|
-
Pkg::Util::Execution.ex(command).
|
36
|
+
it 'should return the output of the command for success' do
|
37
|
+
expect(Pkg::Util::Execution).to receive(:`).with(command).and_return(output)
|
38
|
+
expect(Pkg::Util::Execution).to receive(:success?).and_return(true)
|
39
|
+
expect(Pkg::Util::Execution.ex(command)).to eq output
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
describe
|
44
|
-
it
|
45
|
-
Open3.
|
46
|
-
Pkg::Util::Execution.
|
47
|
-
expect{ Pkg::Util::Execution.capture3(command) }.to raise_error(RuntimeError, /#{output}/)
|
43
|
+
describe '#capture3' do
|
44
|
+
it 'should raise an error if the command fails' do
|
45
|
+
expect(Open3).to receive(:capture3).with(command).and_return([output, '', 1])
|
46
|
+
expect(Pkg::Util::Execution).to receive(:success?).with(1).and_return(false)
|
47
|
+
expect { Pkg::Util::Execution.capture3(command) }.to raise_error(RuntimeError, /#{output}/)
|
48
48
|
end
|
49
49
|
|
50
50
|
it "should return the output of the command for success" do
|
51
|
-
Open3.
|
52
|
-
Pkg::Util::Execution.
|
53
|
-
Pkg::Util::Execution.capture3(command).
|
51
|
+
expect(Open3).to receive(:capture3).with(command).and_return([output, '', 0])
|
52
|
+
expect(Pkg::Util::Execution).to receive(:success?).with(0).and_return(true)
|
53
|
+
expect(Pkg::Util::Execution.capture3(command)).to eq([output, '', 0])
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
@@ -1,112 +1,146 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
4
|
-
let(:source) {
|
5
|
-
let(:target) {
|
6
|
-
let(:options) {
|
7
|
-
let(:tar) {
|
8
|
-
let(:files) { [
|
9
|
-
let(:symlinks) { [
|
10
|
-
let(:dirs) { [
|
11
|
-
let(:empty_dirs) { [
|
12
|
-
|
13
|
-
|
14
|
-
describe
|
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
15
|
before :each do
|
16
|
-
Pkg::Util::Tool
|
16
|
+
allow(Pkg::Util::Tool)
|
17
|
+
.to receive(:find_tool)
|
18
|
+
.with('tar', required: true)
|
19
|
+
.and_return(tar)
|
17
20
|
end
|
18
21
|
|
19
|
-
it
|
20
|
-
Pkg::Util::File
|
21
|
-
|
22
|
+
it 'raises an exception if the source doesn\'t exist' do
|
23
|
+
expect(Pkg::Util::File)
|
24
|
+
.to receive(:file_exists?)
|
25
|
+
.with(source, { required: true })
|
26
|
+
.and_raise(RuntimeError)
|
27
|
+
expect(Pkg::Util::Execution).not_to receive(:capture3)
|
22
28
|
expect { Pkg::Util::File.untar_into(source) }.to raise_error(RuntimeError)
|
23
29
|
end
|
24
30
|
|
25
|
-
it
|
26
|
-
Pkg::Util::File
|
27
|
-
|
31
|
+
it 'unpacks the tarball to the current directory if no target is passed' do
|
32
|
+
expect(Pkg::Util::File)
|
33
|
+
.to receive(:file_exists?)
|
34
|
+
.with(source, { required: true }) { true }
|
35
|
+
expect(Pkg::Util::Execution)
|
36
|
+
.to receive(:capture3)
|
37
|
+
.with("#{tar} -xf #{source}")
|
28
38
|
Pkg::Util::File.untar_into(source)
|
29
39
|
end
|
30
40
|
|
31
|
-
it
|
32
|
-
Pkg::Util::File
|
33
|
-
|
41
|
+
it 'unpacks the tarball to the current directory with options if no target is passed' do
|
42
|
+
expect(Pkg::Util::File)
|
43
|
+
.to receive(:file_exists?)
|
44
|
+
.with(source, { required: true }) { true }
|
45
|
+
expect(Pkg::Util::Execution)
|
46
|
+
.to receive(:capture3)
|
47
|
+
.with("#{tar} #{options} -xf #{source}")
|
34
48
|
Pkg::Util::File.untar_into(source, nil, options)
|
35
49
|
end
|
36
50
|
|
37
|
-
it
|
38
|
-
File.
|
39
|
-
Pkg::Util::File.
|
40
|
-
Pkg::Util::File.
|
41
|
-
Pkg::Util::Execution.
|
51
|
+
it 'unpacks the tarball into the target' do
|
52
|
+
allow(File).to receive(:capture3ist?).with(source).and_return(true)
|
53
|
+
expect(Pkg::Util::File).to receive(:file_exists?).with(source, { required: true }) { true }
|
54
|
+
expect(Pkg::Util::File).to receive(:file_writable?).with(target) { true }
|
55
|
+
expect(Pkg::Util::Execution).to receive(:capture3).with("#{tar} -C #{target} -xf #{source}")
|
42
56
|
Pkg::Util::File.untar_into(source, target)
|
43
57
|
end
|
44
58
|
|
45
59
|
it "unpacks the tarball into the target with options passed" do
|
46
|
-
File.
|
47
|
-
Pkg::Util::File.
|
48
|
-
Pkg::Util::File.
|
49
|
-
Pkg::Util::Execution
|
60
|
+
allow(File).to receive(:capture3ist?).with(source).and_return(true)
|
61
|
+
expect(Pkg::Util::File).to receive(:file_exists?).with(source, { required: true }) { true }
|
62
|
+
expect(Pkg::Util::File).to receive(:file_writable?).with(target) { true }
|
63
|
+
expect(Pkg::Util::Execution)
|
64
|
+
.to receive(:capture3)
|
65
|
+
.with("#{tar} #{options} -C #{target} -xf #{source}")
|
50
66
|
Pkg::Util::File.untar_into(source, target, options)
|
51
67
|
end
|
52
68
|
end
|
53
69
|
|
54
|
-
describe
|
55
|
-
it
|
56
|
-
Pkg::Util::File.files_with_ext(
|
70
|
+
describe '#files_with_ext' do
|
71
|
+
it 'returns nothing if there are no files with that extension' do
|
72
|
+
expect(Pkg::Util::File.files_with_ext('./spec/fixtures/configs/components', '.fake'))
|
73
|
+
.to be_empty
|
57
74
|
end
|
58
75
|
|
59
|
-
it
|
60
|
-
expect(Pkg::Util::File.files_with_ext(
|
61
|
-
|
76
|
+
it 'returns only the files with that extension' do
|
77
|
+
expect(Pkg::Util::File.files_with_ext('./spec/fixtures/configs/components', '.json'))
|
78
|
+
.to include('./spec/fixtures/configs/components/test_file.json')
|
79
|
+
expect(Pkg::Util::File.files_with_ext('./spec/fixtures/configs/components', '.json'))
|
80
|
+
.to include('./spec/fixtures/configs/components/test_file_2.json')
|
62
81
|
end
|
63
82
|
end
|
64
83
|
|
65
|
-
describe
|
66
|
-
it
|
84
|
+
describe '#install_files_into_dir' do
|
85
|
+
it 'selects the correct files to install' do
|
67
86
|
Pkg::Config.load_defaults
|
68
87
|
workdir = Pkg::Util::File.mktemp
|
69
88
|
patterns = []
|
70
89
|
|
71
|
-
|
72
|
-
File.
|
73
|
-
File.
|
74
|
-
File.
|
75
|
-
Pkg::Util::File.stub(:empty_dir?) { false }
|
90
|
+
allow(File).to receive(:file?).and_return(false)
|
91
|
+
allow(File).to receive(:symlink?).and_return(false)
|
92
|
+
allow(File).to receive(:directory?).and_return(false)
|
93
|
+
allow(Pkg::Util::File).to receive(:empty_dir?).and_return(false)
|
76
94
|
|
77
95
|
# Files should have the path made and should be copied
|
78
96
|
files.each do |file|
|
79
|
-
File.
|
80
|
-
Dir.
|
81
|
-
FileUtils
|
82
|
-
|
97
|
+
allow(File).to receive(:file?).with(file).and_return(true)
|
98
|
+
allow(Dir).to receive(:[]).with(file).and_return(file)
|
99
|
+
expect(FileUtils)
|
100
|
+
.to receive(:mkpath)
|
101
|
+
.with(File.dirname(File.join(workdir, file)), verbose: false)
|
102
|
+
expect(FileUtils)
|
103
|
+
.to receive(:cp)
|
104
|
+
.with(file, File.join(workdir, file), verbose: false, preserve: true)
|
83
105
|
patterns << file
|
84
106
|
end
|
85
107
|
|
86
108
|
# Symlinks should have the path made and should be copied
|
87
109
|
symlinks.each do |file|
|
88
|
-
File.
|
89
|
-
Dir.
|
90
|
-
FileUtils
|
91
|
-
|
110
|
+
allow(File).to receive(:symlink?).with(file).and_return(true)
|
111
|
+
allow(Dir).to receive(:[]).with(file).and_return(file)
|
112
|
+
expect(FileUtils)
|
113
|
+
.to receive(:mkpath)
|
114
|
+
.with(File.dirname(File.join(workdir, file)), verbose: false)
|
115
|
+
expect(FileUtils)
|
116
|
+
.to receive(:cp)
|
117
|
+
.with(file, File.join(workdir, file), verbose: false, preserve: true)
|
92
118
|
patterns << file
|
93
119
|
end
|
94
120
|
|
95
|
-
# Dirs should be added to patterns but
|
121
|
+
# Dirs should be added to patterns but not acted upon
|
96
122
|
dirs.each do |dir|
|
97
|
-
File.
|
98
|
-
Dir.
|
99
|
-
FileUtils
|
100
|
-
|
123
|
+
allow(File).to receive(:directory?).with(dir).and_return(true)
|
124
|
+
allow(Dir).to receive(:[]).with("#{dir}/**/*").and_return(dir)
|
125
|
+
expect(FileUtils)
|
126
|
+
.not_to receive(:mkpath)
|
127
|
+
.with(File.dirname(File.join(workdir, dir)), verbose: false)
|
128
|
+
expect(FileUtils)
|
129
|
+
.not_to receive(:cp)
|
130
|
+
.with(dir, File.join(workdir, dir), verbose: false, preserve: true)
|
101
131
|
patterns << dir
|
102
132
|
end
|
103
133
|
|
104
134
|
# Empty dirs should have the path created and nothing copied
|
105
135
|
empty_dirs.each do |dir|
|
106
|
-
Pkg::Util::File.
|
107
|
-
Dir.
|
108
|
-
FileUtils
|
109
|
-
|
136
|
+
allow(Pkg::Util::File).to receive(:empty_dir?).with(dir).and_return(true)
|
137
|
+
allow(Dir).to receive(:[]).with(dir).and_return(dir)
|
138
|
+
expect(FileUtils)
|
139
|
+
.to receive(:mkpath)
|
140
|
+
.with(File.join(workdir, dir), verbose: false)
|
141
|
+
expect(FileUtils)
|
142
|
+
.not_to receive(:cp)
|
143
|
+
.with(dir, File.join(workdir, dir), verbose: false, preserve: true)
|
110
144
|
patterns << dir
|
111
145
|
end
|
112
146
|
|
@@ -115,25 +149,28 @@ describe "Pkg::Util::File" do
|
|
115
149
|
end
|
116
150
|
end
|
117
151
|
|
118
|
-
describe
|
119
|
-
it
|
120
|
-
File.
|
121
|
-
Pkg::Util::File.directories(
|
152
|
+
describe '#directories' do
|
153
|
+
it 'returns nil if there is no directory' do
|
154
|
+
expect(File).to receive(:directory?).with('/tmp').and_return(false)
|
155
|
+
expect(Pkg::Util::File.directories('/tmp')).to be_nil
|
122
156
|
end
|
123
157
|
|
124
|
-
it
|
125
|
-
File.
|
126
|
-
Dir.
|
127
|
-
Pkg::Util::File.directories("/tmp").
|
158
|
+
it 'returns the empty array if there are no dirs in the directory' do
|
159
|
+
expect(File).to receive(:directory?).with('/tmp').and_return(true)
|
160
|
+
expect(Dir).to receive(:glob).with('*').and_return([])
|
161
|
+
expect(Pkg::Util::File.directories("/tmp")).to be_empty
|
128
162
|
end
|
129
163
|
|
130
|
-
it
|
131
|
-
File.
|
132
|
-
[
|
133
|
-
File.
|
164
|
+
it 'returns an array of the top level directories inside a directory' do
|
165
|
+
allow(File).to receive(:directory?).and_return(false)
|
166
|
+
['/tmp', '/tmp/dir', '/tmp/other_dir'].each do |dir|
|
167
|
+
expect(File).to receive(:directory?).with(dir).and_return(true)
|
134
168
|
end
|
135
|
-
Dir
|
136
|
-
|
169
|
+
expect(Dir)
|
170
|
+
.to receive(:glob)
|
171
|
+
.with('*')
|
172
|
+
.and_return(['/tmp/file', '/tmp/dir', '/tmp/other_dir'])
|
173
|
+
expect(Pkg::Util::File.directories('/tmp')).to eq(['/tmp/dir', '/tmp/other_dir'])
|
137
174
|
end
|
138
175
|
end
|
139
176
|
end
|