packaging 0.99.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 +7 -0
- data/LICENSE +17 -0
- data/README-Solaris.md +117 -0
- data/README.md +1031 -0
- data/lib/packaging.rb +32 -0
- data/lib/packaging/artifactory.rb +278 -0
- data/lib/packaging/config.rb +392 -0
- data/lib/packaging/config/params.rb +366 -0
- data/lib/packaging/deb.rb +28 -0
- data/lib/packaging/deb/repo.rb +263 -0
- data/lib/packaging/gem.rb +112 -0
- data/lib/packaging/ips.rb +57 -0
- data/lib/packaging/msi.rb +89 -0
- data/lib/packaging/nuget.rb +39 -0
- data/lib/packaging/osx.rb +36 -0
- data/lib/packaging/paths.rb +238 -0
- data/lib/packaging/platforms.rb +480 -0
- data/lib/packaging/repo.rb +55 -0
- data/lib/packaging/retrieve.rb +46 -0
- data/lib/packaging/rpm.rb +5 -0
- data/lib/packaging/rpm/repo.rb +257 -0
- data/lib/packaging/tar.rb +154 -0
- data/lib/packaging/util.rb +146 -0
- data/lib/packaging/util/date.rb +15 -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 +62 -0
- data/lib/packaging/util/jenkins.rb +95 -0
- data/lib/packaging/util/misc.rb +69 -0
- data/lib/packaging/util/net.rb +368 -0
- data/lib/packaging/util/os.rb +17 -0
- data/lib/packaging/util/platform.rb +40 -0
- data/lib/packaging/util/rake_utils.rb +111 -0
- data/lib/packaging/util/serialization.rb +19 -0
- data/lib/packaging/util/ship.rb +171 -0
- data/lib/packaging/util/tool.rb +41 -0
- data/lib/packaging/util/version.rb +326 -0
- data/spec/fixtures/config/ext/build_defaults.yaml +2 -0
- data/spec/fixtures/config/ext/project_data.yaml +2 -0
- data/spec/fixtures/config/params.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 +171 -0
- data/spec/lib/packaging/config_spec.rb +556 -0
- data/spec/lib/packaging/deb/repo_spec.rb +148 -0
- data/spec/lib/packaging/deb_spec.rb +52 -0
- data/spec/lib/packaging/paths_spec.rb +153 -0
- data/spec/lib/packaging/platforms_spec.rb +153 -0
- data/spec/lib/packaging/repo_spec.rb +97 -0
- data/spec/lib/packaging/retrieve_spec.rb +61 -0
- data/spec/lib/packaging/rpm/repo_spec.rb +133 -0
- data/spec/lib/packaging/tar_spec.rb +122 -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 +239 -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 +117 -0
- data/spec/lib/packaging/util/version_spec.rb +123 -0
- data/spec/lib/packaging_spec.rb +19 -0
- data/spec/spec_helper.rb +36 -0
- data/static_artifacts/PackageInfo.plist +3 -0
- data/tasks/00_utils.rake +216 -0
- data/tasks/30_metrics.rake +33 -0
- data/tasks/apple.rake +266 -0
- data/tasks/build.rake +12 -0
- data/tasks/clean.rake +5 -0
- data/tasks/config.rake +30 -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 +57 -0
- data/tasks/gem.rake +146 -0
- data/tasks/jenkins.rake +494 -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 +335 -0
- data/tasks/pe_deb.rake +12 -0
- data/tasks/pe_rpm.rake +13 -0
- data/tasks/pe_ship.rake +221 -0
- data/tasks/pe_sign.rake +13 -0
- data/tasks/pe_tar.rake +5 -0
- data/tasks/retrieve.rake +45 -0
- data/tasks/rpm.rake +66 -0
- data/tasks/rpm_repos.rake +29 -0
- data/tasks/ship.rake +752 -0
- data/tasks/sign.rake +226 -0
- data/tasks/tag.rake +8 -0
- data/tasks/tar.rake +34 -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 +344 -0
- data/templates/repo.xml.erb +114 -0
- metadata +234 -0
@@ -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
|
@@ -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", "master")
|
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
|