clc-promote 0.8.7 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,181 +2,194 @@ require 'promote'
2
2
  require_relative '../support/dummy_log'
3
3
 
4
4
  describe Promote::Versioner do
5
- before(:all) {
5
+ before(:all) do
6
6
  cb_dir = '/tmp/promote_test_cookbooks'
7
7
  FileUtils.rm_rf(cb_dir) if Dir.exist?(cb_dir)
8
8
  Dir.mkdir(cb_dir)
9
- FileUtils.cp_r(File.join(File.dirname(File.dirname(__FILE__)), 'stubs'), cb_dir)
10
- }
11
-
12
- let(:cookbook_dir) {'/tmp/promote_test_cookbooks/stubs'}
13
- let(:test_cookbook) {'cookbook_1'}
14
- let(:config) {Promote::Config.new(:cookbook_directory => cookbook_dir)}
15
- let(:fake_file) { double('file') }
16
-
17
- let(:artifact_file) { "" }
18
- let(:fake_berks) { double('berksfile', :install => nil) }
19
- before {
20
- allow(Berkshelf::Berksfile).to receive(:from_file).and_return(fake_berks)
21
- allow_any_instance_of(Promote::GitRepo).to receive(:git).and_return(Git::Base.new)
22
- allow_any_instance_of(Git::Base).to receive(:tags).and_return([
23
- double("tag", :name => '1.0', :sha => 'abc'),
24
- double("tag", :name => '1.1', :sha => 'def'),
25
- double("tag", :name => '1.2', :sha => 'ghi')
26
- ])
27
- allow_any_instance_of(Git::Base).to receive(:log).with(10000).and_return(
28
- PromoteSpecs::DummyLog.new([
29
- {:msg => 'blah', :sha => 'aaa'},
30
- {:msg => 'CI:bumping', :sha => 'bbb'},
31
- {:msg => 'blah', :sha => 'ccc'}
32
- ]))
33
- config = Promote::Config.new
34
- }
9
+ FileUtils.cp_r(
10
+ File.join(File.dirname(File.dirname(__FILE__)), 'stubs'),
11
+ cb_dir
12
+ )
13
+ end
14
+
15
+ let(:cookbook_dir) { '/tmp/promote_test_cookbooks/stubs' }
16
+ let(:test_cookbook) { 'cookbook_1' }
17
+ let(:config) { Promote::Config.new(cookbook_directory: cookbook_dir) }
18
+ let(:fake_file) { double('file') }
19
+
20
+ let(:artifact_file) { '' }
21
+ let(:fake_berks) { double('berksfile', install: nil) }
22
+ before do
23
+ allow(Berkshelf::Berksfile).to receive(:from_file).and_return(fake_berks)
24
+ allow_any_instance_of(Promote::GitRepo).to receive(:git)
25
+ .and_return(Git::Base.new)
26
+ allow_any_instance_of(Git::Base).to receive(:tags).and_return([
27
+ double('tag', name: '1.0', sha: 'abc'),
28
+ double('tag', name: '1.1', sha: 'def'),
29
+ double('tag', name: '1.2', sha: 'ghi')
30
+ ])
31
+ allow_any_instance_of(Git::Base).to receive(:log).with(10_000).and_return(
32
+ PromoteSpecs::DummyLog.new([
33
+ { msg: 'blah', sha: 'aaa' },
34
+ { msg: 'CI:bumping', sha: 'bbb' },
35
+ { msg: 'blah', sha: 'ccc' }
36
+ ]))
37
+ end
35
38
 
36
39
  subject { Promote::Versioner.new(config) }
37
40
 
