knife-essentials 0.9.2 → 0.9.3

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.
@@ -6,26 +6,27 @@ describe 'knife download' do
6
6
  extend IntegrationSupport
7
7
  include KnifeSupport
8
8
 
9
- when_the_chef_server "has one of each thing" do
10
- client 'x', '{}'
11
- cookbook 'x', '1.0.0', { 'metadata.rb' => 'version "1.0.0"' }
12
- data_bag 'x', { 'y' => '{}' }
13
- environment 'x', '{}'
14
- node 'x', '{}'
15
- role 'x', '{}'
16
- user 'x', '{}'
17
-
18
- when_the_repository 'has only top-level directories' do
19
- directory 'clients'
20
- directory 'cookbooks'
21
- directory 'data_bags'
22
- directory 'environments'
23
- directory 'nodes'
24
- directory 'roles'
25
- directory 'users'
26
-
27
- it 'knife download downloads everything' do
28
- knife('download /').should_succeed <<EOM
9
+ context 'without versioned cookbooks' do
10
+ when_the_chef_server "has one of each thing" do
11
+ client 'x', '{}'
12
+ cookbook 'x', '1.0.0', { 'metadata.rb' => 'version "1.0.0"' }
13
+ data_bag 'x', { 'y' => '{}' }
14
+ environment 'x', '{}'
15
+ node 'x', '{}'
16
+ role 'x', '{}'
17
+ user 'x', '{}'
18
+
19
+ when_the_repository 'has only top-level directories' do
20
+ directory 'clients'
21
+ directory 'cookbooks'
22
+ directory 'data_bags'
23
+ directory 'environments'
24
+ directory 'nodes'
25
+ directory 'roles'
26
+ directory 'users'
27
+
28
+ it 'knife download downloads everything' do
29
+ knife('download /').should_succeed <<EOM
29
30
  Created /cookbooks/x
30
31
  Created /cookbooks/x/metadata.rb
31
32
  Created /data_bags/x
@@ -34,21 +35,21 @@ Created /environments/_default.json
34
35
  Created /environments/x.json
35
36
  Created /roles/x.json
36
37
  EOM
37
- knife('diff --name-status /').should_succeed ''
38
+ knife('diff --name-status /').should_succeed ''
39
+ end
38
40
  end
39
- end
40
41
 
41
- when_the_repository 'has an identical copy of each thing' do
42
- file 'clients/x.json', <<EOM
42
+ when_the_repository 'has an identical copy of each thing' do
43
+ file 'clients/x.json', <<EOM
43
44
  {}
44
45
  EOM
45
- file 'cookbooks/x/metadata.rb', 'version "1.0.0"'
46
- file 'data_bags/x/y.json', <<EOM
46
+ file 'cookbooks/x/metadata.rb', 'version "1.0.0"'
47
+ file 'data_bags/x/y.json', <<EOM
47
48
  {
48
49
  "id": "y"
49
50
  }
50
51
  EOM
51
- file 'environments/_default.json', <<EOM
52
+ file 'environments/_default.json', <<EOM
52
53
  {
53
54
  "name": "_default",
54
55
  "description": "The default Chef environment",
@@ -62,7 +63,7 @@ EOM
62
63
  }
63
64
  }
64
65
  EOM
65
- file 'environments/x.json', <<EOM
66
+ file 'environments/x.json', <<EOM
66
67
  {
67
68
  "chef_type": "environment",
68
69
  "cookbook_versions": {
@@ -76,10 +77,10 @@ EOM
76
77
  }
77
78
  }
78
79
  EOM
79
- file 'nodes/x.json', <<EOM
80
+ file 'nodes/x.json', <<EOM
80
81
  {}
81
82
  EOM
82
- file 'roles/x.json', <<EOM
83
+ file 'roles/x.json', <<EOM
83
84
  {
84
85
  "chef_type": "role",
85
86
  "default_attributes": {
@@ -96,22 +97,22 @@ EOM
96
97
  ]
97
98
  }
98
99
  EOM
99
- file 'users/x.json', <<EOM
100
+ file 'users/x.json', <<EOM
100
101
  {}
101
102
  EOM
102
103
 
103
- it 'knife download makes no changes' do
104
- knife('download /').should_succeed ''
105
- knife('diff --name-status /').should_succeed ''
106
- end
104
+ it 'knife download makes no changes' do
105
+ knife('download /').should_succeed ''
106
+ knife('diff --name-status /').should_succeed ''
107
+ end
107
108
 
108
- it 'knife download --purge makes no changes' do
109
- knife('download --purge /').should_succeed ''
110
- knife('diff --name-status /').should_succeed ''
111
- end
109
+ it 'knife download --purge makes no changes' do
110
+ knife('download --purge /').should_succeed ''
111
+ knife('diff --name-status /').should_succeed ''
112
+ end
112
113
 
113
- context 'except the role file' do
114
- file 'roles/x.json', <<EOM
114
+ context 'except the role file' do
115
+ file 'roles/x.json', <<EOM
115
116
  {
116
117
  "chef_type": "role",
117
118
  "default_attributes": {
@@ -128,14 +129,14 @@ EOM
128
129
  ]
129
130
  }
130
131
  EOM
131
- it 'knife download changes the role' do
132
- knife('download /').should_succeed "Updated /roles/x.json\n"
133
- knife('diff --name-status /').should_succeed ''
132
+ it 'knife download changes the role' do
133
+ knife('download /').should_succeed "Updated /roles/x.json\n"
134
+ knife('diff --name-status /').should_succeed ''
135
+ end
134
136
  end
135
- end
136
137
 
137
- context 'except the role file is textually different, but not ACTUALLY different' do
138
- file 'roles/x.json', <<EOM
138
+ context 'except the role file is textually different, but not ACTUALLY different' do
139
+ file 'roles/x.json', <<EOM
139
140
  {
140
141
  "chef_type": "role",
141
142
  "default_attributes": {
@@ -152,27 +153,27 @@ EOM
152
153
  ]
153
154
  }
154
155
  EOM
155
- it 'knife download / does not change anything' do
156
- knife('download /').should_succeed ''
157
- knife('diff --name-status /').should_succeed ''
156
+ it 'knife download / does not change anything' do
157
+ knife('download /').should_succeed ''
158
+ knife('diff --name-status /').should_succeed ''
159
+ end
158
160
  end
159
- end
160
161
 
161
- context 'as well as one extra copy of each thing' do
162
- file 'clients/y.json', { 'name' => 'y' }
163
- file 'cookbooks/x/blah.rb', ''
164
- file 'cookbooks/y/metadata.rb', 'version "1.0.0"'
165
- file 'data_bags/x/z.json', <<EOM
162
+ context 'as well as one extra copy of each thing' do
163
+ file 'clients/y.json', { 'name' => 'y' }
164
+ file 'cookbooks/x/blah.rb', ''
165
+ file 'cookbooks/y/metadata.rb', 'version "1.0.0"'
166
+ file 'data_bags/x/z.json', <<EOM
166
167
  {
167
168
  "id": "z"
168
169
  }
