bosh_cli 0.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. data/README +4 -0
  2. data/Rakefile +55 -0
  3. data/bin/bosh +17 -0
  4. data/lib/cli.rb +76 -0
  5. data/lib/cli/cache.rb +44 -0
  6. data/lib/cli/changeset_helper.rb +142 -0
  7. data/lib/cli/command_definition.rb +52 -0
  8. data/lib/cli/commands/base.rb +245 -0
  9. data/lib/cli/commands/biff.rb +300 -0
  10. data/lib/cli/commands/blob.rb +125 -0
  11. data/lib/cli/commands/cloudcheck.rb +169 -0
  12. data/lib/cli/commands/deployment.rb +147 -0
  13. data/lib/cli/commands/job.rb +42 -0
  14. data/lib/cli/commands/job_management.rb +117 -0
  15. data/lib/cli/commands/log_management.rb +81 -0
  16. data/lib/cli/commands/maintenance.rb +131 -0
  17. data/lib/cli/commands/misc.rb +240 -0
  18. data/lib/cli/commands/package.rb +112 -0
  19. data/lib/cli/commands/property_management.rb +125 -0
  20. data/lib/cli/commands/release.rb +469 -0
  21. data/lib/cli/commands/ssh.rb +271 -0
  22. data/lib/cli/commands/stemcell.rb +184 -0
  23. data/lib/cli/commands/task.rb +213 -0
  24. data/lib/cli/commands/user.rb +28 -0
  25. data/lib/cli/commands/vms.rb +53 -0
  26. data/lib/cli/config.rb +154 -0
  27. data/lib/cli/core_ext.rb +145 -0
  28. data/lib/cli/dependency_helper.rb +62 -0
  29. data/lib/cli/deployment_helper.rb +263 -0
  30. data/lib/cli/deployment_manifest_compiler.rb +28 -0
  31. data/lib/cli/director.rb +633 -0
  32. data/lib/cli/director_task.rb +64 -0
  33. data/lib/cli/errors.rb +48 -0
  34. data/lib/cli/event_log_renderer.rb +351 -0
  35. data/lib/cli/job_builder.rb +226 -0
  36. data/lib/cli/package_builder.rb +254 -0
  37. data/lib/cli/packaging_helper.rb +248 -0
  38. data/lib/cli/release.rb +176 -0
  39. data/lib/cli/release_builder.rb +215 -0
  40. data/lib/cli/release_compiler.rb +178 -0
  41. data/lib/cli/release_tarball.rb +272 -0
  42. data/lib/cli/runner.rb +771 -0
  43. data/lib/cli/stemcell.rb +83 -0
  44. data/lib/cli/task_log_renderer.rb +40 -0
  45. data/lib/cli/templates/help_message.erb +75 -0
  46. data/lib/cli/validation.rb +42 -0
  47. data/lib/cli/version.rb +7 -0
  48. data/lib/cli/version_calc.rb +48 -0
  49. data/lib/cli/versions_index.rb +126 -0
  50. data/lib/cli/yaml_helper.rb +62 -0
  51. data/spec/assets/biff/bad_gateway_config.yml +28 -0
  52. data/spec/assets/biff/good_simple_config.yml +63 -0
  53. data/spec/assets/biff/good_simple_golden_config.yml +63 -0
  54. data/spec/assets/biff/good_simple_template.erb +69 -0
  55. data/spec/assets/biff/multiple_subnets_config.yml +40 -0
  56. data/spec/assets/biff/network_only_template.erb +34 -0
  57. data/spec/assets/biff/no_cc_config.yml +27 -0
  58. data/spec/assets/biff/no_range_config.yml +27 -0
  59. data/spec/assets/biff/no_subnet_config.yml +16 -0
  60. data/spec/assets/biff/ok_network_config.yml +30 -0
  61. data/spec/assets/biff/properties_template.erb +6 -0
  62. data/spec/assets/deployment.MF +0 -0
  63. data/spec/assets/plugins/bosh/cli/commands/echo.rb +43 -0
  64. data/spec/assets/plugins/bosh/cli/commands/ruby.rb +24 -0
  65. data/spec/assets/release/jobs/cacher.tgz +0 -0
  66. data/spec/assets/release/jobs/cacher/config/file1.conf +0 -0
  67. data/spec/assets/release/jobs/cacher/config/file2.conf +0 -0
  68. data/spec/assets/release/jobs/cacher/job.MF +6 -0
  69. data/spec/assets/release/jobs/cacher/monit +1 -0
  70. data/spec/assets/release/jobs/cleaner.tgz +0 -0
  71. data/spec/assets/release/jobs/cleaner/job.MF +4 -0
  72. data/spec/assets/release/jobs/cleaner/monit +1 -0
  73. data/spec/assets/release/jobs/sweeper.tgz +0 -0
  74. data/spec/assets/release/jobs/sweeper/config/test.conf +1 -0
  75. data/spec/assets/release/jobs/sweeper/job.MF +5 -0
  76. data/spec/assets/release/jobs/sweeper/monit +1 -0
  77. data/spec/assets/release/packages/mutator.tar.gz +0 -0
  78. data/spec/assets/release/packages/stuff.tgz +0 -0
  79. data/spec/assets/release/release.MF +17 -0
  80. data/spec/assets/release_invalid_checksum.tgz +0 -0
  81. data/spec/assets/release_invalid_jobs.tgz +0 -0
  82. data/spec/assets/release_no_name.tgz +0 -0
  83. data/spec/assets/release_no_version.tgz +0 -0
  84. data/spec/assets/stemcell/image +1 -0
  85. data/spec/assets/stemcell/stemcell.MF +6 -0
  86. data/spec/assets/stemcell_invalid_mf.tgz +0 -0
  87. data/spec/assets/stemcell_no_image.tgz +0 -0
  88. data/spec/assets/valid_release.tgz +0 -0
  89. data/spec/assets/valid_stemcell.tgz +0 -0
  90. data/spec/spec_helper.rb +25 -0
  91. data/spec/unit/base_command_spec.rb +66 -0
  92. data/spec/unit/biff_spec.rb +135 -0
  93. data/spec/unit/cache_spec.rb +36 -0
  94. data/spec/unit/cli_commands_spec.rb +481 -0
  95. data/spec/unit/config_spec.rb +139 -0
  96. data/spec/unit/core_ext_spec.rb +77 -0
  97. data/spec/unit/dependency_helper_spec.rb +52 -0
  98. data/spec/unit/deployment_manifest_compiler_spec.rb +63 -0
  99. data/spec/unit/director_spec.rb +511 -0
  100. data/spec/unit/director_task_spec.rb +48 -0
  101. data/spec/unit/event_log_renderer_spec.rb +171 -0
  102. data/spec/unit/hash_changeset_spec.rb +73 -0
  103. data/spec/unit/job_builder_spec.rb +454 -0
  104. data/spec/unit/package_builder_spec.rb +567 -0
  105. data/spec/unit/release_builder_spec.rb +65 -0
  106. data/spec/unit/release_spec.rb +66 -0
  107. data/spec/unit/release_tarball_spec.rb +33 -0
  108. data/spec/unit/runner_spec.rb +140 -0
  109. data/spec/unit/ssh_spec.rb +78 -0
  110. data/spec/unit/stemcell_spec.rb +17 -0
  111. data/spec/unit/version_calc_spec.rb +27 -0
  112. data/spec/unit/versions_index_spec.rb +132 -0
  113. metadata +338 -0