38
- context 'version_cookbook' do
39
- context 'when versioning a new cookbook version' do
40
- it "writes the new version and sha to the file" do
41
- subject.version_cookbook(test_cookbook)
42
- expect(Promote::Cookbook.new(test_cookbook, config).version.to_s).to eq('1.2.2')
43
- end
44
-
45
- it "adds the new version and sha to the cookbook" do
46
- subject.version_cookbook(test_cookbook)
47
- expect(Promote::Cookbook.new(test_cookbook, config).raw_metadata).to end_with("#sha1 'aaa'")
48
- end
49
- end
50
-
51
- context 'when versioning a cookbook with no changes' do
52
- it "does not write to metadata rb" do
53
- expect(subject.version_cookbook(test_cookbook)).to be nil
54
- end
55
- end
56
- end
57
-
58
- context 'version_cookbooks' do
59
- let(:cookbooks) {[
60
- File.join(subject.config.cookbook_directory, "cookbook1"),
61
- File.join(subject.config.cookbook_directory, "cookbook2"),
62
- File.join(subject.config.cookbook_directory, "cookbook3")
63
- ]}
64
- before {
65
- allow(subject).to receive(:version_cookbook)
66
- allow(Dir).to receive(:glob).with(
67
- File.join(subject.config.cookbook_directory, "*")).and_return(cookbooks)
68
- }
69
-
70
- it "versions each cookbook" do
71
- cookbooks.each do |cookbook|
72
- expect(subject).to receive(:version_cookbook).with(File.basename(cookbook))
73
- end
74
- subject.version_cookbooks
75
- end
76
- end
77
-
78
- context 'version_environment' do
79
- before {
80
- regex = File.join(config.environment_directory,'test.json')
81
- allow(File).to receive(:read).with(regex).and_return(artifact_file)
82
- allow(File).to receive(:open).with(regex, "w").and_yield(fake_file)
83
- }
84
-
85
- context 'when versioning a new environment with no version' do
86
- let(:artifact_file) do
87
- <<-EOS
88
- {
89
- "name": "QA1",
90
- "chef_type": "environment",
91
- "json_class": "Chef::Environment",
92
- "override_attributes": {
93
- "environment_parent": "QA"
94
- }
95
- }
96
- EOS
97
- end
98
-
99
- it "writes the new version and sha to the file" do
100
- parsed = JSON.parse(artifact_file)
101
- parsed['override_attributes']['version'] = '1.2.2'
102
- parsed['override_attributes']['sha1'] = 'aaa'
103
- expect(fake_file).to receive(:<<).with(JSON.pretty_generate(parsed))
104
- subject.version_environment('test')
105
- end
106
- end
107
-
108
- context 'when versioning a new environment with old version' do
109
-
110
- let(:artifact_file) do
111
- <<-EOS
112
- {
113
- "name": "QA1",
114
- "chef_type": "environment",
115
- "json_class": "Chef::Environment",
116
- "override_attributes": {
117
- "environment_parent": "QA",
118
- "version": "1.0.0",
119
- "sha1": "ccc"
120
- }
121
- }
122
- EOS
123
- end
124
-
125
- it "writes the new version and sha to the file" do
126
- parsed = JSON.parse(artifact_file)
127
- parsed['override_attributes']['version'] = '1.2.2'
128
- parsed['override_attributes']['sha1'] = 'aaa'
129
- expect(fake_file).to receive(:<<).with(JSON.pretty_generate(parsed))
130
- subject.version_environment('test')
131
- end
132
- end
133
-
134
- context 'when commiting an environment with no changes' do
135
- let(:artifact_file) do
136
- <<-EOS
137
- {
138
- "name": "QA1",
139
- "chef_type": "environment",
140
- "json_class": "Chef::Environment",
141
- "override_attributes": {
142
- "environment_parent": "QA",
143
- "version": "1.2.2",
144
- "sha1": "aaa"
145
- }
146
- }
147
- EOS
148
- end
149
-
150
- it "does not write to the file" do
151
- expect(fake_file).not_to receive(:<<)
152
- subject.version_environment('test')
153
- end
154
- end
155
- end
156
-
157
- context 'version_environments' do
158
- let(:environments) {%w{dir/environment1.json dir/environment2.json dir/environment3.json}}
159
- before {
160
- allow(subject).to receive(:version_environment)
161
- allow(Dir).to receive(:glob).with(
162
- File.join(subject.config.environment_directory, "*.json")).and_return(environments)
163
- }
164
-
165
- it "versions each environment" do
166
- environments.each do |environment|
167
- expect(subject).to receive(:version_environment).with(
168
- File.basename(environment ,File.extname(environment)))
169
- end
170
- subject.version_environments
171
- end
172
- end
41
+ context 'version_cookbook' do
42
+ context 'when versioning a new cookbook version' do
43
+ let(:cookbook) { Promote::Cookbook.new(test_cookbook, config) }
44
+ it 'writes the new version and sha to the file' do
45
+ subject.version_cookbook(test_cookbook)
46
+ expect(cookbook.version.to_s).to eq('1.2.2')
47
+ end
48
+
49
+ it 'adds the new version and sha to the cookbook' do
50
+ subject.version_cookbook(test_cookbook)
51
+ expect(cookbook.raw_metadata).to end_with("#sha1 'aaa'")
52
+ end
53
+ end
54
+
55
+ context 'when versioning a cookbook with no changes' do
56
+ it 'does not write to metadata rb' do
57
+ expect(subject.version_cookbook(test_cookbook)).to be nil
58
+ end
59
+ end
60
+ end
61
+
62
+ context 'version_cookbooks' do
63
+ let(:cookbooks) do
64
+ [
65
+ File.join(subject.config.cookbook_directory, 'cookbook1'),
66
+ File.join(subject.config.cookbook_directory, 'cookbook2'),
67
+ File.join(subject.config.cookbook_directory, 'cookbook3')
68
+ ]
69
+ end
70
+ before do
71
+ allow(subject).to receive(:version_cookbook)
72
+ allow(Dir).to receive(:glob).with(
73
+ File.join(subject.config.cookbook_directory, '*')).and_return(cookbooks)
74
+ end
75
+
76
+ it 'versions each cookbook' do
77
+ cookbooks.each do |cookbook|
78
+ expect(subject).to receive(:version_cookbook)
79
+ .with(File.basename(cookbook))
80
+ end
81
+ subject.version_cookbooks
82
+ end
83
+ end
84
+
85
+ context 'version_environment' do
86
+ before do
87
+ regex = File.join(config.environment_directory, 'test.json')
88
+ allow(File).to receive(:read).with(regex).and_return(artifact_file)
89
+ allow(File).to receive(:open).with(regex, 'w').and_yield(fake_file)
90
+ end
91
+
92
+ context 'when versioning a new environment with no version' do
93
+ let(:artifact_file) do
94
+ <<-EOS
95
+ {
96
+ "name": "QA1",
97
+ "chef_type": "environment",
98
+ "json_class": "Chef::Environment",
99
+ "override_attributes": {
100
+ "environment_parent": "QA"
101
+ }
102
+ }
103
+ EOS
104
+ end
105
+
106
+ it 'writes the new version and sha to the file' do
107
+ parsed = JSON.parse(artifact_file)
108
+ parsed['override_attributes']['version'] = '1.2.2'
109
+ parsed['override_attributes']['sha1'] = 'aaa'
110
+ expect(fake_file).to receive(:<<).with(JSON.pretty_generate(parsed))
111
+ subject.version_environment('test')
112
+ end
113
+ end
114
+
115
+ context 'when versioning a new environment with old version' do
116
+ let(:artifact_file) do
117
+ <<-EOS
118
+ {
119
+ "name": "QA1",
120
+ "chef_type": "environment",
121
+ "json_class": "Chef::Environment",
122
+ "override_attributes": {
123
+ "environment_parent": "QA",
124
+ "version": "1.0.0",
125
+ "sha1": "ccc"
126
+ }
127
+ }
128
+ EOS
129
+ end
130
+
131
+ it 'writes the new version and sha to the file' do
132
+ parsed = JSON.parse(artifact_file)
133
+ parsed['override_attributes']['version'] = '1.2.2'
134
+ parsed['override_attributes']['sha1'] = 'aaa'
135
+ expect(fake_file).to receive(:<<).with(JSON.pretty_generate(parsed))
136
+ subject.version_environment('test')
137
+ end
138
+ end
139
+
140
+ context 'when commiting an environment with no changes' do
141
+ let(:artifact_file) do
142
+ <<-EOS
143
+ {
144
+ "name": "QA1",
145
+ "chef_type": "environment",
146
+ "json_class": "Chef::Environment",
147
+ "override_attributes": {
148
+ "environment_parent": "QA",
149
+ "version": "1.2.2",
150
+ "sha1": "aaa"
151
+ }
152
+ }
153
+ EOS
154
+ end
155
+
156
+ it 'does not write to the file' do
157
+ expect(fake_file).not_to receive(:<<)
158
+ subject.version_environment('test')
159
+ end
160
+ end
161
+ end
162
+
163
+ context 'version_environments' do
164
+ let(:environments) do
165
+ [
166
+ 'dir/environment1.json',
167
+ 'dir/environment2.json',
168
+ 'dir/environment3.json'
169
+ ]
170
+ end
171
+ before do
172
+ allow(subject).to receive(:version_environment)
173
+ allow(Dir).to receive(:glob).with(
174
+ File.join(subject.config.environment_directory, '*.json'))
175
+ .and_return(environments)
176
+ end
177
+
178
+ it 'versions each environment' do
179
+ environments.each do |environment|
180
+ expect(subject).to receive(:version_environment).with(
181
+ File.basename(environment, File.extname(environment)))
182
+ end
183
+ subject.version_environments
184
+ end
185
+ end
173
186
 