169
170
  EOM
170
- file 'data_bags/y/zz.json', <<EOM
171
+ file 'data_bags/y/zz.json', <<EOM
171
172
  {
172
173
  "id": "zz"
173
174
  }
174
175
  EOM
175
- file 'environments/y.json', <<EOM
176
+ file 'environments/y.json', <<EOM
176
177
  {
177
178
  "chef_type": "environment",
178
179
  "cookbook_versions": {
@@ -186,8 +187,8 @@ EOM
186
187
  }
187
188
  }
188
189
  EOM
189
- file 'nodes/y.json', { 'name' => 'y' }
190
- file 'roles/y.json', <<EOM
190
+ file 'nodes/y.json', { 'name' => 'y' }
191
+ file 'roles/y.json', <<EOM
191
192
  {
192
193
  "chef_type": "role",
193
194
  "default_attributes": {
@@ -204,11 +205,11 @@ EOM
204
205
  ]
205
206
  }
206
207
  EOM
207
- file 'users/y.json', { 'name' => 'y' }
208
+ file 'users/y.json', { 'name' => 'y' }
208
209
 
209
- it 'knife download does nothing' do
210
- knife('download /').should_succeed ''
211
- knife('diff --name-status /').should_succeed <<EOM
210
+ it 'knife download does nothing' do
211
+ knife('download /').should_succeed ''
212
+ knife('diff --name-status /').should_succeed <<EOM
212
213
  A\t/cookbooks/x/blah.rb
213
214
  A\t/cookbooks/y
214
215
  A\t/data_bags/x/z.json
@@ -216,10 +217,10 @@ A\t/data_bags/y
216
217
  A\t/environments/y.json
217
218
  A\t/roles/y.json
218
219
  EOM
219
- end
220
+ end
220
221
 
221
- it 'knife download --purge deletes the extra files' do
222
- knife('download --purge /').should_succeed <<EOM
222
+ it 'knife download --purge deletes the extra files' do
223
+ knife('download --purge /').should_succeed <<EOM
223
224
  Deleted extra entry /cookbooks/x/blah.rb (purge is on)
224
225
  Deleted extra entry /cookbooks/y (purge is on)
225
226
  Deleted extra entry /data_bags/x/z.json (purge is on)
@@ -227,14 +228,14 @@ Deleted extra entry /data_bags/y (purge is on)
227
228
  Deleted extra entry /environments/y.json (purge is on)
228
229
  Deleted extra entry /roles/y.json (purge is on)
229
230
  EOM
230
- knife('diff --name-status /').should_succeed ''
231
+ knife('diff --name-status /').should_succeed ''
232
+ end
231
233
  end
232
234
  end
233
- end
234
235
 
235
- when_the_repository 'is empty' do
236
- it 'knife download creates the extra files' do
237
- knife('download /').should_succeed <<EOM
236
+ when_the_repository 'is empty' do
237
+ it 'knife download creates the extra files' do
238
+ knife('download /').should_succeed <<EOM
238
239
  Created /cookbooks
239
240
  Created /cookbooks/x
240
241
  Created /cookbooks/x/metadata.rb
@@ -247,37 +248,37 @@ Created /environments/x.json
247
248
  Created /roles
248
249
  Created /roles/x.json
249
250
  EOM
250
- knife('diff --name-status /').should_succeed ''
251
- end
251
+ knife('diff --name-status /').should_succeed ''
252
+ end
252
253
 
253
- context 'when current directory is top level' do
254
- cwd '.'
255
- it 'knife download with no parameters reports an error' do
256
- knife('download').should_fail "FATAL: Must specify at least one argument. If you want to download everything in this directory, type \"knife download .\"\n", :stdout => /USAGE/
254
+ context 'when current directory is top level' do
255
+ cwd '.'
256
+ it 'knife download with no parameters reports an error' do
257
+ knife('download').should_fail "FATAL: Must specify at least one argument. If you want to download everything in this directory, type \"knife download .\"\n", :stdout => /USAGE/
258
+ end
257
259
  end
258
260
  end
259
261
  end
260
- end
261
262
 
262
- # Test download of an item when the other end doesn't even have the container
263
- when_the_repository 'is empty' do
264
- when_the_chef_server 'has two data bag items' do
265
- data_bag 'x', { 'y' => {}, 'z' => {} }
263
+ # Test download of an item when the other end doesn't even have the container
264
+ when_the_repository 'is empty' do
265
+ when_the_chef_server 'has two data bag items' do
266
+ data_bag 'x', { 'y' => {}, 'z' => {} }
266
267
 
267
- it 'knife download of one data bag item itself succeeds' do
268
- knife('download /data_bags/x/y.json').should_succeed <<EOM
268
+ it 'knife download of one data bag item itself succeeds' do
269
+ knife('download /data_bags/x/y.json').should_succeed <<EOM
269
270
  Created /data_bags
270
271
  Created /data_bags/x
271
272
  Created /data_bags/x/y.json
272
273
  EOM
273
- knife('diff --name-status /data_bags').should_succeed <<EOM
274
+ knife('diff --name-status /data_bags').should_succeed <<EOM
274
275
  D\t/data_bags/x/z.json
275
276
  EOM
277
+ end
276
278
  end
277
279
  end
278
- end
279
280
 
280
- when_the_repository 'has three data bag items' do
281
+ when_the_repository 'has three data bag items' do
281
282
  file 'data_bags/x/deleted.json', <<EOM
282
283
  {
283
284
  "id": "deleted"
@@ -294,234 +295,765 @@ EOM
294
295
  }
295
296
  EOM
296
297
 
297
- when_the_chef_server 'has a modified, unmodified, added and deleted data bag item' do
298
- data_bag 'x', {
299
- 'added' => {},
300
- 'modified' => { 'foo' => 'bar' },
301
- 'unmodified' => {}
302
- }
298
+ when_the_chef_server 'has a modified, unmodified, added and deleted data bag item' do
299
+ data_bag 'x', {
300
+ 'added' => {},
301
+ 'modified' => { 'foo' => 'bar' },
302
+ 'unmodified' => {}
303
+ }
303
304
 
304
- it 'knife download of the modified file succeeds' do
305
- knife('download /data_bags/x/modified.json').should_succeed <<EOM
305
+ it 'knife download of the modified file succeeds' do
306
+ knife('download /data_bags/x/modified.json').should_succeed <<EOM
306
307
  Updated /data_bags/x/modified.json
307
308
  EOM
308
- knife('diff --name-status /data_bags').should_succeed <<EOM
309
+ knife('diff --name-status /data_bags').should_succeed <<EOM
309
310
  D\t/data_bags/x/added.json
310
311
  A\t/data_bags/x/deleted.json
311
312
  EOM
