simp-rake-helpers 4.0.1 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,179 @@
1
+ require 'simp/rake/build/rpmdeps'
2
+ require 'spec_helper'
3
+ require 'yaml'
4
+
5
+ describe 'Simp::Rake::Build::RpmDeps#get_version_requires' do
6
+ let(:pkg) { 'pupmod-foo-bar' }
7
+
8
+ context 'with valid version specifications' do
9
+ {
10
+ "1.0.0" => ['Requires: pupmod-foo-bar = 1.0.0'],
11
+ "> 2.0.0" => ['Requires: pupmod-foo-bar > 2.0.0'],
12
+ "< 3.0.0" => ['Requires: pupmod-foo-bar < 3.0.0'],
13
+ ">= 4.0.0 < 5.0.0" => ['Requires: pupmod-foo-bar >= 4.0.0',
14
+ 'Requires: pupmod-foo-bar < 5.0.0'],
15
+ "5.x" => ['Requires: pupmod-foo-bar >= 5.0.0',
16
+ 'Requires: pupmod-foo-bar < 6.0.0'],
17
+ "6.4.x" => ['Requires: pupmod-foo-bar >= 6.4.0',
18
+ 'Requires: pupmod-foo-bar < 7.0.0']
19
+ }.each do |input, output|
20
+ it do
21
+ expect(Simp::Rake::Build::RpmDeps::get_version_requires(pkg, input)).to eq output
22
+ end
23
+ end
24
+ end
25
+
26
+ context 'with invalid version specifications' do
27
+ it do
28
+ expect{ Simp::Rake::Build::RpmDeps::get_version_requires(pkg,
29
+ '1.0.0.1') }.to raise_error(SIMPRpmDepVersionException)
30
+ end
31
+
32
+ # FIXME regex doesn't catch this
33
+ pending do
34
+ expect{ Simp::Rake::Build::RpmDeps::get_version_requires(pkg,
35
+ '<= 3.0.0') }.to raise_error(SIMPRpmDepVersionException)
36
+ end
37
+ end
38
+ end
39
+
40
+ describe 'Simp::Rake::Build::RpmDeps#generate_rpm_requires_file' do
41
+ let(:files_dir) { File.join(File.dirname(__FILE__), 'files') }
42
+ let(:rpm_dependency_metadata) {
43
+ YAML.load(File.read(File.join(files_dir, 'dependencies.yaml')))
44
+ }
45
+
46
+ before :each do
47
+ @tmp_dir = Dir.mktmpdir( File.basename( __FILE__ ) )
48
+ FileUtils.cp_r(files_dir, @tmp_dir)
49
+ end
50
+
51
+ after :each do
52
+ FileUtils.remove_entry_secure @tmp_dir
53
+ end
54
+
55
+ context 'managed component with a name change (obsoletes)' do
56
+ it 'should generate requires file with obsoletes' do
57
+ mod_dir = File.join(@tmp_dir, 'files', 'changed_name_mod')
58
+ Simp::Rake::Build::RpmDeps::generate_rpm_requires_file(mod_dir,
59
+ rpm_dependency_metadata)
60
+
61
+ requires_file = File.join(mod_dir, 'build', 'rpm_metadata', 'requires')
62
+ expect(File.exist?(requires_file)).to be true
63
+ expected = <<EOM
64
+ Obsoletes: pupmod-oldowner-changed_name_mod > 2.5.0-2016.1
65
+ Requires: pupmod-foo1-bar1 = 1.0.0
66
+ Requires: pupmod-foo2-bar2 > 2.0.0
67
+ Requires: pupmod-foo3-bar3 < 3.0.0
68
+ Requires: pupmod-foo4-bar4 >= 4.0.0
69
+ Requires: pupmod-foo4-bar4 < 5.0.0
70
+ Requires: pupmod-foo5-bar5 >= 5.0.0
71
+ Requires: pupmod-foo5-bar5 < 6.0.0
72
+ Requires: pupmod-foo6-bar6 >= 6.4.0
73
+ Requires: pupmod-foo6-bar6 < 7.0.0
74
+ EOM
75
+ actual = IO.read(requires_file)
76
+ expect(actual).to eq expected
77
+ end
78
+ end
79
+
80
+ context 'managed component with a subset of metadata.json dependencies' do
81
+ it 'should generate requires file with dependencies only from dependencies.yaml' do
82
+ mod_dir = File.join(@tmp_dir, 'files', 'managed_mod')
83
+ Simp::Rake::Build::RpmDeps::generate_rpm_requires_file(mod_dir,
84
+ rpm_dependency_metadata)
85
+
86
+ requires_file = File.join(mod_dir, 'build', 'rpm_metadata', 'requires')
87
+ expect(File.exist?(requires_file)).to be true
88
+
89
+ # expected should not include pupmod-puppetlabs-apt
90
+ expected = <<EOM
91
+ Requires: pupmod-puppetlabs-stdlib >= 3.2.0
92
+ Requires: pupmod-puppetlabs-stdlib < 5.0.0
93
+ Requires: pupmod-ceritsc-yum >= 0.9.6
94
+ Requires: pupmod-ceritsc-yum < 1.0.0
95
+ Requires: pupmod-richardc-datacat >= 0.6.2
96
+ Requires: pupmod-richardc-datacat < 1.0.0
97
+ EOM
98
+ actual = IO.read(requires_file)
99
+ expect(actual).to eq expected
100
+ end
101
+ end
102
+
103
+ context 'unmanaged component' do
104
+ it 'should replace requires file with metadata.json dependencies' do
105
+ mod_dir = File.join(@tmp_dir, 'files', 'unmanaged_mod')
106
+ Simp::Rake::Build::RpmDeps::generate_rpm_requires_file(mod_dir,
107
+ rpm_dependency_metadata)
108
+
109
+ # expected should overwritten with simply dependencies in order
110
+ # they were listed in metadata.json
111
+ expected = <<EOM
112
+ Requires: pupmod-puppetlabs-inifile >= 1.6.0
113
+ Requires: pupmod-puppetlabs-inifile < 2.0.0
114
+ Requires: pupmod-puppetlabs-puppetdb >= 5.1.2
115
+ Requires: pupmod-puppetlabs-puppetdb < 6.0.0
116
+ Requires: pupmod-puppetlabs-postgresql >= 4.8.0
117
+ Requires: pupmod-puppetlabs-postgresql < 5.0.0
118
+ Requires: pupmod-puppetlabs-stdlib >= 4.13.1
119
+ Requires: pupmod-puppetlabs-stdlib < 5.0.0
120
+ EOM
121
+ requires_file = File.join(mod_dir, 'build', 'rpm_metadata', 'requires')
122
+ expect(File.exist?(requires_file)).to be true
123
+
124
+ actual = IO.read(requires_file)
125
+ expect(actual).to eq expected
126
+
127
+ original = IO.readlines(File.join(files_dir, 'unmanaged_mod',
128
+ 'build', 'rpm_metadata', 'requires'))
129
+ expect(actual).to_not eq original
130
+ end
131
+ end
132
+
133
+ context 'ignores obsoletes when version obsoleted is newer than this version' do
134
+ it 'should generate requires file with no obsoletes' do
135
+ mod_dir = File.join(@tmp_dir, 'files', 'obsoletes_too_new_mod')
136
+ Simp::Rake::Build::RpmDeps::generate_rpm_requires_file(mod_dir,
137
+ rpm_dependency_metadata)
138
+
139
+ requires_file = File.join(mod_dir, 'build', 'rpm_metadata', 'requires')
140
+ expect(File.exist?(requires_file)).to be true
141
+
142
+ # expected should not include pupmod-puppetlabs-apt
143
+ expected = <<EOM
144
+ Requires: pupmod-foo1-bar1 = 1.0.0
145
+ Requires: pupmod-foo2-bar2 > 2.0.0
146
+ EOM
147
+ actual = IO.read(requires_file)
148
+ expect(actual).to eq expected
149
+ end
150
+ end
151
+
152
+ context 'dependency from dependencies.yaml not found in metadata.json' do
153
+ it 'should fail when dep in depedencies.yaml is not found in metadata.json' do
154
+ mod_dir = File.join(@tmp_dir, 'files', 'unknown_dep_mod')
155
+ err_msg = "Could not find oops/unknown dependency in #{mod_dir}/metadata.json"
156
+ expect { Simp::Rake::Build::RpmDeps::generate_rpm_requires_file(mod_dir,
157
+ rpm_dependency_metadata) }.to raise_error(err_msg)
158
+ end
159
+ end
160
+
161
+ context 'malformed dependency version' do
162
+ it 'should fail for managed component with invalid dep version in metadata.json' do
163
+ mod_dir = File.join(@tmp_dir, 'files', 'malformed_dep_meta_mod')
164
+ err_msg = "Unable to parse foo1/bar1 dependency version '1.0.0.1' in #{mod_dir}/metadata.json"
165
+ expect { Simp::Rake::Build::RpmDeps::generate_rpm_requires_file(mod_dir,
166
+ rpm_dependency_metadata) }.to raise_error(err_msg)
167
+ end
168
+
169
+ it 'should fail for unmanaged component with invalid dep version in metadata.json' do
170
+ rpm_dep_meta = rpm_dependency_metadata.dup
171
+ rpm_dep_meta ['malformed_dep_meta_mod'] = nil
172
+ puts rpm_dep_meta
173
+ mod_dir = File.join(@tmp_dir, 'files', 'malformed_dep_meta_mod')
174
+ err_msg = "Unable to parse foo1/bar1 dependency version '1.0.0.1' in #{mod_dir}/metadata.json"
175
+ expect { Simp::Rake::Build::RpmDeps::generate_rpm_requires_file(mod_dir,
176
+ rpm_dep_meta) }.to raise_error(err_msg)
177
+ end
178
+ end
179
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simp-rake-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.1
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Tessmer
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-08-02 00:00:00.000000000 Z
12
+ date: 2017-08-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -413,6 +413,7 @@ files:
413
413
  - lib/simp/rake/build/helpers.rb
