builderator 1.1.9 → 1.1.10

Sign up to get free protection for your applications and to get access to all the features.
File without changes
@@ -1,39 +0,0 @@
1
- require_relative './spec_helper'
2
-
3
- require 'builderator/config'
4
- require 'builderator/interface/berkshelf'
5
- require 'builderator/interface/packer'
6
- require 'builderator/interface/vagrant'
7
-
8
- # :nodoc:
9
- module Builderator
10
- RSpec.describe Interface do
11
- context 'Berksfile' do
12
- berkshelf = Interface.berkshelf
13
-
14
- it 'loads from Config values' do
15
- expect(berkshelf.vendor).to eq Config.local.cookbook_path
16
- end
17
-
18
- it 'generates the correct Berksfile' do
19
- skip
20
- expect(berkshelf.render).to eq IO.read(::File.expand_path('../data/Berksfile', __FILE__))
21
- end
22
- end
23
-
24
- context 'Vagrantfile' do
25
- # vagrant = Interface.vagrant(:default)
26
-
27
- it 'loads from Config values' do
28
- skip
29
- expect(vagrant.build_name).to eq Config.build_name
30
- end
31
-
32
- it 'generates the correct Vagrantfile' do
33
- skip
34
- pending "test doesn't work with absolute paths"
35
- expect(vagrant.render).to eq IO.read(::File.expand_path('../data/Vagrantfile', __FILE__))
36
- end
37
- end
38
- end
39
- end
@@ -1,27 +0,0 @@
1
- ##
2
- # Test Buildfile
3
- ##
4
- build_name 'builderator'
5
-
6
- autoversion.create_tags false
7
- autoversion.search_tags false
8
-
9
- cookbook do |cookbook|
10
- cookbook.depends 'apt'
11
- cookbook.depends 'etcd-v2'
12
- end
13
-
14
- ## Fetch Chef resources
15
- vendor :chef do |vendor|
16
- vendor.git 'git@github.com:rapid7/chef-demo-data.git'
17
- end
18
-
19
- profile :default do |profile|
20
- profile.chef.run_list 'apt::default', 'etcd-v2::node'
21
-
22
- profile.vagrant do |vagrant|
23
- vagrant.local do |local|
24
- local.memory 512
25
- end
26
- end
27
- end
@@ -1,20 +0,0 @@
1
- ##
2
- # This test file simulates a Buildfile in a user's home directory
3
- ##
4
- policy(:test).path './Buildfile-policy-organization'
5
-
6
- profile :default do |default|
7
- default.vagrant.ec2.ssh_host_attribute :public_ip_address
8
- default.vagrant.ec2.source_ami = 'my-source-ami'
9
- default.vagrant.ec2.subnet_id 'my-subnet-1'
10
- default.vagrant.ec2.security_groups 'my-sg-id', :mode => :override
11
- default.vagrant.ec2.iam_instance_profile_arn 'arn:aws:iam::xxxxxxxxxx:instance-profile/iam_profile_name'
12
-
13
- default.vagrant.local do |vagrant_virtualbox|
14
- vagrant_virtualbox.memory 2048
15
- end
16
- end
17
-
18
- vendor :test_policies do |vendor|
19
- vendor.path '.'
20
- end
@@ -1,10 +0,0 @@
1
- ##
2
- # This test file simulates a Buildfile in a cookbook project's working directory
3
- ##
4
- build_name 'builderator-testing'
5
-
6
- policy(:test).path './Buildfile-policy1'
7
-
8
- vendor :test_policies do |vendor|
9
- vendor.path '.'
10
- end
@@ -1,34 +0,0 @@
1
- ##
2
- # This test file simulates a policy Buildfile for a common type of build in an
3
- # organization's CI environment
4
- ##
5
- cookbook.depends 'shared-recipes' do |cookbook|
6
- cookbook.version '~> 2.0'
7
- end
8
-
9
- profile :default do |default|
10
- default.chef do |chef|
11
- chef.run_list 'shared-recipes::default'
12
- chef.environment = 'non-default'
13
- end
14
-
15
- ## Upload the generated code artifact to the image/VM
16
- default.artifact :code_bundle do |bundle|
17
- bundle.path 'target/bundle.tar.gz'
18
- bundle.destination ::File.join(Config.chef.staging_directory,
19
- 'cache/code-bundle.tar.gz')
20
- end
21
- end
22
-
23
- profile :bake => Config.profile(:default) do |bake|
24
- bake.chef.run_list 'shared-recipes::ami-bake', :mode => :override
25
-
26
- bake.packer do |packer|
27
- packer.build :default do |build|
28
-
29
- # build.ami_regions 'eu-central-1' - Packer doesn't support eu-central-1
30
- build.ami_users '0123456789'
31
- end
32
- end
33
-
34
- end
@@ -1,39 +0,0 @@
1
- ##
2
- # This test file simulates a policy Buildfile for a common type of build in an
3
- # organization's CI environment
4
- ##
5
- cookbook.depends 'shared-recipes' do |cookbook|
6
- cookbook.version '~> 2.0'
7
- end
8
-
9
- profile :default do |default|
10
- default.tags(:service => Config.build_name,
11
- :version => "#{Config.version}-#{Config.build_number}",
12
- :created => Config.date.iso8601)
13
-
14
- default.chef do |chef|
15
- chef.run_list 'shared-recipes::default'
16
- chef.environment = 'non-default'
17
- end
18
-
19
- ## Upload the generated code artifact to the image/VM
20
- default.artifact :code_bundle do |bundle|
21
- bundle.path 'target/bundle.tar.gz'
22
- bundle.destination ::File.join(Config.chef.staging_directory,
23
- 'cache/code-bundle.tar.gz')
24
- end
25
- end
26
-
27
- profile :bake => Config.profile(:default) do |bake|
28
- bake.tags(:parent => 'some-value') ## TODO This triggers an issue still.
29
-
30
- bake.chef.run_list 'shared-recipes::ami-bake', :mode => :override
31
-
32
- bake.packer do |packer|
33
- packer.build :default do |build|
34
-
35
- # build.ami_regions 'eu-central-1' - Packer doesn't support eu-central-1
36
- build.ami_users '0123456789'
37
- end
38
- end
39
- end
@@ -1,31 +0,0 @@
1
- ##
2
- # This test file simulates a policy Buildfile for an organization's CI environment
3
- ##
4
- cookbook do |cb|
5
- cb.add_source 'https://supermarket.chef.io'
6
- end
7
-
8
- local do |local|
9
- local.data_bag_path relative('data_bags')
10
- local.environment_path relative('environments')
11
- end
12
-
13
- profile(:default) do |default|
14
-
15
- default.vagrant.ec2 do |ec2|
16
- ## VPN-attached VPC resources
17
- ec2.subnet_id 'my-subnet-id'
18
- ec2.security_groups 'my-sg-id'
19
-
20
- ec2.associate_public_ip false
21
- ec2.ssh_host_attribute :private_ip_address
22
- end
23
-
24
- default.packer.build(:default) do |build|
25
- build.ami_name [Config.build_name, Config.version, Config.build_number].reject(&:nil?).join('-')
26
- end
27
- end
28
-
29
- generator.project :default do |default|
30
- default.ruby.version '2.1.5'
31
- end
@@ -1,5 +0,0 @@
1
- ##
2
- # This test file simulates a Buildfile in a project's working directory
3
- # without any cookbooks
4
- ##
5
- build_name 'builderator-simple-test'
@@ -1,17 +0,0 @@
1
- ##
2
- # This test file simulates a Buildfile in a project's working directory
3
- # without any cookbooks
4
- ##
5
- build_name 'builderator-with-overrides'
6
-
7
- policy(:test).path './Buildfile-policy-buildtype1'
8
-
9
- profile :default do |default|
10
- default.chef do |chef|
11
- chef.run_list ['rapid7-test::default']
12
- end
13
- end
14
-
15
- profile :bake => Config.profile(:default) do |bake|
16
- bake.chef.run_list ['rapid7-test::override']
17
- end
@@ -1,17 +0,0 @@
1
- ##
2
- # This test file simulates a Buildfile in a project's working directory
3
- # without any cookbooks
4
- ##
5
- build_name 'builderator-with-overrides'
6
-
7
- policy(:test).path './Buildfile-policy-buildtype2'
8
-
9
- profile :default do |default|
10
- default.chef do |chef|
11
- chef.run_list ['rapid7-test::default']
12
- end
13
- end
14
-
15
- profile :bake => Config.profile(:default) do |bake|
16
- bake.chef.run_list ['rapid7-test::override']
17
- end
@@ -1,7 +0,0 @@
1
- ##
2
- # This test file simulates a Buildfile in a project's working directory
3
- # without any cookbooks
4
- ##
5
- build_name 'builderator-with-policy-test'
6
-
7
- policy(:test).path './Buildfile-policy-buildtype1'
@@ -1,89 +0,0 @@
1
- lib = File.expand_path('../../lib', __FILE__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
-
4
- require 'builderator/config'
5
- require 'builderator/util'
6
-
7
- module Builderator
8
- ## Hack everything into running in spec/resource
9
- module Util
10
- class << self
11
- def relative_path(*relative)
12
- relative = relative.flatten.map { |r| r.to_s }
13
- Pathname.new(__FILE__).join('../resource').join(*relative).expand_path
14
- end
15
- end
16
- end
17
- end
18
-
19
- RSpec.configure do |config|
20
- # rspec-expectations config goes here. You can use an alternate
21
- # assertion/expectation library such as wrong or the stdlib/minitest
22
- # assertions if you prefer.
23
- config.expect_with :rspec do |expectations|
24
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
25
- end
26
-
27
- # rspec-mocks config goes here. You can use an alternate test double
28
- # library (such as bogus or mocha) by changing the `mock_with` option here.
29
- config.mock_with :rspec do |mocks|
30
- mocks.verify_partial_doubles = true
31
- end
32
-
33
- # The settings below are suggested to provide a good initial experience
34
- # with RSpec, but feel free to customize to your heart's content.
35
-
36
- # rubocop:disable Style/BlockComments
37
- =begin
38
- # These two settings work together to allow you to limit a spec run
39
- # to individual examples or groups you care about by tagging them with
40
- # `:focus` metadata. When nothing is tagged with `:focus`, all examples
41
- # get run.
42
- config.filter_run :focus
43
- config.run_all_when_everything_filtered = true
44
-
45
- # Allows RSpec to persist some state between runs in order to support
46
- # the `--only-failures` and `--next-failure` CLI options. We recommend
47
- # you configure your source control system to ignore this file.
48
- config.example_status_persistence_file_path = "spec/examples.txt"
49
-
50
- # Limits the available syntax to the non-monkey patched syntax that is
51
- # recommended. For more details, see:
52
- # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
53
- # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
54
- # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
55
- config.disable_monkey_patching!
56
-
57
- # This setting enables warnings. It's recommended, but in some cases may
58
- # be too noisy due to issues in dependencies.
59
- config.warnings = true
60
-
61
- # Many RSpec users commonly either run the entire suite or an individual
62
- # file, and it's useful to allow more verbose output when running an
63
- # individual spec file.
64
- if config.files_to_run.one?
65
- # Use the documentation formatter for detailed output,
66
- # unless a formatter has already been configured
67
- # (e.g. via a command-line flag).
68
- config.default_formatter = 'doc'
69
- end
70
-
71
- # Print the 10 slowest examples and example groups at the
72
- # end of the spec run, to help surface which specs are running
73
- # particularly slow.
74
- config.profile_examples = 10
75
-
76
- # Run specs in random order to surface order dependencies. If you find an
77
- # order dependency and want to debug it, you can fix the order by providing
78
- # the seed, which is printed after each run.
79
- # --seed 1234
80
- config.order = :random
81
-
82
- # Seed global randomization in this process using the `--seed` CLI option.
83
- # Setting this allows you to use `--seed` to deterministically reproduce
84
- # test failures related to randomization by passing the same `--seed` value
85
- # as the one that triggered the failure.
86
- Kernel.srand config.seed
87
- =end
88
- # rubocop:enable Style/BlockComments
89
- end
@@ -1,322 +0,0 @@
1
- require_relative './spec_helper'
2
-
3
- require 'json'
4
- require 'builderator/control/version'
5
-
6
- # rubocop:disable Metrics/ClassLength
7
-
8
- module Builderator
9
- module Control
10
- # :nodoc:
11
- class Version
12
- ## Test stub to load from an included JSON document
13
- module Test
14
- extend SCM
15
-
16
- def self.supported?
17
- true
18
- end
19
-
20
- def self._history
21
- JSON.parse(
22
- IO.read(::File.expand_path('../data/history.json', __FILE__)),
23
- :symbolize_names => true)
24
- end
25
- end
26
-
27
- ## Test stub with no history
28
- module NoHistory
29
- extend SCM
30
-
31
- def self.supported?
32
- true
33
- end
34
-
35
- def self._history
36
- []
37
- end
38
- end
39
-
40
- ## Disable the Git provider
41
- module Git
42
- extend SCM
43
-
44
- def self.supported?
45
- false
46
- end
47
- end
48
-
49
- RSpec.describe Builderator::Control::Version do
50
- before(:context) do
51
- SCM.unregister(Test)
52
- SCM.register(NoHistory)
53
- end
54
-
55
- after(:context) do
56
- SCM.unregister(NoHistory)
57
- SCM.register(Test)
58
- end
59
-
60
- context 'current' do
61
- it 'provides an error message if no version is found' do
62
- version_file = Util.relative_path('VERSION')
63
- version_file.delete if version_file.exist?
64
-
65
- expect(SCM.tags.last).to be_nil
66
- expect { Version.current }.to raise_error RuntimeError
67
- end
68
-
69
- it 'falls back to VERSION file if no tags are found' do
70
- Util.relative_path('VERSION').write('1.2.3')
71
- expect(Version.current).to be == Version.from_string('1.2.3')
72
- end
73
- end
74
- end
75
-
76
- SCM.register(Test)
77
-
78
- RSpec.describe Builderator::Control::Version do
79
- context 'loading, parsing, and ordering of commits and tags' do
80
- it 'loads history from a provider' do
81
- expect(SCM.history).to be_a Array
82
- expect(SCM.history).to_not be_empty
83
- expect(SCM.history).to all be_a SCM::Commit
84
- end
85
-
86
- context 'parses semver strings correctly' do
87
- it 'parses a.b.c versions correctly' do
88
- version = Version.from_string('1.2.3')
89
-
90
- expect(version.major).to be == 1
91
- expect(version.minor).to be == 2
92
- expect(version.patch).to be == 3
93
-
94
- expect(version.is_prerelease).to be false
95
- expect(version.prerelease_name).to be_nil
96
- expect(version.prerelease_iteration).to be_nil
97
- expect(version.build).to be_nil
98
- end
99
-
100
- it 'parses pre-release versions correctly' do
101
- version = Version.from_string('1.2.3-pre.42')
102
-
103
- expect(version.major).to be == 1
104
- expect(version.minor).to be == 2
105
- expect(version.patch).to be == 3
106
- expect(version.is_prerelease).to be true
107
- expect(version.prerelease_name).to be == 'pre'
108
- expect(version.prerelease_iteration).to be == 42
109
- expect(version.build).to be_nil
110
- end
111
-
112
- it 'parses build versions correctly' do
113
- version = Version.from_string('1.2.3+build.9')
114
-
115
- expect(version.major).to be == 1
116
- expect(version.minor).to be == 2
117
- expect(version.patch).to be == 3
118
- expect(version.is_prerelease).to be false
119
- expect(version.prerelease_name).to be_nil
120
- expect(version.prerelease_iteration).to be_nil
121
- expect(version.build).to be == 9
122
- end
123
-
124
- it 'parses the complete spec' do
125
- version = Version.from_string('1.2.3-yolo.42+build.9')
126
-
127
- expect(version.major).to be == 1
128
- expect(version.minor).to be == 2
129
- expect(version.patch).to be == 3
130
- expect(version.is_prerelease).to be true
131
- expect(version.prerelease_name).to be == 'yolo'
132
- expect(version.prerelease_iteration).to be == 42
133
- expect(version.build).to be == 9
134
- end
135
-
136
- it 'does not fail on invalid specs' do
137
- expect(Version.from_string('1.2.lizard-alpha.42+build.9')).to be_nil
138
- expect(Version.from_string('1.2.3-alpha.42+taco.9')).to be_nil
139
- expect(Version.from_string('1.2.3-alpha.guacamole+build.9')).to be_nil
140
- expect(Version.from_string('1.2.3-alpha.42+build.beef')).to be_nil
141
- expect(Version.from_string('1.2.dog')).to be_nil
142
- expect(Version.from_string('1.cat.3')).to be_nil
143
- expect(Version.from_string('cow.2.3')).to be_nil
144
- end
145
- end
146
-
147
- it 'generates Version objects from commits' do
148
- expect(SCM.tags).to be_a Array
149
- expect(SCM.tags).to_not be_empty
150
- expect(SCM.tags).to all be_a Version
151
- end
152
-
153
- it 'finds the current version of the module' do
154
- expect(SCM.tags).to all be <= Version.current
155
- end
156
- end
157
-
158
- context 'bumping versions' do
159
- it 'attaches the correct SCM ref to new versions' do
160
- previous = Version.current
161
-
162
- Version.bump(:major)
163
- expect(Version.current.ref).to eq SCM.history.first.id
164
- expect(Version.current).to_not equal(previous)
165
- end
166
-
167
- it 'fails when an invalid step is passed to #bump' do
168
- expect { Version.bump(:lizard) }.to raise_error RuntimeError
169
- end
170
-
171
- context 'bump build' do
172
- it 'adds, increments, and resets build numbers' do
173
- expect(Version.current.build).to be_nil
174
- previous = Version.current
175
-
176
- Version.bump(:build)
177
- expect(Version.current).to_not equal(previous)
178
- expect(Version.current.build).to be == 0
179
-
180
- Version.bump(:build)
181
- expect(Version.current.build).to be == 1
182
-
183
- Version.bump(:patch)
184
- expect(Version.current.build).to be_nil
185
- end
186
- end
187
-
188
- context 'bump prerelease and release' do
189
- it 'creates and increments pre-releases from previous releases' do
190
- expect(Version.current.is_prerelease).to be false
191
- previous = Version.current
192
-
193
- Version.bump(:prerelease)
194
- expect(Version.current.patch).to be == (previous.patch + 1)
195
- expect(Version.current.is_prerelease).to be true
196
- expect(Version.current.prerelease_name).to be == 'alpha'
197
- expect(Version.current.prerelease_iteration).to be == 0
198
-
199
- Version.bump(:prerelease)
200
- expect(Version.current.prerelease_name).to be == 'alpha'
201
- expect(Version.current.prerelease_iteration).to be == 1
202
- end
203
-
204
- it 'creates and increments pre-releases with a specified name' do
205
- expect(Version.current.is_prerelease).to be true
206
-
207
- Version.bump(:prerelease, 'beta')
208
- expect(Version.current.prerelease_name).to be == 'beta'
209
- expect(Version.current.prerelease_iteration).to be == 0
210
-
211
- Version.bump(:prerelease)
212
- expect(Version.current.prerelease_name).to be == 'beta'
213
- expect(Version.current.prerelease_iteration).to be == 1
214
-
215
- Version.bump(:prerelease, 'beta')
216
- expect(Version.current.prerelease_name).to be == 'beta'
217
- expect(Version.current.prerelease_iteration).to be == 2
218
- end
219
-
220
- it 'removes pre-release parameters for a release' do
221
- expect(Version.current.is_prerelease).to be true
222
- previous = Version.current
223
-
224
- Version.bump(:release)
225
- expect(Version.current.patch).to be == previous.patch
226
- expect(Version.current.is_prerelease).to be false
227
- expect(Version.current.prerelease_name).to be_nil
228
- expect(Version.current.prerelease_iteration).to be_nil
229
- end
230
- end
231
-
232
- context 'bump major, minor, and patch-prerelease' do
233
- it 'creates a new patch version for a patch-prerelease' do
234
- Version.bump(:prerelease)
235
- previous = Version.current
236
- expect(Version.current.is_prerelease).to be true
237
-
238
- Version.bump('patch-prerelease')
239
- expect(Version.current.is_prerelease).to be true
240
- expect(Version.current.patch).to be == (previous.patch + 1)
241
- end
242
-
243
- it 'creates a new minor version for a minor-prerelease' do
244
- previous = Version.current
245
- expect(Version.current.is_prerelease).to be true
246
-
247
- Version.bump('minor-prerelease')
248
- expect(Version.current.is_prerelease).to be true
249
- expect(Version.current.patch).to be == 0
250
- expect(Version.current.minor).to be == (previous.minor + 1)
251
- end
252
-
253
- it 'creates a new major version for a major-prerelease' do
254
- previous = Version.current
255
- expect(Version.current.is_prerelease).to be true
256
-
257
- Version.bump('major-prerelease')
258
- expect(Version.current.is_prerelease).to be true
259
- expect(Version.current.patch).to be == 0
260
- expect(Version.current.minor).to be == 0
261
- expect(Version.current.major).to be == (previous.major + 1)
262
- end
263
- end
264
-
265
- context 'bump major, minor, and patch' do
266
- it 'creates a new patch version and resets build and prerelease parameters' do
267
- Version.bump(:prerelease)
268
- Version.bump(:build)
269
- previous = Version.current
270
-
271
- expect(Version.current.is_prerelease).to be true
272
- expect(Version.current.build).to_not be_nil
273
-
274
- Version.bump(:patch)
275
-
276
- expect(Version.current.is_prerelease).to be false
277
- expect(Version.current.build).to be_nil
278
- expect(Version.current.patch).to be == (previous.patch + 1)
279
- end
280
-
281
- it 'creates a new minor version and resets lower-precedence parameters' do
282
- Version.bump(:prerelease)
283
- Version.bump(:build)
284
- previous = Version.current
285
-
286
- expect(Version.current.is_prerelease).to be true
287
- expect(Version.current.build).to_not be_nil
288
- expect(Version.current.patch).to_not be == 0
289
-
290
- Version.bump(:minor)
291
-
292
- expect(Version.current.is_prerelease).to be false
293
- expect(Version.current.build).to be_nil
294
- expect(Version.current.patch).to be == 0
295
- expect(Version.current.minor).to be == (previous.minor + 1)
296
- end
297
-
298
- it 'creates a new major version and resets lower-precedence parameters' do
299
- Version.bump(:prerelease)
300
- Version.bump(:build)
301
- previous = Version.current
302
-
303
- expect(Version.current.is_prerelease).to be true
304
- expect(Version.current.build).to_not be_nil
305
- expect(Version.current.patch).to_not be == 0
306
- expect(Version.current.minor).to_not be == 0
307
-
308
- Version.bump(:major)
309
-
310
- expect(Version.current.is_prerelease).to be false
311
- expect(Version.current.build).to be_nil
312
- expect(Version.current.patch).to be == 0
313
- expect(Version.current.minor).to be == 0
314
- expect(Version.current.major).to be == (previous.major + 1)
315
- end
316
- end
317
- end
318
- end
319
- end
320
- end
321
- end
322
- # rubocop:enable Metrics/ClassLength