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.
Files changed (114) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +17 -0
  3. data/README-Solaris.md +117 -0
  4. data/README.md +1031 -0
  5. data/lib/packaging.rb +32 -0
  6. data/lib/packaging/artifactory.rb +278 -0
  7. data/lib/packaging/config.rb +392 -0
  8. data/lib/packaging/config/params.rb +366 -0
  9. data/lib/packaging/deb.rb +28 -0
  10. data/lib/packaging/deb/repo.rb +263 -0
  11. data/lib/packaging/gem.rb +112 -0
  12. data/lib/packaging/ips.rb +57 -0
  13. data/lib/packaging/msi.rb +89 -0
  14. data/lib/packaging/nuget.rb +39 -0
  15. data/lib/packaging/osx.rb +36 -0
  16. data/lib/packaging/paths.rb +238 -0
  17. data/lib/packaging/platforms.rb +480 -0
  18. data/lib/packaging/repo.rb +55 -0
  19. data/lib/packaging/retrieve.rb +46 -0
  20. data/lib/packaging/rpm.rb +5 -0
  21. data/lib/packaging/rpm/repo.rb +257 -0
  22. data/lib/packaging/tar.rb +154 -0
  23. data/lib/packaging/util.rb +146 -0
  24. data/lib/packaging/util/date.rb +15 -0
  25. data/lib/packaging/util/execution.rb +85 -0
  26. data/lib/packaging/util/file.rb +125 -0
  27. data/lib/packaging/util/git.rb +174 -0
  28. data/lib/packaging/util/git_tags.rb +73 -0
  29. data/lib/packaging/util/gpg.rb +62 -0
  30. data/lib/packaging/util/jenkins.rb +95 -0
  31. data/lib/packaging/util/misc.rb +69 -0
  32. data/lib/packaging/util/net.rb +368 -0
  33. data/lib/packaging/util/os.rb +17 -0
  34. data/lib/packaging/util/platform.rb +40 -0
  35. data/lib/packaging/util/rake_utils.rb +111 -0
  36. data/lib/packaging/util/serialization.rb +19 -0
  37. data/lib/packaging/util/ship.rb +171 -0
  38. data/lib/packaging/util/tool.rb +41 -0
  39. data/lib/packaging/util/version.rb +326 -0
  40. data/spec/fixtures/config/ext/build_defaults.yaml +2 -0
  41. data/spec/fixtures/config/ext/project_data.yaml +2 -0
  42. data/spec/fixtures/config/params.yaml +2 -0
  43. data/spec/fixtures/configs/components/test_file.json +1 -0
  44. data/spec/fixtures/configs/components/test_file_2.json +0 -0
  45. data/spec/fixtures/configs/components/test_file_not_tagged.json +1 -0
  46. data/spec/fixtures/configs/components/test_file_wrong_ext.txt +0 -0
  47. data/spec/fixtures/configs/components/test_file_wrong_ext.wrong +0 -0
  48. data/spec/fixtures/util/pre_tasks.yaml +4 -0
  49. data/spec/lib/packaging/artifactory_spec.rb +171 -0
  50. data/spec/lib/packaging/config_spec.rb +556 -0
  51. data/spec/lib/packaging/deb/repo_spec.rb +148 -0
  52. data/spec/lib/packaging/deb_spec.rb +52 -0
  53. data/spec/lib/packaging/paths_spec.rb +153 -0
  54. data/spec/lib/packaging/platforms_spec.rb +153 -0
  55. data/spec/lib/packaging/repo_spec.rb +97 -0
  56. data/spec/lib/packaging/retrieve_spec.rb +61 -0
  57. data/spec/lib/packaging/rpm/repo_spec.rb +133 -0
  58. data/spec/lib/packaging/tar_spec.rb +122 -0
  59. data/spec/lib/packaging/util/execution_spec.rb +56 -0
  60. data/spec/lib/packaging/util/file_spec.rb +139 -0
  61. data/spec/lib/packaging/util/git_spec.rb +160 -0
  62. data/spec/lib/packaging/util/git_tag_spec.rb +36 -0
  63. data/spec/lib/packaging/util/gpg_spec.rb +64 -0
  64. data/spec/lib/packaging/util/jenkins_spec.rb +112 -0
  65. data/spec/lib/packaging/util/misc_spec.rb +31 -0
  66. data/spec/lib/packaging/util/net_spec.rb +239 -0
  67. data/spec/lib/packaging/util/os_spec.rb +31 -0
  68. data/spec/lib/packaging/util/rake_utils_spec.rb +70 -0
  69. data/spec/lib/packaging/util/ship_spec.rb +117 -0
  70. data/spec/lib/packaging/util/version_spec.rb +123 -0
  71. data/spec/lib/packaging_spec.rb +19 -0
  72. data/spec/spec_helper.rb +36 -0
  73. data/static_artifacts/PackageInfo.plist +3 -0
  74. data/tasks/00_utils.rake +216 -0
  75. data/tasks/30_metrics.rake +33 -0
  76. data/tasks/apple.rake +266 -0
  77. data/tasks/build.rake +12 -0
  78. data/tasks/clean.rake +5 -0
  79. data/tasks/config.rake +30 -0
  80. data/tasks/deb.rake +129 -0
  81. data/tasks/deb_repos.rake +28 -0
  82. data/tasks/deprecated.rake +130 -0
  83. data/tasks/doc.rake +20 -0
  84. data/tasks/education.rake +57 -0
  85. data/tasks/fetch.rake +57 -0
  86. data/tasks/gem.rake +146 -0
  87. data/tasks/jenkins.rake +494 -0
  88. data/tasks/jenkins_dynamic.rake +202 -0
  89. data/tasks/load_extras.rake +21 -0
  90. data/tasks/mock.rake +348 -0
  91. data/tasks/nightly_repos.rake +335 -0
  92. data/tasks/pe_deb.rake +12 -0
  93. data/tasks/pe_rpm.rake +13 -0
  94. data/tasks/pe_ship.rake +221 -0
  95. data/tasks/pe_sign.rake +13 -0
  96. data/tasks/pe_tar.rake +5 -0
  97. data/tasks/retrieve.rake +45 -0
  98. data/tasks/rpm.rake +66 -0
  99. data/tasks/rpm_repos.rake +29 -0
  100. data/tasks/ship.rake +752 -0
  101. data/tasks/sign.rake +226 -0
  102. data/tasks/tag.rake +8 -0
  103. data/tasks/tar.rake +34 -0
  104. data/tasks/update.rake +16 -0
  105. data/tasks/vanagon.rake +35 -0
  106. data/tasks/vendor_gems.rake +117 -0
  107. data/tasks/version.rake +33 -0
  108. data/tasks/z_data_dump.rake +65 -0
  109. data/templates/README +1 -0
  110. data/templates/downstream.xml.erb +47 -0
  111. data/templates/msi.xml.erb +197 -0
  112. data/templates/packaging.xml.erb +344 -0
  113. data/templates/repo.xml.erb +114 -0
  114. metadata +234 -0