312
- end
313
- it 'knife download of the unmodified file does nothing' do
314
- knife('download /data_bags/x/unmodified.json').should_succeed ''
315
- knife('diff --name-status /data_bags').should_succeed <<EOM
313
+ end
314
+ it 'knife download of the unmodified file does nothing' do
315
+ knife('download /data_bags/x/unmodified.json').should_succeed ''
316
+ knife('diff --name-status /data_bags').should_succeed <<EOM
316
317
  D\t/data_bags/x/added.json
317
318
  M\t/data_bags/x/modified.json
318
319
  A\t/data_bags/x/deleted.json
319
320
  EOM
320
- end
321
- it 'knife download of the added file succeeds' do
322
- knife('download /data_bags/x/added.json').should_succeed <<EOM
321
+ end
322
+ it 'knife download of the added file succeeds' do
323
+ knife('download /data_bags/x/added.json').should_succeed <<EOM
323
324
  Created /data_bags/x/added.json
324
325
  EOM
325
- knife('diff --name-status /data_bags').should_succeed <<EOM
326
+ knife('diff --name-status /data_bags').should_succeed <<EOM
326
327
  M\t/data_bags/x/modified.json
327
328
  A\t/data_bags/x/deleted.json
328
329
  EOM
329
- end
330
- it 'knife download of the deleted file does nothing' do
331
- knife('download /data_bags/x/deleted.json').should_succeed ''
332
- knife('diff --name-status /data_bags').should_succeed <<EOM
330
+ end
331
+ it 'knife download of the deleted file does nothing' do
332
+ knife('download /data_bags/x/deleted.json').should_succeed ''
333
+ knife('diff --name-status /data_bags').should_succeed <<EOM
333
334
  D\t/data_bags/x/added.json
334
335
  M\t/data_bags/x/modified.json
335
336
  A\t/data_bags/x/deleted.json
336
337
  EOM
337
- end
338
- it 'knife download --purge of the deleted file deletes it' do
339
- knife('download --purge /data_bags/x/deleted.json').should_succeed <<EOM
338
+ end
339
+ it 'knife download --purge of the deleted file deletes it' do
340
+ knife('download --purge /data_bags/x/deleted.json').should_succeed <<EOM
340
341
  Deleted extra entry /data_bags/x/deleted.json (purge is on)
341
342
  EOM
342
- knife('diff --name-status /data_bags').should_succeed <<EOM
343
+ knife('diff --name-status /data_bags').should_succeed <<EOM
343
344
  D\t/data_bags/x/added.json
344
345
  M\t/data_bags/x/modified.json
345
346
  EOM
346
- end
347
- it 'knife download of the entire data bag downloads everything' do
348
- knife('download /data_bags/x').should_succeed <<EOM
347
+ end
348
+ it 'knife download of the entire data bag downloads everything' do
349
+ knife('download /data_bags/x').should_succeed <<EOM
349
350
  Created /data_bags/x/added.json
350
351
  Updated /data_bags/x/modified.json
351
352
  EOM
352
- knife('diff --name-status /data_bags').should_succeed <<EOM
353
+ knife('diff --name-status /data_bags').should_succeed <<EOM
353
354
  A\t/data_bags/x/deleted.json
354
355
  EOM
355
- end
356
- it 'knife download --purge of the entire data bag downloads everything' do
357
- knife('download --purge /data_bags/x').should_succeed <<EOM
356
+ end
357
+ it 'knife download --purge of the entire data bag downloads everything' do
358
+ knife('download --purge /data_bags/x').should_succeed <<EOM
358
359
  Created /data_bags/x/added.json
359
360
  Updated /data_bags/x/modified.json
360
361
  Deleted extra entry /data_bags/x/deleted.json (purge is on)
361
362
  EOM
362
- knife('diff --name-status /data_bags').should_succeed ''
363
- end
364
- context 'when cwd is the /data_bags directory' do
365
- cwd 'data_bags'
366
- it 'knife download fails' do
367
- knife('download').should_fail "FATAL: Must specify at least one argument. If you want to download everything in this directory, type \"knife download .\"\n", :stdout => /USAGE/
363
+ knife('diff --name-status /data_bags').should_succeed ''
368
364
  end
369
- it 'knife download --purge . downloads everything' do
370
- knife('download --purge .').should_succeed <<EOM
365
+ context 'when cwd is the /data_bags directory' do
366
+ cwd 'data_bags'
367
+ it 'knife download fails' do
368
+ knife('download').should_fail "FATAL: Must specify at least one argument. If you want to download everything in this directory, type \"knife download .\"\n", :stdout => /USAGE/
369
+ end
370
+ it 'knife download --purge . downloads everything' do
371
+ knife('download --purge .').should_succeed <<EOM
371
372
  Created x/added.json
372
373
  Updated x/modified.json
373
374
  Deleted extra entry x/deleted.json (purge is on)
374
375
  EOM
375
- knife('diff --name-status /data_bags').should_succeed ''
376
- end
377
- it 'knife download --purge * downloads everything' do
378
- knife('download --purge *').should_succeed <<EOM
376
+ knife('diff --name-status /data_bags').should_succeed ''
377
+ end
378
+ it 'knife download --purge * downloads everything' do
379
+ knife('download --purge *').should_succeed <<EOM
379
380
  Created x/added.json
380
381
  Updated x/modified.json
381
382
  Deleted extra entry x/deleted.json (purge is on)
382
383
  EOM
383
- knife('diff --name-status /data_bags').should_succeed ''
384
+ knife('diff --name-status /data_bags').should_succeed ''
385
+ end
384
386
  end
385
387
  end
386
388
  end
387
- end
388
389
 
389
- when_the_repository 'has a cookbook' do
390
- file 'cookbooks/x/metadata.rb', 'version "1.0.0"'
391
- file 'cookbooks/x/z.rb', ''
390
+ when_the_repository 'has a cookbook' do
391
+ file 'cookbooks/x/metadata.rb', 'version "1.0.0"'
392
+ file 'cookbooks/x/z.rb', ''
392
393
 
393
- when_the_chef_server 'has a modified, added and deleted file for the cookbook' do
394
- cookbook 'x', '1.0.0', { 'metadata.rb' => 'version "1.0.0"', 'y.rb' => 'hi' }
394
+ when_the_chef_server 'has a modified, added and deleted file for the cookbook' do
395
+ cookbook 'x', '1.0.0', { 'metadata.rb' => 'version "1.0.0"', 'y.rb' => 'hi' }
395
396
 
396
- it 'knife download of a modified file succeeds' do
397
- knife('download /cookbooks/x/metadata.rb').should_succeed "Updated /cookbooks/x/metadata.rb\n"
398
- knife('diff --name-status /cookbooks').should_succeed <<EOM
397
+ it 'knife download of a modified file succeeds' do
398
+ knife('download /cookbooks/x/metadata.rb').should_succeed "Updated /cookbooks/x/metadata.rb\n"
399
+ knife('diff --name-status /cookbooks').should_succeed <<EOM
399
400
  D\t/cookbooks/x/y.rb
400
401
  A\t/cookbooks/x/z.rb