@@ -0,0 +1,567 @@
1
+ # Copyright (c) 2009-2012 VMware, Inc.
2
+
3
+ require "spec_helper"
4
+
5
+ describe Bosh::Cli::PackageBuilder, "dev build" do
6
+
7
+ before(:each) do
8
+ @release_dir = Dir.mktmpdir
9
+ @src_dir = FileUtils.mkdir(File.join(@release_dir, "src"))
10
+ @blobs_dir = FileUtils.mkdir(File.join(@release_dir, "blobs"))
11
+ end
12
+
13
+ after(:each) do
14
+ FileUtils.rm_rf(@src_dir)
15
+ FileUtils.rm_rf(@blobs_dir)
16
+ end
17
+
18
+ def source_path(filename)
19
+ File.join(@release_dir, "src", filename)
20
+ end
21
+
22
+ def add_sources(*files)
23
+ files.each do |file|
24
+ path = source_path(file)
25
+ FileUtils.mkdir_p(File.dirname(path))
26
+ FileUtils.touch(path)
27
+ end
28
+ end
29
+
30
+ def remove_sources(*files)
31
+ files.each do |file|
32
+ FileUtils.rm(source_path(file))
33
+ end
34
+ end
35
+
36
+ def blob_path(filename)
37
+ File.join(@release_dir, "blobs", filename)
38
+ end
39
+
40
+ def add_blobs(*files)
41
+ files.each do |file|
42
+ path = blob_path(file)
43
+ FileUtils.mkdir_p(File.dirname(path))
44
+ FileUtils.touch(path)
45
+ end
46
+ end
47
+
48
+ def remove_blobs(*files)
49
+ files.each do |file|
50
+ FileUtils.rm(blob_path(file))
51
+ end
52
+ end
53
+
54
+ def make_builder(name, files, dependencies = [], sources_dir = nil)
55
+ blobstore = mock("blobstore")
56
+ spec = { "name" => name, "files" => files,
57
+ "dependencies" => dependencies }
58
+ Bosh::Cli::PackageBuilder.new(spec, @release_dir,
59
+ false, blobstore, sources_dir)
60
+ end
61
+
62
+ it "whines on missing name" do
63
+ lambda {
64
+ make_builder(" ", [])
65
+ }.should raise_error(Bosh::Cli::InvalidPackage, "Package name is missing")
66
+ end
67
+
68
+ it "whines on funny characters in name" do
69
+ lambda {
70
+ make_builder("@#!", [])
71
+ }.should raise_error(Bosh::Cli::InvalidPackage,
72
+ "Package name should be a valid BOSH identifier")
73
+ end
74
+
75
+ it "whines on empty files" do
76
+ lambda {
77
+ make_builder("aa", [])
78
+ }.should raise_error(Bosh::Cli::InvalidPackage,
79
+ "Package 'aa' doesn't include any files")
80
+ end
81
+
82
+ it "whines on metadata file having the same name as one of package files" do
83
+ lambda {
84
+ builder = make_builder("aa", ["*.rb", "packaging"])
85
+ add_sources("1.rb", "packaging")
86
+ builder.source_files.include?("packaging").should be_true
87
+
88
+ File.open("#{@release_dir}/packages/aa/packaging", "w") do |f|
89
+ f.puts("make install")
90
+ end
91
+
92
+ builder.copy_files
93
+ }.should raise_error(Bosh::Cli::InvalidPackage,
94
+ "Package 'aa' has 'packaging' file which " +
95
+ "conflicts with BOSH packaging")
96
+ end
97
+
98
+ it "whines on globs not yielding any file names" do
99
+ add_sources("lib/1.rb", "lib/2.rb", "baz")
100
+ builder = make_builder("foo", ["lib/*.rb", "baz", "bar"])
101
+
102
+ lambda {
103
+ builder.build
104
+ }.should raise_error(Bosh::Cli::InvalidPackage,
105
+ "`foo' has a glob that resolves " +
106
+ "to an empty file list: bar")
107
+ end
108
+
109
+ it "has no way to calculate checksum for not yet generated package" do
110
+ lambda {
111
+ builder = make_builder("aa", ["*.rb", "packaging"])
112
+ add_sources("1.rb", "packaging")
113
+ builder.checksum
114
+ }.should raise_error(RuntimeError,
115
+ "cannot read checksum for not yet " +
116
+ "generated package/job")
117
+ end
118
+
119
+ it "has a checksum for a generated package" do
120
+ builder = make_builder("aa", ["*.rb"])
121
+ add_sources("1.rb", "2.rb")
122
+ builder.build
123
+ builder.checksum.should =~ /[0-9a-f]+/
124
+ end
125
+
126
+ it "is created with name and globs" do
127
+ builder = make_builder("aa", ["1", "*/*"])
128
+ builder.name.should == "aa"
129
+ builder.globs.should == ["1", "*/*"]
130
+ end
131
+
132
+ it "resolves globs and generates fingerprint" do
133
+ add_sources("lib/1.rb", "lib/2.rb", "lib/README.txt",
134
+ "README.2", "README.md")
135
+
136
+ builder = make_builder("A", ["lib/*.rb", "README.*"])
137
+ builder.source_files.should == ["lib/1.rb", "lib/2.rb",
138
+ "README.2", "README.md"].sort
139
+ builder.fingerprint.should == "397a99ccd267ebc9bcc632b746db2cd5b29db050"
140
+ end
141
+
142
+ it "has stable fingerprint" do
143
+ add_sources("lib/1.rb", "lib/2.rb", "lib/README.txt",
144
+ "README.2", "README.md")
145
+ builder = make_builder("A", ["lib/*.rb", "README.*"])
146
+ s1 = builder.fingerprint
147
+
148
+ builder.reload.fingerprint.should == s1
149
+ end
150
+
151
+ it "changes fingerprint when new file that matches glob is added" do
152
+ add_sources("lib/1.rb", "lib/2.rb", "lib/README.txt",
153
+ "README.2", "README.md")
154
+
155
+ builder = make_builder("A", ["lib/*.rb", "README.*"])
156
+ s1 = builder.fingerprint
157
+ add_sources("lib/3.rb")
158
+ builder.reload.fingerprint.should_not == s1
159
+
160
+ remove_sources("lib/3.rb")
161
+ builder.reload.fingerprint.should == s1
162
+ end
163
+
164
+ it "changes fingerprint when one of the matched files changes" do
165
+ add_sources("lib/1.rb", "lib/2.rb", "lib/README.txt",
166
+ "README.2", "README.md")
167
+ File.open("#{@release_dir}/src/lib/1.rb", "w") { |f| f.write("1") }
168
+
169
+ builder = make_builder("A", ["lib/*.rb", "README.*"])
170
+ s1 = builder.fingerprint
171
+
172
+ File.open("#{@release_dir}/src/lib/1.rb", "w+") { |f| f.write("2") }
173
+
174
+ builder.reload.fingerprint.should_not == s1
175
+
176
+ File.open("#{@release_dir}/src/lib/1.rb", "w") { |f| f.write("1") }
177
+ builder.reload.fingerprint.should == s1
178
+ end
179
+
180
+ it "changes fingerprint when empty directory added/removed" do
181
+ add_sources("lib/1.rb", "lib/2.rb", "baz")
182
+ builder = make_builder("foo", ["lib/*.rb", "baz", "bar/*"])
183
+ FileUtils.mkdir_p(@release_dir + "/src/bar/zb")
184
+
185
+ s1 = builder.fingerprint
186
+
187
+ FileUtils.mkdir_p(@release_dir + "/src/bar/zb2")
188
+ s2 = builder.reload.fingerprint
189
+ s2.should_not == s1
190
+
191
+ builder.reload.fingerprint.should == s2
192
+ FileUtils.rm_rf(@release_dir + "/src/bar/zb2")
193
+ builder.reload.fingerprint.should == s1
194
+ end
195
+
196
+ it "doesn't change fingerprint when files that doesn't match glob is added" do
197
+ add_sources("lib/1.rb", "lib/2.rb", "lib/README.txt",
198
+ "README.2", "README.md")
199
+
200
+ builder = make_builder("A", ["lib/*.rb", "README.*"])
201
+ s1 = builder.fingerprint
202
+ add_sources("lib/a.out")
203
+ builder.reload.fingerprint.should == s1
204
+ end
205
+
206
+ it "changes fingerprint when dependencies change" do
207
+ add_sources("lib/1.rb", "lib/2.rb", "lib/README.txt",
208
+ "README.2", "README.md")
209
+
210
+ builder1 = make_builder("A", ["lib/*.rb", "README.*"], ["foo", "bar"])
211
+ s1 = builder1.fingerprint
212
+ builder2 = make_builder("A", ["lib/*.rb", "README.*"], ["bar", "foo"])
213
+ s2 = builder2.fingerprint
214
+
215
+ s1.should == s2
216
+ builder3 = make_builder("A", ["lib/*.rb", "README.*"],
217
+ ["bar", "foo", "baz"])
218
+ s3 = builder3.fingerprint
219
+ s3.should_not == s1
220
+ end
221
+
222
+ it "copies files to build directory" do
223
+ add_sources("foo/foo.rb", "foo/lib/1.rb", "foo/lib/2.rb",
224
+ "foo/README", "baz")
225
+ globs = ["foo/**/*", "baz"]
226
+
227
+ builder = make_builder("bar", globs)
228
+ builder.copy_files.should == 5
229
+
230
+ builder2 = make_builder("bar", globs, [], builder.build_dir)
231
+
232
+ # Also turned out to be a nice test for directory portability
233
+ builder.fingerprint.should == builder2.fingerprint
234
+ end
235
+
236
+ it "generates tarball" do
237
+ add_sources("foo/foo.rb", "foo/lib/1.rb", "foo/lib/2.rb",
238
+ "foo/README", "baz")
239
+ globs = ["foo/**/*", "baz"]
240
+
241
+ builder = make_builder("bar", globs)
242
+ builder.generate_tarball.should be_true
243
+ end
244
+
245
+ it "can point to either dev or a final version of a package" do
246
+ add_sources("foo/foo.rb", "foo/lib/1.rb", "foo/lib/2.rb",
247
+ "foo/README", "baz")
248
+ globs = ["foo/**/*", "baz"]
249
+
250
+ fingerprint = "86e8d5f5530a89659f588f5884fe8c13e639d94b"
251
+
252
+ final_versions = Bosh::Cli::VersionsIndex.new(
253
+ File.join(@release_dir, ".final_builds", "packages", "bar"))
254
+ dev_versions = Bosh::Cli::VersionsIndex.new(
255
+ File.join(@release_dir, ".dev_builds", "packages", "bar"))
256
+
257
+ final_versions.add_version(fingerprint,
258
+ { "version" => "4", "blobstore_id" => "12321" },
259
+ "payload")
260
+ dev_versions.add_version(fingerprint,
261
+ { "version" => "0.7-dev" },
262
+ "dev_payload")
263
+
264
+ builder = make_builder("bar", globs)
265
+ builder.fingerprint.should == fingerprint
266
+
267
+ builder.use_final_version
268
+ builder.version.should == "4"
269
+ builder.tarball_path.should == File.join(
270
+ @release_dir, ".final_builds", "packages", "bar", "4.tgz")
271
+
272
+ builder.use_dev_version
273
+ builder.version.should == "0.7-dev"
274
+ builder.tarball_path.should == File.join(
275
+ @release_dir, ".dev_builds", "packages", "bar", "0.7-dev.tgz")
276
+ end
277
+
278
+ it "creates a new version tarball" do
279
+ add_sources("foo/foo.rb", "foo/lib/1.rb",
280
+ "foo/lib/2.rb", "foo/README", "baz")
281
+ globs = ["foo/**/*", "baz"]
282
+ builder = make_builder("bar", globs)
283
+
284
+ File.exists?(@release_dir + "/.dev_builds/packages/bar/0.1-dev.tgz").
285
+ should be_false
286
+ builder.build
287
+ File.exists?(@release_dir + "/.dev_builds/packages/bar/0.1-dev.tgz").
288
+ should be_true
289
+
290
+ builder = make_builder("bar", globs)
291
+ builder.build
292
+ v1_fingerprint = builder.fingerprint
293
+
294
+ File.exists?(@release_dir + "/.dev_builds/packages/bar/0.1-dev.tgz").
295
+ should be_true
296
+ File.exists?(@release_dir + "/.dev_builds/packages/bar/0.2-dev.tgz").
297
+ should be_false
298
+
299
+ add_sources("foo/3.rb")
300
+ builder = make_builder("bar", globs)
301
+ builder.build
302
+
303
+ File.exists?(@release_dir + "/.dev_builds/packages/bar/0.1-dev.tgz").
304
+ should be_true
305
+ File.exists?(@release_dir + "/.dev_builds/packages/bar/0.2-dev.tgz").
306
+ should be_true
307
+
308
+ remove_sources("foo/3.rb")
309
+ builder = make_builder("bar", globs)
310
+ builder.build
311
+ builder.version.should == "0.1-dev"
312
+
313
+ builder.fingerprint.should == v1_fingerprint
314
+
315
+ File.exists?(@release_dir + "/.dev_builds/packages/bar/0.1-dev.tgz").
316
+ should be_true
317
+ File.exists?(@release_dir + "/.dev_builds/packages/bar/0.2-dev.tgz").
318
+ should be_true
319
+ File.exists?(@release_dir + "/.dev_builds/packages/bar/0.3-dev.tgz").
320
+ should be_false
321
+
322
+ # Now add packaging
323
+ File.open("#{@release_dir}/packages/bar/packaging", "w") do |f|
324
+ f.puts("make install")
325
+ end
326
+ builder = make_builder("bar", globs)
327
+ builder.build
328
+ builder.version.should == "0.3-dev"
329
+
330
+ # Add prepackaging
331
+ File.open("#{@release_dir}/packages/bar/pre_packaging", "w") do |f|
332
+ f.puts("exit 0")
333
+ end
334
+ builder = make_builder("bar", globs)
335
+ builder.build
336
+
337
+ File.exists?(@release_dir + "/.dev_builds/packages/bar/0.3-dev.tgz").
338
+ should be_true
339
+
340
+ # And remove all
341
+ builder = make_builder("bar", globs)
342
+ builder.build
343
+ builder.version.should == "0.4-dev"
344
+ File.exists?(@release_dir + "/.dev_builds/packages/bar/0.4-dev.tgz").
345
+ should be_true
346
+ File.exists?(@release_dir + "/.dev_builds/packages/bar/0.5-dev.tgz").
347
+ should be_false
348
+ end
349
+
350
+ it "stops if pre_packaging fails" do
351
+ add_sources("foo/foo.rb", "foo/lib/1.rb", "foo/lib/2.rb",
352
+ "foo/README", "baz")
353
+ globs = ["foo/**/*", "baz"]
354
+
355
+ builder = make_builder("bar", globs)
356
+ File.open("#{@release_dir}/packages/bar/pre_packaging", "w") do |f|
357
+ f.puts("rake db:migrate")
358
+ end
359
+
360
+ lambda {
361
+ builder.build
362
+ }.should raise_error(Bosh::Cli::InvalidPackage,
363
+ "`bar' pre-packaging failed")
364
+ end
365
+
366
+ it "bumps major dev version in sync with final version" do
367
+ add_sources("foo/foo.rb", "foo/lib/1.rb", "foo/lib/2.rb",
368
+ "foo/README", "baz")
369
+ globs = ["foo/**/*", "baz"]
370
+ builder = make_builder("bar", globs)
371
+ builder.build
372
+
373
+ builder.version.should == "0.1-dev"
374
+
375
+ blobstore = mock("blobstore")
376
+ blobstore.should_receive(:create).and_return("object_id")
377
+ final_builder = Bosh::Cli::PackageBuilder.new({ "name" => "bar",
378
+ "files" => globs },
379
+ @release_dir,
380
+ true, blobstore)
381
+ final_builder.build
382
+
383
+ final_builder.version.should == 1
384
+
385
+ add_sources("foo/foo15.rb")
386
+ builder2 = make_builder("bar", globs)
387
+ builder2.build
388
+ builder2.version.should == "1.1-dev"
389
+ end
390
+
391
+ it "uses the appropriate final version for bumping a dev version" do
392
+ add_sources("foo/foo.rb", "foo/lib/1.rb",
393
+ "foo/lib/2.rb", "foo/README", "baz")
394
+ globs = ["foo/**/*", "baz"]
395
+ builder = make_builder("bar", globs)
396
+ final_builds_dir = File.join(@release_dir,
397
+ ".final_builds", "packages", "bar")
398
+ builder.build
399
+
400
+ final_index = Bosh::Cli::VersionsIndex.new(final_builds_dir)
401
+ final_index.add_version("deadbeef", { "version" => 34 }, "payload")
402
+
403
+ add_sources("foo/foo14.rb")
404
+ builder.reload.build
405
+ builder.version.should == "34.1-dev"
406
+
407
+ final_index.add_version("deadbeef2", { "version" => 37 }, "payload")
408
+
409
+ add_sources("foo/foo15.rb")
410
+ builder.reload.build
411
+ builder.version.should == "37.1-dev"
412
+
413
+ add_sources("foo/foo16.rb")
414
+ builder.reload.build
415
+ builder.version.should == "37.2-dev"
416
+
417
+ FileUtils.rm_rf(final_builds_dir)
418
+ final_index = Bosh::Cli::VersionsIndex.new(final_builds_dir)
419
+ final_index.add_version("deadbeef3", { "version" => 34 }, "payload")
420
+
421
+ add_sources("foo/foo17.rb")
422
+ builder.reload.build
423
+ builder.version.should == "34.2-dev"
424
+ end
425
+
426
+ it "whines on attempt to create final build if not matched " +
427
+ "by existing final or dev build" do
428
+ add_sources("foo/foo.rb", "foo/lib/1.rb",
429
+ "foo/lib/2.rb", "foo/README", "baz")
430
+ globs = ["foo/**/*", "baz"]
431
+
432
+ blobstore = mock("blobstore")
433
+ blobstore.should_receive(:create).and_return("object_id")
434
+
435
+ final_builder = Bosh::Cli::PackageBuilder.new(
436
+ { "name" => "bar", "files" => globs }, @release_dir, true, blobstore)
437
+ lambda {
438
+ final_builder.build
439
+ }.should raise_error(Bosh::Cli::CliExit)
440
+
441
+ builder = make_builder("bar", globs)
442
+ builder.build
443
+
444
+ builder.version.should == "0.1-dev"
445
+
446
+ final_builder2 = Bosh::Cli::PackageBuilder.new(
447
+ { "name" => "bar", "files" => globs }, @release_dir, true, blobstore)
448
+ final_builder2.build
449
+ final_builder2.version.should == 1
450
+
451
+ add_sources("foo/foo15.rb")
452
+ final_builder3 = Bosh::Cli::PackageBuilder.new(
453
+ { "name" => "bar", "files" => globs }, @release_dir, true, blobstore)
454
+ lambda {
455
+ final_builder3.build
456
+ }.should raise_error(Bosh::Cli::CliExit)
457
+ end
458
+
459
+ it "includes dotfiles in a fingerprint" do
460
+ add_sources("lib/1.rb", "lib/2.rb",
461
+ "lib/README.txt", "README.2", "README.md")
462
+
463
+ builder = make_builder("A", ["lib/*.rb", "README.*"])
464
+ builder.source_files.should == ["lib/1.rb", "lib/2.rb",
465
+ "README.2", "README.md"].sort
466
+
467
+ builder.fingerprint.should == "397a99ccd267ebc9bcc632b746db2cd5b29db050"
468
+
469
+ add_sources("lib/.zb.rb")
470
+ builder.reload
471
+
472
+ builder.source_files.should == ["lib/.zb.rb", "lib/1.rb",
473
+ "lib/2.rb", "README.2", "README.md"].sort
474
+ builder.fingerprint.should == "351b3bb8dc430e58a3264bcfb5c9c19c06ece4af"
475
+
476
+ remove_sources("lib/.zb.rb")
477
+ builder.reload
478
+
479
+ builder.source_files.should == ["lib/1.rb", "lib/2.rb",
480
+ "README.2", "README.md"].sort
481
+ builder.fingerprint.should == "397a99ccd267ebc9bcc632b746db2cd5b29db050"
482
+ end
483
+
484
+ it "supports dry run" do
485
+ add_sources("foo/foo.rb", "foo/lib/1.rb",
486
+ "foo/lib/2.rb", "foo/README", "baz")
487
+ globs = ["foo/**/*", "baz"]
488
+ builder = make_builder("bar", globs)
489
+ builder.dry_run = true
490
+ builder.build
491
+
492
+ builder.version.should == "0.1-dev"
493
+ File.exists?(@release_dir + "/.dev_builds/packages/bar/0.1-dev.tgz").
494
+ should be_false
495
+
496
+ builder.dry_run = false
497
+ builder.reload.build
498
+ builder.version.should == "0.1-dev"
499
+ File.exists?(@release_dir + "/.dev_builds/packages/bar/0.1-dev.tgz").
500
+ should be_true
501
+
502
+ blobstore = mock("blobstore")
503
+ blobstore.should_not_receive(:create)
504
+ final_builder = Bosh::Cli::PackageBuilder.new(
505
+ { "name" => "bar", "files" => globs }, @release_dir, true, blobstore)
506
+ final_builder.dry_run = true
507
+ final_builder.build
508
+
509
+ # Hasn't been promoted b/c of dry run
510
+ final_builder.version.should == "0.1-dev"
511
+
512
+ add_sources("foo/foo15.rb")
513
+ builder2 = make_builder("bar", globs)
514
+ builder2.dry_run = true
515
+ builder2.build
516
+ builder2.version.should == "0.2-dev"
517
+ File.exists?(@release_dir + "/.dev_builds/packages/bar/0.1-dev.tgz").
518
+ should be_true
519
+ File.exists?(@release_dir + "/.dev_builds/packages/bar/0.2-dev.tgz").
520
+ should be_false
521
+ end
522
+
523
+ it "resolves files using blob" do
524
+ add_blobs("lib/1.rb", "lib/2.rb", "lib/README.txt", "README.2", "README.md")
525
+
526
+ builder = make_builder("A", ["lib/*.rb", "README.*"])
527
+ builder.blob_files.should == ["lib/1.rb", "lib/2.rb",
528
+ "README.2", "README.md"].sort
529
+ builder.fingerprint.should == "397a99ccd267ebc9bcc632b746db2cd5b29db050"
530
+ end
531
+
532
+ it "resolves files using both blob and source" do
533
+ add_sources("lib/1.rb", "lib/2.rb")
534
+ add_blobs("lib/README.txt", "README.2", "README.md")
535
+
536
+ builder = make_builder("A", ["lib/*.rb", "README.*"])
537
+
538
+ builder.source_files.should == ["lib/1.rb", "lib/2.rb"].sort
539
+ builder.blob_files.should == ["README.2", "README.md"].sort
540
+ builder.files.should == ["lib/1.rb", "lib/2.rb",
541
+ "README.2", "README.md"].sort
542
+ builder.fingerprint.should == "397a99ccd267ebc9bcc632b746db2cd5b29db050"
543
+ end
544
+
545
+ it "should keep same fingerprint moving packages " +
546
+ "from source_dir to blob_dir" do
547
+
548
+ # compute fingerprint when all the files are 'blob'
549
+ add_blobs("lib/1.rb", "lib/2.rb", "lib/README.txt",
550
+ "README.2", "README.md")
551
+ builder = make_builder("A", ["lib/*.rb", "README.*"])
552
+ blob_fingerprint = builder.fingerprint
553
+ remove_blobs("lib/1.rb", "lib/2.rb", "lib/README.txt",
554
+ "README.2", "README.md")
555
+
556
+ # compute fingerprint when all the files are in 'source'
557
+ add_sources("lib/1.rb", "lib/2.rb", "lib/README.txt",
558
+ "README.2", "README.md")
559
+ builder = make_builder("A", ["lib/*.rb", "README.*"])
560
+ blob_sources = builder.fingerprint
561
+ remove_sources("lib/1.rb", "lib/2.rb", "lib/README.txt",
562
+ "README.2", "README.md")
563
+
564
+ builder.fingerprint.should == blob_fingerprint
565
+ end
566
+
567
+ end