174
187
  context 'version_role' do
175
- before {
176
- regex = File.join(config.role_directory,'test.json')
188
+ before do
189
+ regex = File.join(config.role_directory, 'test.json')
177
190
  allow(File).to receive(:read).with(regex).and_return(artifact_file)
178
- allow(File).to receive(:open).with(regex, "w").and_yield(fake_file)
179
- }
191
+ allow(File).to receive(:open).with(regex, 'w').and_yield(fake_file)
192
+ end
180
193
 
181
194
  context 'when versioning a new role with no version' do
182
195
  let(:artifact_file) do
@@ -191,7 +204,7 @@ describe Promote::Versioner do
191
204
  }
192
205
  EOS
193
206
  end
194
- it "writes the new version and sha to the file" do
207
+ it 'writes the new version and sha to the file' do
195
208
  parsed = JSON.parse(artifact_file)
196
209
  parsed['override_attributes']['version'] = '1.2.2'
197
210
  parsed['override_attributes']['sha1'] = 'aaa'
@@ -210,9 +223,9 @@ describe Promote::Versioner do
210
223
  }
211
224
  EOS
212
225
  end
213
- it "adds an override_attributes key to the role" do
226
+ it 'adds an override_attributes key to the role' do
214
227
  parsed = JSON.parse(artifact_file)