401
402
  EOM
402
- end
403
- it 'knife download of a deleted file does nothing' do
404
- knife('download /cookbooks/x/z.rb').should_succeed ''
405
- knife('diff --name-status /cookbooks').should_succeed <<EOM
403
+ end
404
+ it 'knife download of a deleted file does nothing' do
405
+ knife('download /cookbooks/x/z.rb').should_succeed ''
406
+ knife('diff --name-status /cookbooks').should_succeed <<EOM
406
407
  M\t/cookbooks/x/metadata.rb
407
408
  D\t/cookbooks/x/y.rb
408
409
  A\t/cookbooks/x/z.rb
409
410
  EOM
410
- end
411
- it 'knife download --purge of a deleted file succeeds' do
412
- knife('download --purge /cookbooks/x/z.rb').should_succeed "Deleted extra entry /cookbooks/x/z.rb (purge is on)\n"
413
- knife('diff --name-status /cookbooks').should_succeed <<EOM
411
+ end
412
+ it 'knife download --purge of a deleted file succeeds' do
413
+ knife('download --purge /cookbooks/x/z.rb').should_succeed "Deleted extra entry /cookbooks/x/z.rb (purge is on)\n"
414
+ knife('diff --name-status /cookbooks').should_succeed <<EOM
414
415
  M\t/cookbooks/x/metadata.rb
415
416
  D\t/cookbooks/x/y.rb
416
417
  EOM
417
- end
418
- it 'knife download of an added file succeeds' do
419
- knife('download /cookbooks/x/y.rb').should_succeed "Created /cookbooks/x/y.rb\n"
420
- knife('diff --name-status /cookbooks').should_succeed <<EOM
418
+ end
419
+ it 'knife download of an added file succeeds' do
420
+ knife('download /cookbooks/x/y.rb').should_succeed "Created /cookbooks/x/y.rb\n"
421
+ knife('diff --name-status /cookbooks').should_succeed <<EOM
421
422
  M\t/cookbooks/x/metadata.rb
422
423
  A\t/cookbooks/x/z.rb
423
424
  EOM
424
- end
425
- it 'knife download of the cookbook itself succeeds' do
426
- knife('download /cookbooks/x').should_succeed <<EOM
425
+ end
426
+ it 'knife download of the cookbook itself succeeds' do
427
+ knife('download /cookbooks/x').should_succeed <<EOM
427
428
  Updated /cookbooks/x/metadata.rb
428
429
  Created /cookbooks/x/y.rb
429
430
  EOM
430
- knife('diff --name-status /cookbooks').should_succeed <<EOM
431
+ knife('diff --name-status /cookbooks').should_succeed <<EOM
431
432
  A\t/cookbooks/x/z.rb
432
433
  EOM
433
- end
434
- it 'knife download --purge of the cookbook itself succeeds' do
435
- knife('download --purge /cookbooks/x').should_succeed <<EOM
434
+ end
435
+ it 'knife download --purge of the cookbook itself succeeds' do
436
+ knife('download --purge /cookbooks/x').should_succeed <<EOM
436
437
  Updated /cookbooks/x/metadata.rb
437
438
  Created /cookbooks/x/y.rb
438
439
  Deleted extra entry /cookbooks/x/z.rb (purge is on)
439
440
  EOM
440
- knife('diff --name-status /cookbooks').should_succeed ''
441
+ knife('diff --name-status /cookbooks').should_succeed ''
442
+ end
441
443
  end
442
444
  end
443
- end
444
445
 
445
- when_the_repository 'has a cookbook' do
446
- file 'cookbooks/x/metadata.rb', 'version "1.0.0"'
447
- file 'cookbooks/x/onlyin1.0.0.rb', 'old_text'
446
+ when_the_repository 'has a cookbook' do
447
+ file 'cookbooks/x/metadata.rb', 'version "1.0.0"'
448
+ file 'cookbooks/x/onlyin1.0.0.rb', 'old_text'
448
449
 
449
- when_the_chef_server 'has a later version for the cookbook' do
450
- cookbook 'x', '1.0.0', { 'metadata.rb' => 'version "1.0.0"', 'onlyin1.0.0.rb' => '' }
451
- cookbook 'x', '1.0.1', { 'metadata.rb' => 'version "1.0.1"', 'onlyin1.0.1.rb' => 'hi' }
450
+ when_the_chef_server 'has a later version for the cookbook' do
451
+ cookbook 'x', '1.0.0', { 'metadata.rb' => 'version "1.0.0"', 'onlyin1.0.0.rb' => '' }
452
+ cookbook 'x', '1.0.1', { 'metadata.rb' => 'version "1.0.1"', 'onlyin1.0.1.rb' => 'hi' }
452
453
 
453
- it 'knife download /cookbooks/x downloads the latest version' do
454
- knife('download --purge /cookbooks/x').should_succeed <<EOM
454
+ it 'knife download /cookbooks/x downloads the latest version' do
455
+ knife('download --purge /cookbooks/x').should_succeed <<EOM
455
456
  Updated /cookbooks/x/metadata.rb
456
457
  Created /cookbooks/x/onlyin1.0.1.rb
457
458
  Deleted extra entry /cookbooks/x/onlyin1.0.0.rb (purge is on)
458
459
  EOM
459
- knife('diff --name-status /cookbooks').should_succeed ''
460
+ knife('diff --name-status /cookbooks').should_succeed ''
461
+ end
460
462
  end
461
- end
462
463
 
463
- when_the_chef_server 'has an earlier version for the cookbook' do
464
- cookbook 'x', '1.0.0', { 'metadata.rb' => 'version "1.0.0"', 'onlyin1.0.0.rb' => ''}
465
- cookbook 'x', '0.9.9', { 'metadata.rb' => 'version "0.9.9"', 'onlyin0.9.9.rb' => 'hi' }
466
- it 'knife download /cookbooks/x downloads the updated file' do
467
- knife('download --purge /cookbooks/x').should_succeed <<EOM
464
+ when_the_chef_server 'has an earlier version for the cookbook' do
465
+ cookbook 'x', '1.0.0', { 'metadata.rb' => 'version "1.0.0"', 'onlyin1.0.0.rb' => ''}
466
+ cookbook 'x', '0.9.9', { 'metadata.rb' => 'version "0.9.9"', 'onlyin0.9.9.rb' => 'hi' }
467
+ it 'knife download /cookbooks/x downloads the updated file' do
468
+ knife('download --purge /cookbooks/x').should_succeed <<EOM
468
469
  Updated /cookbooks/x/onlyin1.0.0.rb
469
470
  EOM
470
- knife('diff --name-status /cookbooks').should_succeed ''
471
+ knife('diff --name-status /cookbooks').should_succeed ''
472
+ end
471
473
  end
472
- end
473
474
 