414
414
  - lib/simp/rake/build/iso.rb
415
415
  - lib/simp/rake/build/pkg.rb
416
+ - lib/simp/rake/build/rpmdeps.rb
416
417
  - lib/simp/rake/build/spec.rb
417
418
  - lib/simp/rake/build/tar.rb
418
419
  - lib/simp/rake/build/unpack.rb
@@ -481,7 +482,16 @@ files:
481
482
  - spec/lib/simp/files/testpackage-1-0.noarch.rpm
482
483
  - spec/lib/simp/files/testpackage-multi.spec
483
484
  - spec/lib/simp/files/testpackage.spec
485
+ - spec/lib/simp/rake/build/files/changed_name_mod/metadata.json
486
+ - spec/lib/simp/rake/build/files/dependencies.yaml
487
+ - spec/lib/simp/rake/build/files/malformed_dep_meta_mod/metadata.json
488
+ - spec/lib/simp/rake/build/files/managed_mod/metadata.json
489
+ - spec/lib/simp/rake/build/files/obsoletes_too_new_mod/metadata.json
490
+ - spec/lib/simp/rake/build/files/unknown_dep_mod/metadata.json
491
+ - spec/lib/simp/rake/build/files/unmanaged_mod/build/rpm_metadata/requires
492
+ - spec/lib/simp/rake/build/files/unmanaged_mod/metadata.json
484
493
  - spec/lib/simp/rake/build/helpers_spec.rb
494
+ - spec/lib/simp/rake/build/rpmdeps_spec.rb
485
495
  - spec/lib/simp/rake/helpers_spec.rb
486
496
  - spec/lib/simp/rake/pkg_spec.rb
487
497
  - spec/lib/simp/rake/pupmod/fixtures/othermod/Gemfile
@@ -1 +0,0 @@
1
- lib/simp/rake/helpers/assets/rpm_spec/simpdefault.spec