@@ -0,0 +1,148 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Pkg::Deb::Repo" do
4
+ let(:wget) { "/opt/tools/bin/wget" }
5
+ let(:builds_server) { "saturn.puppetlabs.net" }
6
+ let(:project) { "deb_repos" }
7
+ let(:ref) { "1234abcd" }
8
+ let(:base_url) { "http://#{builds_server}/#{project}/#{ref}" }
9
+ let(:cows) { ["xenial", "jessie", "trusty", "stretch", ""] }
10
+ let(:wget_results) { cows.map {|cow| "#{base_url}/repos/apt/#{cow}" }.join("\n") }
11
+ let(:wget_garbage) { "\n and an index\nhttp://somethingelse.com/robots" }
12
+ let(:repo_configs) { cows.reject {|cow| cow.empty?}.map {|dist| "pkg/repo_configs/deb/pl-#{project}-#{ref}-#{dist}.list" } }
13
+
14
+ # Setup and tear down for the tests
15
+ around do |example|
16
+ orig_server = Pkg::Config.builds_server
17
+ orig_host = Pkg::Config.distribution_server
18
+ orig_project = Pkg::Config.project
19
+ orig_ref = Pkg::Config.ref
20
+ orig_repo_path = Pkg::Config.jenkins_repo_path
21
+ Pkg::Config.builds_server = builds_server
22
+ Pkg::Config.project = project
23
+ Pkg::Config.ref = ref
24
+ example.run
25
+ Pkg::Config.builds_server = orig_server
26
+ Pkg::Config.distribution_server = orig_host
27
+ Pkg::Config.project = orig_project
28
+ Pkg::Config.ref = orig_ref
29
+ Pkg::Config.jenkins_repo_path = orig_repo_path
30
+ end
31
+
32
+ describe "#generate_repo_configs" do
33
+ it "fails if wget isn't available" do
34
+ Pkg::Util::Tool.should_receive(:find_tool).with("wget", {:required => true}).and_raise(RuntimeError)
35
+ expect {Pkg::Deb::Repo.generate_repo_configs}.to raise_error(RuntimeError)
36
+ end
37
+
38
+ it "warns if there are no deb repos available for the build" do
39
+ Pkg::Util::Tool.should_receive(:find_tool).with("wget", {:required => true}).and_return(wget)
40
+ Pkg::Util::Execution.should_receive(:capture3).with("#{wget} --spider -r -l 1 --no-parent #{base_url}/repos/apt/ 2>&1").and_raise(RuntimeError)
41
+ Pkg::Deb::Repo.should_receive(:warn).with("No debian repos available for #{project} at #{ref}.")
42
+ Pkg::Deb::Repo.generate_repo_configs
43
+ end
44
+
45
+ it "writes the expected repo configs to disk" do
46
+ Pkg::Util::Tool.should_receive(:find_tool).with("wget", {:required => true}).and_return(wget)
47
+ Pkg::Util::Execution.should_receive(:capture3).with("#{wget} --spider -r -l 1 --no-parent #{base_url}/repos/apt/ 2>&1").and_return(wget_results + wget_garbage)
48
+ FileUtils.should_receive(:mkdir_p).with("pkg/repo_configs/deb")
49
+ config = []
50
+ repo_configs.each_with_index do |repo_config, i|
51
+ config[i] = double(File)
52
+ File.should_receive(:open).with(repo_config, 'w').and_yield(config[i])
53
+ config[i].should_receive(:puts)
54
+ end
55
+ Pkg::Deb::Repo.generate_repo_configs
56
+ end
57
+ end
58
+
59
+ describe "#retrieve_repo_configs" do
60
+ it "fails if wget isn't available" do
61
+ Pkg::Util::Tool.should_receive(:find_tool).with("wget", {:required => true}).and_raise(RuntimeError)
62
+ expect {Pkg::Deb::Repo.generate_repo_configs}.to raise_error(RuntimeError)
63
+ end
64
+
65
+ it "warns if there are no deb repos available for the build" do
66
+ Pkg::Util::Tool.should_receive(:find_tool).with("wget", {:required => true}).and_return(wget)
67
+ FileUtils.should_receive(:mkdir_p).with("pkg/repo_configs").and_return(true)
68
+ Pkg::Util::Execution.should_receive(:capture3).with("#{wget} -r -np -nH --cut-dirs 3 -P pkg/repo_configs --reject 'index*' #{base_url}/repo_configs/deb/").and_raise(RuntimeError)
69
+ expect {Pkg::Deb::Repo.retrieve_repo_configs}.to raise_error(RuntimeError, /Couldn't retrieve deb apt repo configs/)
70
+ end
71
+ end
72
+
73
+ describe "#repo_creation_command" do
74
+ let(:prefix) { "thing" }
75
+ let(:artifact_directory) { ["/a/b/c/xenial"] }
76
+
77
+ it "returns a command to make repos" do
78
+ command = Pkg::Deb::Repo.repo_creation_command(prefix, artifact_directory)
79
+ command.should match(/reprepro/)
80
+ command.should match(/#{prefix}/)
81
+ command.should match(/#{artifact_directory}/)
82
+ end
83
+ end
84
+
85
+ describe "#create_repos" do
86
+ let(:command) { "/usr/bin/make some repos" }
87
+ let(:artifact_directory) { "/tmp/dir/thing" }
88
+ let(:pkg_directories) { ['place/to/deb/xenial', 'other/deb/trusty'] }
89
+
90
+ it "generates repo configs remotely and then ships them" do
91
+ File.stub(:join) {artifact_directory}
92
+ Pkg::Repo.should_receive(:directories_that_contain_packages).and_return(pkg_directories)
93
+ Pkg::Repo.should_receive(:populate_repo_directory)
94
+ Pkg::Deb::Repo.should_receive(:repo_creation_command).and_return(command)
95
+ Pkg::Util::Net.should_receive(:remote_ssh_cmd).with(Pkg::Config.distribution_server, command)
96
+ Pkg::Deb::Repo.should_receive(:generate_repo_configs)
97
+ Pkg::Deb::Repo.should_receive(:ship_repo_configs)
98
+ Pkg::Util::Net.should_receive(:remote_ssh_cmd).with(Pkg::Config.distribution_server, "rm -f #{artifact_directory}/repos/.lock" )
99
+ Pkg::Deb::Repo.create_repos
100
+ end
101
+ end
102
+
103
+ describe "#ship_repo_configs" do
104
+ it "warns if there are no repo configs to ship" do
105
+ File.should_receive(:exist?).with("pkg/repo_configs/deb").and_return(true)
106
+ Pkg::Util::File.should_receive(:empty_dir?).with("pkg/repo_configs/deb").and_return(true)
107
+ Pkg::Deb::Repo.should_receive(:warn).with("No repo configs have been generated! Try pl:deb_repo_configs.")
108
+ Pkg::Deb::Repo.ship_repo_configs
109
+ end
110
+
111
+ it "ships repo configs to the build server" do
112
+ File.should_receive(:exist?).with("pkg/repo_configs/deb").and_return(true)
113
+ Pkg::Config.jenkins_repo_path = "/a/b/c/d"
114
+ Pkg::Config.distribution_server = "a.host.that.wont.exist"
115
+ repo_dir = "#{Pkg::Config.jenkins_repo_path}/#{Pkg::Config.project}/#{Pkg::Config.ref}/repo_configs/deb"
116
+ Pkg::Util::File.should_receive(:empty_dir?).with("pkg/repo_configs/deb").and_return(false)
117
+ Pkg::Deb::Repo.should_receive(:invoke_task).with("pl:fetch")
118
+ Pkg::Util::Net.should_receive(:remote_ssh_cmd).with(Pkg::Config.distribution_server, "mkdir -p #{repo_dir}")
119
+ Pkg::Util::Execution.should_receive(:retry_on_fail).with(:times => 3)
120
+ Pkg::Deb::Repo.ship_repo_configs
121
+ end
122
+ end
123
+
124
+ describe "#sign_repos" do
125
+ it "fails without reprepro" do
126
+ Pkg::Util::Tool.should_receive(:find_tool).with('reprepro', {:required => true}).and_raise(RuntimeError)
127
+ expect { Pkg::Deb::Repo.sign_repos }.to raise_error(RuntimeError)
128
+ end
129
+
130
+ it "makes a repo for each dist" do
131
+ dists = cows.reject { |cow| cow.empty? }
132
+ distfiles = {}
133
+ reprepro = "/bin/reprepro"
134
+ Pkg::Util::File.should_receive(:directories).with("repos/apt").and_return(dists)
135
+ Pkg::Util::Tool.should_receive(:check_tool).with("reprepro").and_return(reprepro)
136
+ Pkg::Util::Execution.should_receive(:capture3).at_least(1).times.with("#{reprepro} -vvv --confdir ./conf --dbdir ./db --basedir ./ export")
137
+
138
+ dists.each do |dist|
139
+ distfiles[dist] = double
140
+ Dir.should_receive(:chdir).with("repos/apt/#{dist}").and_yield
141
+ File.should_receive(:open).with("conf/distributions", "w").and_yield(distfiles[dist])
142
+ distfiles[dist].should_receive(:puts)
143
+ end
144
+
145
+ Pkg::Deb::Repo.sign_repos
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,52 @@
1
+ # -*- ruby -*-
2
+ require 'spec_helper'
3
+ require 'packaging/deb'
4
+
5
+ describe 'deb.rb' do
6
+ describe "#set_cow_envs" do
7
+ before(:each) do
8
+ reset_env(["DIST", "ARCH", "PE_VER", "BUILDMIRROR"])
9
+ Pkg::Config.deb_build_mirrors = nil
10
+ Pkg::Config.build_pe = nil
11
+ Pkg::Config.pe_version = nil
12
+ end
13
+
14
+ after(:all) do
15
+ reset_env(["DIST", "ARCH", "PE_VER", "BUILDMIRROR"])
16
+ Pkg::Config.deb_build_mirrors = nil
17
+ Pkg::Config.build_pe = nil
18
+ Pkg::Config.pe_version = nil
19
+ end
20
+
21
+ it "should always set DIST and ARCH correctly" do
22
+ Pkg::Deb.send(:set_cow_envs, "base-wheezy-i386.cow")
23
+ ENV["DIST"].should eq("wheezy")
24
+ ENV["ARCH"].should eq("i386")
25
+ ENV["PE_VER"].should be_nil
26
+ ENV["BUILDMIRROR"].should be_nil
27
+ end
28
+
29
+ it "should set BUILDMIRROR if Pkg::Config.deb_build_mirrors is set" do
30
+ Pkg::Config.deb_build_mirrors = ["deb http://pl-build-tools.delivery.puppetlabs.net/debian __DIST__ main", "deb http://debian.is.awesome/wait no it is not"]
31
+ Pkg::Deb.send(:set_cow_envs, "base-wheezy-i386.cow")
32
+ ENV["DIST"].should eq("wheezy")
33
+ ENV["ARCH"].should eq("i386")
34
+ ENV["PE_VER"].should be_nil
35
+ ENV["BUILDMIRROR"].should eq("deb http://pl-build-tools.delivery.puppetlabs.net/debian wheezy main | deb http://debian.is.awesome/wait no it is not")
36
+ end
37
+
38
+ it "should set PE_VER if Pkg::Config.build_pe is truthy" do
39
+ Pkg::Config.build_pe = true
40
+ Pkg::Config.pe_version = "3.2"
41
+ Pkg::Deb.send(:set_cow_envs, "base-wheezy-i386.cow")
42
+ ENV["DIST"].should eq("wheezy")
43
+ ENV["ARCH"].should eq("i386")
44
+ ENV["PE_VER"].should eq("3.2")
45
+ ENV["BUILDMIRROR"].should be_nil
46
+ end
47
+
48
+ it "should fail on a badly formatted cow" do
49
+ expect { Pkg::Deb.send(:set_cow_envs, "wheezy-i386") }.to raise_error(RuntimeError)
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,153 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Pkg::Paths' do
4
+ describe '#arch_from_artifact_path' do
5
+ arch_transformations = {
6
+ ['artifacts/aix/6.1/PC1/ppc/puppet-agent-5.1.0.79.g782e03c-1.aix6.1.ppc.rpm', 'aix', '6.1'] => 'power',
7
+ ['pkg/el-7-x86_64/puppet-agent-4.99.0-1.el7.x86_64.rpm', 'el', '7'] => 'x86_64',
8
+ ['artifacts/ubuntu-16.04-i386/puppetserver_5.0.1-0.1SNAPSHOT.2017.07.27T2346puppetlabs1.debian.tar.gz', 'ubuntu', '16.04'] => 'source',
9
+ ['http://saturn.puppetlabs.net/deb_repos/1234abcd/repos/apt/xenial', 'ubuntu', '16.04'] => 'i386',
10
+ ['pkg/ubuntu-16.04-amd64/puppet-agent_4.99.0-1xenial_amd64.deb', 'ubuntu', '16.04'] => 'amd64',
11
+ ['artifacts/deb/jessie/PC1/puppetserver_5.0.1.master.orig.tar.gz', 'debian', '8'] => 'source',
12
+ ['artifacts/el/6/PC1/SRPMS/puppetserver-5.0.1.master-0.1SNAPSHOT.2017.08.18T0951.el6.src.rpm', 'el', '6'] => 'SRPMS'
13
+ }
14
+ arch_transformations.each do |path_array, arch|
15
+ it "should correctly return #{arch} for #{path_array[0]}" do
16
+ expect(Pkg::Paths.arch_from_artifact_path(path_array[1], path_array[2], path_array[0])).to eq(arch)
17
+ end
18
+ end
19
+ end
20
+
21
+ describe '#tag_from_artifact_path' do
22
+ path_tranformations = {
23
+ 'artifacts/aix/6.1/PC1/ppc/puppet-agent-5.1.0.79.g782e03c-1.aix6.1.ppc.rpm' => 'aix-6.1-power',
24
+ 'pkg/el-7-x86_64/puppet-agent-4.99.0-1.el7.x86_64.rpm' => 'el-7-x86_64',
25
+ 'pkg/ubuntu-16.04-amd64/puppet-agent_4.99.0-1xenial_amd64.deb' => 'ubuntu-16.04-amd64',
26
+ 'pkg/windows-x64/puppet-agent-4.99.0-x64.msi' => 'windows-2012-x64',
27
+ 'artifacts/el/6/products/x86_64/pe-r10k-2.5.4.3-1.el6.x86_64.rpm' => 'el-6-x86_64',
28
+ 'pkg/deb/trusty/pe-r10k_2.5.4.3-1trusty_amd64.deb' => 'ubuntu-14.04-amd64',
29
+ 'pkg/pe/rpm/el-6-i386/pe-puppetserver-2017.3.0.3-1.el6.noarch.rpm' => 'el-6-i386',
30
+ 'pkg/pe/deb/xenial/pe-puppetserver_2017.3.0.3-1puppet1_all.deb' => 'ubuntu-16.04-i386',
31
+ 'pkg/pe/deb/xenial/super-trusty-package_1.0.0-1puppet1_all.deb' => 'ubuntu-16.04-i386',
32
+ 'artifacts/deb/wheezy/PC1/puppetdb_4.3.1-1puppetlabs1_all.deb' => 'debian-7-i386',
33
+ 'pkg/el/7/PC1/x86_64/puppetdb-4.3.1-1.el7.noarch.rpm' => 'el-7-x86_64',
34
+ 'pkg/apple/10.11/PC1/x86_64/puppet-agent-1.9.0-1.osx10.11.dmg' => 'osx-10.11-x86_64',
35
+ 'artifacts/mac/10.11/PC1/x86_64/puppet-agent-1.9.0-1.osx10.11.dmg' => 'osx-10.11-x86_64',
36
+ 'artifacts/eos/4/PC1/i386/puppet-agent-1.9.0-1.eos4.i386.swix' => 'eos-4-i386',
37
+ 'pkg/deb/cumulus/puppet5/puppet-agent_1.4.1.2904.g8023dd1-1cumulus_amd64.deb' => 'cumulus-2.2-amd64',
38
+ 'pkg/windows/puppet-agent-1.9.0-x86.msi' => 'windows-2012-x86',
39
+ 'artifacts/ubuntu-16.04-i386/puppetserver_5.0.1-0.1SNAPSHOT.2017.07.27T2346puppetlabs1.debian.tar.gz' => 'ubuntu-16.04-source',
40
+ 'http://saturn.puppetlabs.net/deb_repos/1234abcd/repos/apt/xenial' => 'ubuntu-16.04-i386',
41
+ 'http://builds.puppetlabs.lan/puppet-agent/0ce4e6a0448366e01537323bbab77f834d7035c7/repos/el/6/PC1/x86_64/' => 'el-6-x86_64',
42
+ 'http://builds.puppetlabs.lan/puppet-agent/0ce4e6a0448366e01537323bbab77f834d7035c7/repos/el/6/PC1/x86_64/' => 'el-6-x86_64',
43
+ 'pkg/pe/rpm/el-6-i386/pe-puppetserver-2017.3.0.3-1.el6.src.rpm' => 'el-6-SRPMS',
44
+ 'pkg/pe/deb/xenial/pe-puppetserver_2017.3.0.3-1puppet1.orig.tar.gz' => 'ubuntu-16.04-source',
45
+ 'pkg/puppet-agent-5.1.0.79.g782e03c.gem' => nil,
46
+ 'pkg/puppet-agent-5.1.0.7.g782e03c.tar.gz' => nil,
47
+ }
48
+ path_tranformations.each do |pre, post|
49
+ it "should correctly return '#{post}' when given #{pre}" do
50
+ expect(Pkg::Paths.tag_from_artifact_path(pre)).to eq(post)
51
+ end
52
+ end
53
+
54
+ failure_cases = [
55
+ 'pkg/pe/deb/preice',
56
+ 'pkg/el-4-x86_64',
57
+ 'a/package/that/sucks.rpm',
58
+ ]
59
+ failure_cases.each do |fail_path|
60
+ it "should fail gracefully if given '#{fail_path}'" do
61
+ expect { Pkg::Paths.tag_from_artifact_path(fail_path) }.to raise_error
62
+ end
63
+ end
64
+ end
65
+
66
+ describe '#repo_name' do
67
+
68
+ it 'should return repo_name for final version' do
69
+ allow(Pkg::Config).to receive(:repo_name).and_return('puppet5')
70
+ allow(Pkg::Util::Version).to receive(:final?).and_return(true)
71
+ expect(Pkg::Paths.repo_name).to eq('puppet5')
72
+ end
73
+
74
+ it 'should be empty string if repo_name is not set for final version' do
75
+ allow(Pkg::Config).to receive(:repo_name).and_return(nil)
76
+ allow(Pkg::Util::Version).to receive(:final?).and_return(true)
77
+ expect(Pkg::Paths.repo_name).to eq('')
78
+ end
79
+
80
+ it 'should return nonfinal_repo_name for non-final version' do
81
+ allow(Pkg::Config).to receive(:nonfinal_repo_name).and_return('puppet5-nightly')
82
+ allow(Pkg::Util::Version).to receive(:final?).and_return(false)
83
+ expect(Pkg::Paths.repo_name).to eq('puppet5-nightly')
84
+ end
85
+
86
+ it 'should return repo_name if nonfinal_repo_name is not set for non-final version' do
87
+ allow(Pkg::Config).to receive(:repo_name).and_return('puppet5')
88
+ allow(Pkg::Config).to receive(:nonfinal_repo_name).and_return(nil)
89
+ allow(Pkg::Util::Version).to receive(:final?).and_return(false)
90
+ expect(Pkg::Paths.repo_name).to eq('puppet5')
91
+ end
92
+ end
93
+
94
+ describe '#artifacts_path' do
95
+ before :each do
96
+ allow(Pkg::Paths).to receive(:repo_name).and_return('puppet5')
97
+ end
98
+
99
+ it 'should be correct for el7' do
100
+ expect(Pkg::Paths.artifacts_path('el-7-x86_64')).to eq('artifacts/puppet5/el/7/x86_64')
101
+ end
102
+
103
+ it 'should be correct for trusty' do
104
+ expect(Pkg::Paths.artifacts_path('ubuntu-14.04-amd64')).to eq('artifacts/trusty/puppet5')
105
+ end
106
+
107
+ it 'should be correct for solaris 11' do
108
+ expect(Pkg::Paths.artifacts_path('solaris-11-sparc')).to eq('artifacts/solaris/puppet5/11')
109
+ end
110
+
111
+ it 'should be correct for osx' do
112
+ expect(Pkg::Paths.artifacts_path('osx-10.10-x86_64')).to eq('artifacts/mac/puppet5/10.10/x86_64')
113
+ end
114
+
115
+ it 'should be correct for windows' do
116
+ expect(Pkg::Paths.artifacts_path('windows-2012-x64')).to eq('artifacts/windows/puppet5')
117
+ end
118
+
119
+ it 'should work on all current platforms' do
120
+ Pkg::Platforms.platform_tags.each do |tag|
121
+ expect { Pkg::Paths.artifacts_path(tag) }.not_to raise_error
122
+ end
123
+ end
124
+ end
125
+
126
+ describe '#repo_path' do
127
+ before :each do
128
+ allow(Pkg::Paths).to receive(:repo_name).and_return('puppet5')
129
+ end
130
+
131
+ it 'should be correct' do
132
+ expect(Pkg::Paths.repo_path('el-7-x86_64')).to eq('repos/puppet5/el/7/x86_64')
133
+ end
134
+
135
+ it 'should work on all current platforms' do
136
+ Pkg::Platforms.platform_tags.each do |tag|
137
+ expect { Pkg::Paths.repo_path(tag) }.not_to raise_error
138
+ end
139
+ end
140
+ end
141
+
142
+ describe '#repo_config_path' do
143
+ it 'should be correct' do
144
+ expect(Pkg::Paths.repo_config_path('el-7-x86_64')).to eq('repo_configs/rpm/*el-7-x86_64*.repo')
145
+ end
146
+
147
+ it 'should work on all current platforms' do
148
+ Pkg::Platforms.platform_tags.each do |tag|
149
+ expect { Pkg::Paths.repo_config_path(tag) }.not_to raise_error
150
+ end
151
+ end
152
+ end
153
+ end
@@ -0,0 +1,153 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Pkg::Platforms' do
4
+ describe '#by_package_format' do
5
+ it 'should return an array of platforms that use a given format' do
6
+ deb_platforms = ['cumulus', 'debian', 'ubuntu']
7
+ rpm_platforms = ['aix', 'cisco-wrlinux', 'el', 'fedora', 'redhat-fips', 'sles']
8
+ expect(Pkg::Platforms.by_package_format('deb')).to match_array(deb_platforms)
9
+ expect(Pkg::Platforms.by_package_format('rpm')).to match_array(rpm_platforms)
10
+ end
11
+ end
12
+
13
+ describe '#formats' do
14
+ it 'should return all package formats' do
15
+ fmts = ['rpm', 'deb', 'swix', 'dmg', 'svr4', 'ips', 'msi']
16
+ expect(Pkg::Platforms.formats).to match_array(fmts)
17
+ end
18
+ end
19
+
20
+ describe '#supported_platforms' do
21
+ it 'should return all supported platforms' do
22
+ platforms = ['aix', 'cisco-wrlinux', 'cumulus', 'debian', 'el', 'eos', 'fedora', 'osx', 'redhat-fips', 'sles', 'solaris', 'ubuntu', 'windows']
23
+ expect(Pkg::Platforms.supported_platforms).to match_array(platforms)
24
+ end
25
+ end
26
+
27
+ describe '#versions_for_platform' do
28
+ it 'should return all supported versions for a given platform' do
29
+ expect(Pkg::Platforms.versions_for_platform('el')).to match_array(['5', '6', '7'])
30
+ end
31
+
32
+ it 'should raise an error if given a nonexistent platform' do
33
+ expect{Pkg::Platforms.versions_for_platform('notaplatform') }.to raise_error
34
+ end
35
+ end
36
+
37
+ describe '#codenames' do
38
+ it 'should return all codenames for a given platform' do
39
+ codenames = ['cumulus', 'wheezy', 'jessie', 'stretch', 'trusty', 'xenial']
40
+ expect(Pkg::Platforms.codenames).to match_array(codenames)
41
+ end
42
+ end
43
+
44
+ describe '#codename_to_platform_version' do
45
+ it 'should return the platform and version corresponding to a given codename' do
46
+ expect(Pkg::Platforms.codename_to_platform_version('xenial')).to eq(['ubuntu', '16.04'])
47
+ end
48
+
49
+ it 'should fail if given nil as a codename' do
50
+ expect{Pkg::Platforms.codename_to_platform_version(nil)}.to raise_error
51
+ end
52
+ end
53
+
54
+ describe '#codename_for_platform_version' do
55
+ it 'should return the codename corresponding to a given platform and version' do
56
+ expect(Pkg::Platforms.codename_for_platform_version('ubuntu', '16.04')).to eq('xenial')
57
+ end
58
+ end
59
+
60
+ describe '#arches_for_codename' do
61
+ it 'should return an array of arches corresponding to a given codename' do
62
+ expect(Pkg::Platforms.arches_for_codename('trusty')).to match_array(['i386', 'amd64'])
63
+ end
64
+ end
65
+
66
+ describe '#codename_to_tags' do
67
+ it 'should return an array of platform tags corresponding to a given codename' do
68
+ expect(Pkg::Platforms.codename_to_tags('trusty')).to match_array(['ubuntu-14.04-i386', 'ubuntu-14.04-amd64'])
69
+ end
70
+ end
71
+
72
+ describe '#arches_for_platform_version' do
73
+ it 'should return an array of arches for a given platform and version' do
74
+ expect(Pkg::Platforms.arches_for_platform_version('sles', '11')).to match_array(['i386', 'x86_64', 's390x'])
75
+ end
76
+ end
77
+
78
+ describe '#platform_tags' do
79
+ it 'should return an array of platform tags' do
80
+ tags = Pkg::Platforms.platform_tags
81
+ expect(tags).to be_instance_of(Array)
82
+ expect(tags.count).to be > 0
83
+ end
84
+
85
+ it 'should include a basic platform' do
86
+ tags = Pkg::Platforms.platform_tags
87
+ expect(tags).to include('el-7-x86_64')
88
+ end
89
+ end
90
+
91
+ describe '#platform_lookup' do
92
+ it 'should return a hash of platform info' do
93
+ expect(Pkg::Platforms.platform_lookup('osx-10.10-x86_64')).to be_instance_of(Hash)
94
+ end
95
+
96
+ it 'should include at least arch and package format keys' do
97
+ expect(Pkg::Platforms.platform_lookup('osx-10.10-x86_64').keys).to include(:architectures)
98
+ expect(Pkg::Platforms.platform_lookup('osx-10.10-x86_64').keys).to include(:package_format)
99
+ end
100
+ end
101
+
102
+ describe '#get_attribute' do
103
+ it 'returns info about a given platform' do
104
+ expect(Pkg::Platforms.get_attribute('el-6-x86_64', :signature_format)).to eq('v4')
105
+ end
106
+
107
+ it 'fails with a reasonable error when specified attribute is not defined' do
108
+ expect { Pkg::Platforms.get_attribute('eos-4-i386', :signature_format) }.to raise_error(/doesn't have information/)
109
+ end
110
+ end
111
+
112
+ describe '#package_format_for_tag' do
113
+ it 'should return the package format for a given platform tag' do
114
+ expect(Pkg::Platforms.package_format_for_tag('windows-2012-x86')).to eq('msi')
115
+ end
116
+ end
117
+
118
+ describe '#parse_platform_tag' do
119
+ test_cases = {
120
+ 'debian-9-amd64' => ['debian', '9', 'amd64'],
121
+ 'windows-2012-x86' => ['windows', '2012', 'x86'],
122
+ 'el-7-x86_64' => ['el', '7', 'x86_64'],
123
+ 'cisco-wrlinux-7-x86_64' => ['cisco-wrlinux', '7', 'x86_64'],
124
+ 'cisco-wrlinux-7' => ['cisco-wrlinux', '7', ''],
125
+ 'el-6' => ['el', '6', ''],
126
+ 'xenial-amd64' => ['ubuntu', '16.04', 'amd64'],
127
+ 'xenial' => ['ubuntu', '16.04', ''],
128
+ 'windows-2012' => ['windows', '2012', ''],
129
+ 'redhat-fips-7-x86_64' => ['redhat-fips', '7', 'x86_64'],
130
+ }
131
+
132
+ fail_cases = [
133
+ 'debian-4-amd64',
134
+ 'el-x86_64',
135
+ 'nothing',
136
+ 'windows-x86',
137
+ 'el-7-notarch',
138
+ 'debian-7-x86_64',
139
+ ]
140
+
141
+ test_cases.each do |platform_tag, results|
142
+ it "returns an array for #{platform_tag}" do
143
+ expect(Pkg::Platforms.parse_platform_tag(platform_tag)).to match_array(results)
144
+ end
145
+ end
146
+
147
+ fail_cases.each do |platform_tag|
148
+ it "fails out for #{platform_tag}" do
149
+ expect { Pkg::Platforms.parse_platform_tag(platform_tag)}.to raise_error
150
+ end
151
+ end
152
+ end
153
+ end