215
- override_hash = { "override_attributes" => {} }
228
+ override_hash = { 'override_attributes' => {} }
216
229
  parsed.merge!(override_hash)
217
230
  expect(fake_file).to receive(:<<).with(JSON.pretty_generate(parsed))
218
231
  subject.version_role('test')
@@ -220,7 +233,6 @@ describe Promote::Versioner do
220
233
  end
221
234
 
222
235
  context 'when versioning a new role with old version' do
223
-
224
236
  let(:artifact_file) do
225
237
  <<-EOS
226
238
  {
@@ -236,7 +248,7 @@ describe Promote::Versioner do
236
248
  EOS
237
249
  end
238
250
 
239
- it "writes the new version and sha to the file" do
251
+ it 'writes the new version and sha to the file' do
240
252
  parsed = JSON.parse(artifact_file)
241
253
  parsed['override_attributes']['version'] = '1.2.2'
242
254
  parsed['override_attributes']['sha1'] = 'aaa'
@@ -261,7 +273,7 @@ describe Promote::Versioner do
261
273
  EOS
262
274
  end
263
275
 
264
- it "does not write to the file" do
276
+ it 'does not write to the file' do
265
277
  expect(fake_file).not_to receive(:<<)
266
278
  subject.version_role('test')
267
279
  end
@@ -269,158 +281,169 @@ describe Promote::Versioner do
269
281
  end
270
282
 
271
283
  context 'version_roles' do
272
- let(:roles) {%w{dir/role1.json dir/role2.json dir/role3.json}}
273
- before {
284
+ let(:roles) { %w(dir/role1.json dir/role2.json dir/role3.json) }
285
+ before do
274
286
  allow(subject).to receive(:version_role)
275
287
  allow(Dir).to receive(:glob).with(
276
- File.join(subject.config.role_directory, "*.json")).and_return(roles)
277
- }
288
+ File.join(subject.config.role_directory, '*.json')).and_return(roles)
289
+ end
278
290
 