474
- when_the_chef_server 'has a later version for the cookbook, and no current version' do
475
- cookbook 'x', '1.0.1', { 'metadata.rb' => 'version "1.0.1"', 'onlyin1.0.1.rb' => 'hi' }
475
+ when_the_chef_server 'has a later version for the cookbook, and no current version' do
476
+ cookbook 'x', '1.0.1', { 'metadata.rb' => 'version "1.0.1"', 'onlyin1.0.1.rb' => 'hi' }
476
477
 
477
- it 'knife download /cookbooks/x downloads the latest version' do
478
- knife('download --purge /cookbooks/x').should_succeed <<EOM
478
+ it 'knife download /cookbooks/x downloads the latest version' do
479
+ knife('download --purge /cookbooks/x').should_succeed <<EOM
479
480
  Updated /cookbooks/x/metadata.rb
480
481
  Created /cookbooks/x/onlyin1.0.1.rb
481
482
  Deleted extra entry /cookbooks/x/onlyin1.0.0.rb (purge is on)
482
483
  EOM
483
- knife('diff --name-status /cookbooks').should_succeed ''
484
+ knife('diff --name-status /cookbooks').should_succeed ''
485
+ end
484
486
  end
485
- end
486
487
 
487
- when_the_chef_server 'has an earlier version for the cookbook, and no current version' do
488
- cookbook 'x', '0.9.9', { 'metadata.rb' => 'version "0.9.9"', 'onlyin0.9.9.rb' => 'hi' }
488
+ when_the_chef_server 'has an earlier version for the cookbook, and no current version' do
489
+ cookbook 'x', '0.9.9', { 'metadata.rb' => 'version "0.9.9"', 'onlyin0.9.9.rb' => 'hi' }
489
490
 
490
- it 'knife download /cookbooks/x downloads the old version' do
491
- knife('download --purge /cookbooks/x').should_succeed <<EOM
491
+ it 'knife download /cookbooks/x downloads the old version' do
492
+ knife('download --purge /cookbooks/x').should_succeed <<EOM
492
493
  Updated /cookbooks/x/metadata.rb
493
494
  Created /cookbooks/x/onlyin0.9.9.rb
494
495
  Deleted extra entry /cookbooks/x/onlyin1.0.0.rb (purge is on)
495
496
  EOM