279
- it "versions each role" do
291
+ it 'versions each role' do
280
292
  roles.each do |role|
281
293
  expect(subject).to receive(:version_role).with(
282
- File.basename(role ,File.extname(role)))
294
+ File.basename(role, File.extname(role)))
283
295
  end
284
296
  subject.version_roles
285
297
  end
286
298
  end
287
299
 
288
- context 'constrain_environment' do
289
- before {
290
- regex = File.join(config.environment_directory,'test.json')
291
- allow(File).to receive(:read).with(regex).and_return(artifact_file)
292
- allow(File).to receive(:open).with(regex, "w").and_yield(fake_file)
293
- }
294
-
295
- let(:artifact_file) do
296
- <<-EOS
297
- {
298
- "name": "QA1",
299
- "chef_type": "environment",
300
- "json_class": "Chef::Environment"
301
- }
302
- EOS
303
- end
304
- before {
305
- allow(File).to receive(:exist?).with(/Berksfile$/).and_return(true)
306
- allow(fake_berks).to receive(:list).and_return([
307
- double('Dependency', :name => 'cookbook1', :locked_version => Semverse::Version.new('1.1.1')),
308
- double('Dependency', :name => 'cookbook2', :locked_version => Semverse::Version.new('2.2.2')),
309
- double('Dependency', :name => 'cookbook3', :locked_version => Semverse::Version.new('3.3.3'))
310
- ])
311
- }
312
- it "writes the cookbook constraints to the file" do
313
- expect(fake_file).to receive(:<<).with(an_instance_of(String)) do |arg|
314
- parsed = JSON.parse(arg)
315
- expect(parsed['cookbook_versions']['cookbook1']).to eq('1.1.1')
316
- expect(parsed['cookbook_versions']['cookbook2']).to eq('2.2.2')
317
- expect(parsed['cookbook_versions']['cookbook3']).to eq('3.3.3')
318
- end
319
- subject.constrain_environment('test', 'test_cookbook')
320
- end
321
- end
322
-
323
- context 'is_dirty' do
324
- before {
325
- regex = File.join(config.environment_directory,'test.json')
326
- allow(File).to receive(:read).with(regex).and_return(artifact_file)
327
- allow(File).to receive(:open).with(regex, "w").and_yield(fake_file)
328
- allow(File).to receive(:read).with(/new.json/).and_return(
329
- <<-EOS
330
- {
331
- "name": "test",
332
- "chef_type": "environment",
333
- "json_class": "Chef::Environment",
334
- "cookbook_versions": {
335
- "cookbook1": "1.1.1",
336
- "cookbook2": "2.2.2",
337
- "cookbook3": "3.3.3"
338
- }
339
- }
340
- EOS
341
- )
342
- }
343
-
344
- context "cookbook is dirty" do
345
-
346
- let(:artifact_file) do
347
- <<-EOS
348
- {
349
- "name": "LKG",
350
- "chef_type": "environment",
351
- "json_class": "Chef::Environment",
352
- "cookbook_versions": {
353
- "cookbook1": "1.1.1.hash",
354
- "cookbook2": "1.1.1.hash",
355
- "cookbook3": "3.3.3.hash"
356
- }
357
- }
358
- EOS
359
- end
360
-
361
- it "returns dirty" do
362
- expect(subject.is_dirty('new', 'test', 'cookbook2', 'hash')).to be(true)
363
- end
364
- end
365
- context "cookbook has same version but different hash" do
366
-
367
- let(:artifact_file) do
368
- <<-EOS
369
- {
370
- "name": "LKG",
371
- "chef_type": "environment",
372
- "json_class": "Chef::Environment",
373
- "cookbook_versions": {
374
- "cookbook1": "1.1.1.hash",
375
- "cookbook2": "2.2.2.diff_hash",
376
- "cookbook3": "3.3.3.hash"
377
- }
378
- }
379
- EOS
380
- end
381
-
382
- it "returns dirty" do
383
- expect(subject.is_dirty('new', 'test', 'cookbook2', 'hash')).to be(true)
384
- end
385
- end
386
- context "cookbook is not dirty" do
387
- let(:artifact_file) do
388
- <<-EOS
389
- {
390
- "name": "LKG",
391
- "chef_type": "environment",
392
- "json_class": "Chef::Environment",
393
- "cookbook_versions": {
394
- "cookbook1": "1.1.1.hash",
395
- "cookbook2": "2.2.2.hash",
396
- "cookbook3": "3.3.3.hash"
397
- }
398
- }
399
- EOS
400
- end
401
-
402
- it "returns clean" do
403
- expect(subject.is_dirty('new', 'test', 'cookbook2', 'hash')).to be(false)
404
- end
405
- end
406
- context "cookbook is new to environment" do
407
- let(:artifact_file) do
408
- <<-EOS
409
- {
410
- "name": "LKG",
411
- "chef_type": "environment",
412
- "json_class": "Chef::Environment",
413
- "cookbook_versions": {
414
- "cookbook1": "1.1.1.hash",
415
- "cookbook3": "3.3.3.hash"
416
- }
417
- }
418
- EOS
419
- end
420
-
421
- it "returns dirty" do
422
- expect(subject.is_dirty('new', 'test', 'cookbook2', 'hash')).to be(true)
423
- end
424
- end
425
- end
300
+ context 'constrain_environment' do
301
+ before do
302
+ regex = File.join(config.environment_directory, 'test.json')
303
+ allow(File).to receive(:read).with(regex).and_return(artifact_file)
304
+ allow(File).to receive(:open).with(regex, 'w').and_yield(fake_file)
305
+ end
306
+
307
+ let(:artifact_file) do
308
+ <<-EOS
309
+ {
310
+ "name": "QA1",
311
+ "chef_type": "environment",
312
+ "json_class": "Chef::Environment"
313
+ }
314
+ EOS
315
+ end
316
+ before do
317
+ allow(File).to receive(:exist?).with(/Berksfile$/).and_return(true)
318
+ allow(fake_berks).to receive(:list).and_return([
319
+ double(
320
+ 'Dependency',
321
+ name: 'cookbook1',
322
+ locked_version: Semverse::Version.new('1.1.1')
323
+ ),
324
+ double(
325
+ 'Dependency',
326
+ name: 'cookbook2',
327
+ locked_version: Semverse::Version.new('2.2.2')
328
+ ),
329
+ double(
330
+ 'Dependency',
331
+ name: 'cookbook3',
332
+ locked_version:
333
+ Semverse::Version.new('3.3.3')
334
+ )
335
+ ])
336
+ end
337
+ it 'writes the cookbook constraints to the file' do
338
+ expect(fake_file).to receive(:<<).with(an_instance_of(String)) do |arg|
339
+ parsed = JSON.parse(arg)
340
+ expect(parsed['cookbook_versions']['cookbook1']).to eq('1.1.1')
341
+ expect(parsed['cookbook_versions']['cookbook2']).to eq('2.2.2')
342
+ expect(parsed['cookbook_versions']['cookbook3']).to eq('3.3.3')
343
+ end
344
+ subject.constrain_environment('test', 'test_cookbook')
345
+ end
346
+ end
347
+
348
+ context 'is_dirty' do
349
+ before do
350
+ regex = File.join(config.environment_directory, 'test.json')
351
+ allow(File).to receive(:read).with(regex).and_return(artifact_file)
352
+ allow(File).to receive(:open).with(regex, 'w').and_yield(fake_file)
353
+ allow(File).to receive(:read).with(/new.json/).and_return(
354
+ <<-EOS
355
+ {
356
+ "name": "test",
357
+ "chef_type": "environment",
358
+ "json_class": "Chef::Environment",
359
+ "cookbook_versions": {
360
+ "cookbook1": "1.1.1",
361
+ "cookbook2": "2.2.2",
362
+ "cookbook3": "3.3.3"
363
+ }
364
+ }
365
+ EOS
366
+ )
367
+ end
368
+
369
+ context 'cookbook is dirty' do
370
+ let(:artifact_file) do
371
+ <<-EOS
372
+ {
373
+ "name": "LKG",
374
+ "chef_type": "environment",
375
+ "json_class": "Chef::Environment",
376
+ "cookbook_versions": {
377
+ "cookbook1": "1.1.1.hash",
378
+ "cookbook2": "1.1.1.hash",
379
+ "cookbook3": "3.3.3.hash"
380
+ }
381
+ }
382
+ EOS
383
+ end
384
+
385
+ it 'returns dirty' do
386
+ expect(subject.is_dirty('new', 'test', 'cookbook2', 'hash')).to be(true)
387
+ end
388
+ end
389
+ context 'cookbook has same version but different hash' do
390
+ let(:artifact_file) do
391
+ <<-EOS
392
+ {
393
+ "name": "LKG",
394
+ "chef_type": "environment",
395
+ "json_class": "Chef::Environment",
396
+ "cookbook_versions": {
397
+ "cookbook1": "1.1.1.hash",
398
+ "cookbook2": "2.2.2.diff_hash",
399
+ "cookbook3": "3.3.3.hash"
400
+ }
401
+ }
402
+ EOS
403
+ end
404
+
405
+ it 'returns dirty' do
406
+ expect(subject.is_dirty('new', 'test', 'cookbook2', 'hash')).to be true
407
+ end
408
+ end
409
+ context 'cookbook is not dirty' do
410
+ let(:artifact_file) do
411
+ <<-EOS
412
+ {
413
+ "name": "LKG",
414
+ "chef_type": "environment",
415
+ "json_class": "Chef::Environment",
416
+ "cookbook_versions": {
417
+ "cookbook1": "1.1.1.hash",
418
+ "cookbook2": "2.2.2.hash",
419
+ "cookbook3": "3.3.3.hash"
420
+ }
421
+ }
422
+ EOS
423
+ end
424
+
425
+ it 'returns clean' do
426
+ expect(subject.is_dirty('new', 'test', 'cookbook2', 'hash')).to be false
427
+ end
428
+ end
429
+ context 'cookbook is new to environment' do
430
+ let(:artifact_file) do
431
+ <<-EOS
432
+ {
433
+ "name": "LKG",
434
+ "chef_type": "environment",
435
+ "json_class": "Chef::Environment",
436
+ "cookbook_versions": {
437
+ "cookbook1": "1.1.1.hash",
438
+ "cookbook3": "3.3.3.hash"
439
+ }
440
+ }
441
+ EOS
442
+ end
443
+
444
+ it 'returns dirty' do
445
+ expect(subject.is_dirty('new', 'test', 'cookbook2', 'hash')).to be true
446
+ end
447
+ end
448
+ end
426
449
  end