496
- knife('diff --name-status /cookbooks').should_succeed ''
497
+ knife('diff --name-status /cookbooks').should_succeed ''
498
+ end
499
+ end
500
+ end
501
+
502
+ when_the_chef_server 'has an environment' do
503
+ environment 'x', {}
504
+ when_the_repository 'has an environment with bad JSON' do
505
+ file 'environments/x.json', '{'
506
+ it 'knife download succeeds' do
507
+ knife('download /environments/x.json').should_succeed "Updated /environments/x.json\n", :stderr => "WARN: Parse error reading #{path_to('environments/x.json')} as JSON: A JSON text must at least contain two octets!\n"
508
+ knife('diff --name-status /environments/x.json').should_succeed ''
509
+ end
510
+ end
511
+
512
+ when_the_repository 'has the same environment with the wrong name in the file' do
513
+ file 'environments/x.json', { 'name' => 'y' }
514
+ it 'knife download succeeds' do
515
+ knife('download /environments/x.json').should_succeed "Updated /environments/x.json\n"
516
+ knife('diff --name-status /environments/x.json').should_succeed ''
517
+ end
518
+ end
519
+
520
+ when_the_repository 'has the same environment with no name in the file' do
521
+ file 'environments/x.json', { 'description' => 'hi' }
522
+ it 'knife download succeeds' do
523
+ knife('download /environments/x.json').should_succeed "Updated /environments/x.json\n"
524
+ knife('diff --name-status /environments/x.json').should_succeed ''
525
+ end
526
+ end
527
+ end
528
+ end # without versioned cookbooks
529
+
530
+ with_versioned_cookbooks do
531
+ when_the_chef_server "has one of each thing" do
532
+ client 'x', '{}'
533
+ cookbook 'x', '1.0.0', { 'metadata.rb' => 'version "1.0.0"' }
534
+ data_bag 'x', { 'y' => '{}' }
535
+ environment 'x', '{}'
536
+ node 'x', '{}'
537
+ role 'x', '{}'
538
+ user 'x', '{}'
539
+
540
+ when_the_repository 'has only top-level directories' do
541
+ directory 'clients'
542
+ directory 'cookbooks'
543
+ directory 'data_bags'
544
+ directory 'environments'
545
+ directory 'nodes'
546
+ directory 'roles'
547
+ directory 'users'
548
+
549
+ it 'knife download downloads everything' do
550
+ knife('download /').should_succeed <<EOM
551
+ Created /cookbooks/x-1.0.0
552
+ Created /cookbooks/x-1.0.0/metadata.rb
553
+ Created /data_bags/x
554
+ Created /data_bags/x/y.json
555
+ Created /environments/_default.json
556
+ Created /environments/x.json
557
+ Created /roles/x.json
558
+ EOM
559
+ knife('diff --name-status /').should_succeed ''
560
+ end
561
+ end
562
+
563
+ when_the_repository 'has an identical copy of each thing' do
564
+ file 'clients/x.json', <<EOM
565
+ {}
566
+ EOM
567
+ file 'cookbooks/x-1.0.0/metadata.rb', 'version "1.0.0"'
568
+ file 'data_bags/x/y.json', <<EOM
569
+ {
570
+ "id": "y"
571
+ }
572
+ EOM
573
+ file 'environments/_default.json', <<EOM
574
+ {
575
+ "name": "_default",
576
+ "description": "The default Chef environment",
577
+ "cookbook_versions": {
578
+ },
579
+ "json_class": "Chef::Environment",
580
+ "chef_type": "environment",
581
+ "default_attributes": {
582
+ },
583
+ "override_attributes": {
584
+ }
585
+ }
586
+ EOM
587
+ file 'environments/x.json', <<EOM
588
+ {
589
+ "chef_type": "environment",
590
+ "cookbook_versions": {
591
+ },
592
+ "default_attributes": {
593
+ },
594
+ "description": "",
595
+ "json_class": "Chef::Environment",
596
+ "name": "x",
597
+ "override_attributes": {
598
+ }
599
+ }
600
+ EOM
601
+ file 'nodes/x.json', <<EOM
602
+ {}
603
+ EOM
604
+ file 'roles/x.json', <<EOM
605
+ {
606
+ "chef_type": "role",
607
+ "default_attributes": {
608
+ },
609
+ "description": "",
610
+ "env_run_lists": {
611
+ },
612
+ "json_class": "Chef::Role",
613
+ "name": "x",
614
+ "override_attributes": {
615
+ },
616
+ "run_list": [
617
+
618
+ ]
619
+ }
620
+ EOM
621
+ file 'users/x.json', <<EOM
622
+ {}
623
+ EOM
624
+
625
+ it 'knife download makes no changes' do
626
+ knife('download /').should_succeed ''
627
+ knife('diff --name-status /').should_succeed ''
628
+ end
629
+
630
+ it 'knife download --purge makes no changes' do
631
+ knife('download --purge /').should_succeed ''
632
+ knife('diff --name-status /').should_succeed ''
633
+ end
634
+
635
+ context 'except the role file' do
636
+ file 'roles/x.json', <<EOM
637
+ {
638
+ "chef_type": "role",
639
+ "default_attributes": {
640
+ },
641
+ "description": "blarghle",
642
+ "env_run_lists": {
643
+ },
644
+ "json_class": "Chef::Role",
645
+ "name": "x",
646
+ "override_attributes": {
647
+ },
648
+ "run_list": [
649
+
650
+ ]
651
+ }
652
+ EOM
653
+ it 'knife download changes the role' do
654
+ knife('download /').should_succeed "Updated /roles/x.json\n"
655
+ knife('diff --name-status /').should_succeed ''
656
+ end
657
+ end
658
+
659
+ context 'except the role file is textually different, but not ACTUALLY different' do
660
+ file 'roles/x.json', <<EOM
661
+ {
662
+ "chef_type": "role",
663
+ "default_attributes": {
664
+ },
665
+ "env_run_lists": {
666
+ },
667
+ "json_class": "Chef::Role",
668
+ "name": "x",
669
+ "description": "",
670
+ "override_attributes": {
671
+ },
672
+ "run_list": [
673
+
674
+ ]
675
+ }
676
+ EOM
677
+ it 'knife download / does not change anything' do
678
+ knife('download /').should_succeed ''
679
+ knife('diff --name-status /').should_succeed ''
680
+ end
681
+ end
682
+
683
+ context 'as well as one extra copy of each thing' do
684
+ file 'clients/y.json', { 'name' => 'y' }
685
+ file 'cookbooks/x-1.0.0/blah.rb', ''
686
+ file 'cookbooks/x-2.0.0/metadata.rb', 'version "2.0.0"'
687
+ file 'cookbooks/y-1.0.0/metadata.rb', 'version "1.0.0"'
688
+ file 'data_bags/x/z.json', <<EOM
689
+ {
690
+ "id": "z"
691
+ }
692
+ EOM
693
+ file 'data_bags/y/zz.json', <<EOM
694
+ {
695
+ "id": "zz"
696
+ }
697
+ EOM
698
+ file 'environments/y.json', <<EOM
699
+ {
700
+ "chef_type": "environment",
701
+ "cookbook_versions": {
702
+ },
703
+ "default_attributes": {
704
+ },
705
+ "description": "",
706
+ "json_class": "Chef::Environment",
707
+ "name": "y",
708
+ "override_attributes": {
709
+ }
710
+ }
711
+ EOM
712
+ file 'nodes/y.json', { 'name' => 'y' }
713
+ file 'roles/y.json', <<EOM
714
+ {
715
+ "chef_type": "role",
716
+ "default_attributes": {
717
+ },
718
+ "description": "",
719
+ "env_run_lists": {
720
+ },
721
+ "json_class": "Chef::Role",
722
+ "name": "y",
723
+ "override_attributes": {
724
+ },
725
+ "run_list": [
726
+
727
+ ]
728
+ }
729
+ EOM
730
+ file 'users/y.json', { 'name' => 'y' }
731
+
732
+ it 'knife download does nothing' do
733
+ knife('download /').should_succeed ''
734
+ knife('diff --name-status /').should_succeed <<EOM
735
+ A\t/cookbooks/x-1.0.0/blah.rb
736
+ A\t/cookbooks/x-2.0.0
737
+ A\t/cookbooks/y-1.0.0
738
+ A\t/data_bags/x/z.json
739
+ A\t/data_bags/y
740
+ A\t/environments/y.json
741
+ A\t/roles/y.json
742
+ EOM
743
+ end
744
+
745
+ it 'knife download --purge deletes the extra files' do
746
+ knife('download --purge /').should_succeed <<EOM
747
+ Deleted extra entry /cookbooks/x-1.0.0/blah.rb (purge is on)
748
+ Deleted extra entry /cookbooks/x-2.0.0 (purge is on)
749
+ Deleted extra entry /cookbooks/y-1.0.0 (purge is on)
750
+ Deleted extra entry /data_bags/x/z.json (purge is on)
751
+ Deleted extra entry /data_bags/y (purge is on)
752
+ Deleted extra entry /environments/y.json (purge is on)
753
+ Deleted extra entry /roles/y.json (purge is on)
754
+ EOM
755
+ knife('diff --name-status /').should_succeed ''
756
+ end
757
+ end
758
+ end
759
+
760
+ when_the_repository 'is empty' do
761
+ it 'knife download creates the extra files' do
762
+ knife('download /').should_succeed <<EOM
763
+ Created /cookbooks
764
+ Created /cookbooks/x-1.0.0
765
+ Created /cookbooks/x-1.0.0/metadata.rb
766
+ Created /data_bags
767
+ Created /data_bags/x
768
+ Created /data_bags/x/y.json
769
+ Created /environments
770
+ Created /environments/_default.json
771
+ Created /environments/x.json
772
+ Created /roles
773
+ Created /roles/x.json
774
+ EOM
775
+ knife('diff --name-status /').should_succeed ''
776
+ end
777
+
778
+ context 'when current directory is top level' do
779
+ cwd '.'
780
+ it 'knife download with no parameters reports an error' do
781
+ knife('download').should_fail "FATAL: Must specify at least one argument. If you want to download everything in this directory, type \"knife download .\"\n", :stdout => /USAGE/
782
+ end
783
+ end
497
784
  end
498
785
  end
499
- end
500
-
501
- when_the_chef_server 'has an environment' do
502
- environment 'x', {}
503
- when_the_repository 'has an environment with bad JSON' do
504
- file 'environments/x.json', '{'
505
- it 'knife download succeeds' do
506
- knife('download /environments/x.json').should_succeed "Updated /environments/x.json\n", :stderr => "WARN: Parse error reading #{path_to('environments/x.json')} as JSON: A JSON text must at least contain two octets!\n"
507
- knife('diff --name-status /environments/x.json').should_succeed ''
786
+
787
+ # Test download of an item when the other end doesn't even have the container
788
+ when_the_repository 'is empty' do
789
+ when_the_chef_server 'has two data bag items' do
790
+ data_bag 'x', { 'y' => {}, 'z' => {} }
791
+
792
+ it 'knife download of one data bag item itself succeeds' do
793
+ knife('download /data_bags/x/y.json').should_succeed <<EOM
794
+ Created /data_bags
795
+ Created /data_bags/x
796
+ Created /data_bags/x/y.json
797
+ EOM
798
+ knife('diff --name-status /data_bags').should_succeed <<EOM
799
+ D\t/data_bags/x/z.json
800
+ EOM
801
+ end
508
802
  end
509
803
  end
510
804
 
511
- when_the_repository 'has the same environment with the wrong name in the file' do
512
- file 'environments/x.json', { 'name' => 'y' }
513
- it 'knife download succeeds' do
514
- knife('download /environments/x.json').should_succeed "Updated /environments/x.json\n"
515
- knife('diff --name-status /environments/x.json').should_succeed ''
805
+ when_the_repository 'has three data bag items' do
806
+ file 'data_bags/x/deleted.json', <<EOM
807
+ {
808
+ "id": "deleted"
809
+ }
810
+ EOM
811
+ file 'data_bags/x/modified.json', <<EOM
812
+ {
813
+ "id": "modified"
814
+ }
815
+ EOM
816
+ file 'data_bags/x/unmodified.json', <<EOM
817
+ {
818
+ "id": "unmodified"
819
+ }
820
+ EOM
821
+
822
+ when_the_chef_server 'has a modified, unmodified, added and deleted data bag item' do
823
+ data_bag 'x', {
824
+ 'added' => {},
825
+ 'modified' => { 'foo' => 'bar' },
826
+ 'unmodified' => {}
827
+ }
828
+
829
+ it 'knife download of the modified file succeeds' do
830
+ knife('download /data_bags/x/modified.json').should_succeed <<EOM
831
+ Updated /data_bags/x/modified.json
832
+ EOM
833
+ knife('diff --name-status /data_bags').should_succeed <<EOM
834
+ D\t/data_bags/x/added.json
835
+ A\t/data_bags/x/deleted.json
836
+ EOM
837
+ end
838
+ it 'knife download of the unmodified file does nothing' do
839
+ knife('download /data_bags/x/unmodified.json').should_succeed ''
840
+ knife('diff --name-status /data_bags').should_succeed <<EOM
841
+ D\t/data_bags/x/added.json
842
+ M\t/data_bags/x/modified.json
843
+ A\t/data_bags/x/deleted.json
844
+ EOM
845
+ end
846
+ it 'knife download of the added file succeeds' do
847
+ knife('download /data_bags/x/added.json').should_succeed <<EOM
848
+ Created /data_bags/x/added.json
849
+ EOM
850
+ knife('diff --name-status /data_bags').should_succeed <<EOM
851
+ M\t/data_bags/x/modified.json
852
+ A\t/data_bags/x/deleted.json
853
+ EOM
854
+ end
855
+ it 'knife download of the deleted file does nothing' do
856
+ knife('download /data_bags/x/deleted.json').should_succeed ''
857
+ knife('diff --name-status /data_bags').should_succeed <<EOM
858
+ D\t/data_bags/x/added.json
859
+ M\t/data_bags/x/modified.json
860
+ A\t/data_bags/x/deleted.json
861
+ EOM
862
+ end
863
+ it 'knife download --purge of the deleted file deletes it' do
864
+ knife('download --purge /data_bags/x/deleted.json').should_succeed <<EOM
865
+ Deleted extra entry /data_bags/x/deleted.json (purge is on)
866
+ EOM
867
+ knife('diff --name-status /data_bags').should_succeed <<EOM
868
+ D\t/data_bags/x/added.json
869
+ M\t/data_bags/x/modified.json
870
+ EOM
871
+ end
872
+ it 'knife download of the entire data bag downloads everything' do
873
+ knife('download /data_bags/x').should_succeed <<EOM
874
+ Created /data_bags/x/added.json
875
+ Updated /data_bags/x/modified.json
876
+ EOM
877
+ knife('diff --name-status /data_bags').should_succeed <<EOM
878
+ A\t/data_bags/x/deleted.json
879
+ EOM
880
+ end
881
+ it 'knife download --purge of the entire data bag downloads everything' do
882
+ knife('download --purge /data_bags/x').should_succeed <<EOM
883
+ Created /data_bags/x/added.json
884
+ Updated /data_bags/x/modified.json
885
+ Deleted extra entry /data_bags/x/deleted.json (purge is on)
886
+ EOM
887
+ knife('diff --name-status /data_bags').should_succeed ''
888
+ end
889
+ context 'when cwd is the /data_bags directory' do
890
+ cwd 'data_bags'
891
+ it 'knife download fails' do
892
+ knife('download').should_fail "FATAL: Must specify at least one argument. If you want to download everything in this directory, type \"knife download .\"\n", :stdout => /USAGE/
893
+ end
894
+ it 'knife download --purge . downloads everything' do
895
+ knife('download --purge .').should_succeed <<EOM
896
+ Created x/added.json
897
+ Updated x/modified.json
898
+ Deleted extra entry x/deleted.json (purge is on)
899
+ EOM
900
+ knife('diff --name-status /data_bags').should_succeed ''
901
+ end
902
+ it 'knife download --purge * downloads everything' do
903
+ knife('download --purge *').should_succeed <<EOM
904
+ Created x/added.json
905
+ Updated x/modified.json
906
+ Deleted extra entry x/deleted.json (purge is on)
907
+ EOM
908
+ knife('diff --name-status /data_bags').should_succeed ''
909
+ end
910
+ end
911
+ end
912
+ end
913
+
914
+ when_the_repository 'has a cookbook' do
915
+ file 'cookbooks/x-1.0.0/metadata.rb', 'version "1.0.0"'
916
+ file 'cookbooks/x-1.0.0/z.rb', ''
917
+
918
+ when_the_chef_server 'has a modified, added and deleted file for the cookbook' do
919
+ cookbook 'x', '1.0.0', { 'metadata.rb' => 'version "1.0.0"', 'y.rb' => 'hi' }
920
+
921
+ it 'knife download of a modified file succeeds' do
922
+ knife('download /cookbooks/x-1.0.0/metadata.rb').should_succeed "Updated /cookbooks/x-1.0.0/metadata.rb\n"
923
+ knife('diff --name-status /cookbooks').should_succeed <<EOM
924
+ D\t/cookbooks/x-1.0.0/y.rb
925
+ A\t/cookbooks/x-1.0.0/z.rb
926
+ EOM
927
+ end
928
+ it 'knife download of a deleted file does nothing' do
929
+ knife('download /cookbooks/x-1.0.0/z.rb').should_succeed ''
930
+ knife('diff --name-status /cookbooks').should_succeed <<EOM
931
+ M\t/cookbooks/x-1.0.0/metadata.rb
932
+ D\t/cookbooks/x-1.0.0/y.rb
933
+ A\t/cookbooks/x-1.0.0/z.rb
934
+ EOM
935
+ end
936
+ it 'knife download --purge of a deleted file succeeds' do
937
+ knife('download --purge /cookbooks/x-1.0.0/z.rb').should_succeed "Deleted extra entry /cookbooks/x-1.0.0/z.rb (purge is on)\n"
938
+ knife('diff --name-status /cookbooks').should_succeed <<EOM
939
+ M\t/cookbooks/x-1.0.0/metadata.rb
940
+ D\t/cookbooks/x-1.0.0/y.rb
941
+ EOM
942
+ end
943
+ it 'knife download of an added file succeeds' do
944
+ knife('download /cookbooks/x-1.0.0/y.rb').should_succeed "Created /cookbooks/x-1.0.0/y.rb\n"
945
+ knife('diff --name-status /cookbooks').should_succeed <<EOM
946
+ M\t/cookbooks/x-1.0.0/metadata.rb
947
+ A\t/cookbooks/x-1.0.0/z.rb
948
+ EOM
949
+ end
950
+ it 'knife download of the cookbook itself succeeds' do
951
+ knife('download /cookbooks/x-1.0.0').should_succeed <<EOM
952
+ Updated /cookbooks/x-1.0.0/metadata.rb
953
+ Created /cookbooks/x-1.0.0/y.rb
954
+ EOM
955
+ knife('diff --name-status /cookbooks').should_succeed <<EOM
956
+ A\t/cookbooks/x-1.0.0/z.rb
957
+ EOM
958
+ end
959
+ it 'knife download --purge of the cookbook itself succeeds' do
960
+ knife('download --purge /cookbooks/x-1.0.0').should_succeed <<EOM
961
+ Updated /cookbooks/x-1.0.0/metadata.rb
962
+ Created /cookbooks/x-1.0.0/y.rb
963
+ Deleted extra entry /cookbooks/x-1.0.0/z.rb (purge is on)
964
+ EOM
965
+ knife('diff --name-status /cookbooks').should_succeed ''
966
+ end
516
967
  end
517
968
  end
518
969
 
519
- when_the_repository 'has the same environment with no name in the file' do
520
- file 'environments/x.json', { 'description' => 'hi' }
521
- it 'knife download succeeds' do
522
- knife('download /environments/x.json').should_succeed "Updated /environments/x.json\n"
523
- knife('diff --name-status /environments/x.json').should_succeed ''
970
+ when_the_repository 'has a cookbook' do
971
+ file 'cookbooks/x-1.0.0/metadata.rb', 'version "1.0.0"'
972
+ file 'cookbooks/x-1.0.0/onlyin1.0.0.rb', 'old_text'
973
+
974
+ when_the_chef_server 'has a later version for the cookbook' do
975
+ cookbook 'x', '1.0.0', { 'metadata.rb' => 'version "1.0.0"', 'onlyin1.0.0.rb' => '' }
976
+ cookbook 'x', '1.0.1', { 'metadata.rb' => 'version "1.0.1"', 'onlyin1.0.1.rb' => 'hi' }
977
+
978
+ it 'knife download /cookbooks/x downloads the latest version' do
979
+ knife('download --purge /cookbooks').should_succeed <<EOM
980
+ Updated /cookbooks/x-1.0.0/onlyin1.0.0.rb
981
+ Created /cookbooks/x-1.0.1
982
+ Created /cookbooks/x-1.0.1/metadata.rb
983
+ Created /cookbooks/x-1.0.1/onlyin1.0.1.rb
984
+ EOM
985
+ knife('diff --name-status /cookbooks').should_succeed ''
986
+ end
987
+ end
988
+
989
+ when_the_chef_server 'has an earlier version for the cookbook' do
990
+ cookbook 'x', '1.0.0', { 'metadata.rb' => 'version "1.0.0"', 'onlyin1.0.0.rb' => ''}
991
+ cookbook 'x', '0.9.9', { 'metadata.rb' => 'version "0.9.9"', 'onlyin0.9.9.rb' => 'hi' }
992
+ it 'knife download /cookbooks downloads the updated file' do
993
+ knife('download --purge /cookbooks').should_succeed <<EOM
994
+ Created /cookbooks/x-0.9.9
995
+ Created /cookbooks/x-0.9.9/metadata.rb
996
+ Created /cookbooks/x-0.9.9/onlyin0.9.9.rb
997
+ Updated /cookbooks/x-1.0.0/onlyin1.0.0.rb
998
+ EOM
999
+ knife('diff --name-status /cookbooks').should_succeed ''
1000
+ end
1001
+ end
1002
+
1003
+ when_the_chef_server 'has a later version for the cookbook, and no current version' do
1004
+ cookbook 'x', '1.0.1', { 'metadata.rb' => 'version "1.0.1"', 'onlyin1.0.1.rb' => 'hi' }
1005
+
1006
+ it 'knife download /cookbooks/x downloads the latest version' do
1007
+ knife('download --purge /cookbooks').should_succeed <<EOM
1008
+ Created /cookbooks/x-1.0.1
1009
+ Created /cookbooks/x-1.0.1/metadata.rb
1010
+ Created /cookbooks/x-1.0.1/onlyin1.0.1.rb
1011
+ Deleted extra entry /cookbooks/x-1.0.0 (purge is on)
1012
+ EOM
1013
+ knife('diff --name-status /cookbooks').should_succeed ''
1014
+ end
1015
+ end
1016
+
1017
+ when_the_chef_server 'has an earlier version for the cookbook, and no current version' do
1018
+ cookbook 'x', '0.9.9', { 'metadata.rb' => 'version "0.9.9"', 'onlyin0.9.9.rb' => 'hi' }
1019
+
1020
+ it 'knife download --purge /cookbooks downloads the old version and deletes the new version' do
1021
+ knife('download --purge /cookbooks').should_succeed <<EOM
1022
+ Created /cookbooks/x-0.9.9
1023
+ Created /cookbooks/x-0.9.9/metadata.rb
1024
+ Created /cookbooks/x-0.9.9/onlyin0.9.9.rb
1025
+ Deleted extra entry /cookbooks/x-1.0.0 (purge is on)
1026
+ EOM
1027
+ knife('diff --name-status /cookbooks').should_succeed ''
1028
+ end
1029
+ end
1030
+ end
1031
+
1032
+ when_the_chef_server 'has an environment' do
1033
+ environment 'x', {}
1034
+ when_the_repository 'has an environment with bad JSON' do
1035
+ file 'environments/x.json', '{'
1036
+ it 'knife download succeeds' do
1037
+ knife('download /environments/x.json').should_succeed "Updated /environments/x.json\n", :stderr => "WARN: Parse error reading #{path_to('environments/x.json')} as JSON: A JSON text must at least contain two octets!\n"
1038
+ knife('diff --name-status /environments/x.json').should_succeed ''
1039
+ end
1040
+ end
1041
+
1042
+ when_the_repository 'has the same environment with the wrong name in the file' do
1043
+ file 'environments/x.json', { 'name' => 'y' }
1044
+ it 'knife download succeeds' do
1045
+ knife('download /environments/x.json').should_succeed "Updated /environments/x.json\n"
1046
+ knife('diff --name-status /environments/x.json').should_succeed ''
1047
+ end
1048
+ end
1049
+
1050
+ when_the_repository 'has the same environment with no name in the file' do
1051
+ file 'environments/x.json', { 'description' => 'hi' }
1052
+ it 'knife download succeeds' do
1053
+ knife('download /environments/x.json').should_succeed "Updated /environments/x.json\n"
1054
+ knife('diff --name-status /environments/x.json').should_succeed ''
1055
+ end
524
1056
  end
525
1057
  end
526
- end
1058
+ end # with versioned cookbooks
527
1059
  end