vmc 0.4.0.beta.33 → 0.4.0.beta.34

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,408 @@
1
+ require "cfoundry"
2
+ require "vmc"
3
+
4
+ require "vmc/spec_helpers/eventlog"
5
+ require "vmc/spec_helpers/patches"
6
+
7
+
8
+ TARGET = ENV["VMC_TEST_TARGET"] || "http://localhost:8181"
9
+ USER = ENV["VMC_TEST_USER"] || "sre@vmware.com"
10
+ PASSWORD = ENV["VMC_TEST_PASSWORD"] || "test"
11
+
12
+ module VMCHelpers
13
+ def random_str
14
+ format("%x", rand(1000000))
15
+ end
16
+
17
+ def client
18
+ VMC::CLI.client
19
+ end
20
+
21
+ # invoke a block while logged out
22
+ def without_auth
23
+ proxy = client.proxy
24
+ client.logout
25
+ client.proxy = nil
26
+ yield
27
+ ensure
28
+ client.login(USER, PASSWORD)
29
+ client.proxy = proxy
30
+ end
31
+
32
+ # same as Ruby 1.9's Array#sample
33
+ def sample(ary)
34
+ ary[rand(ary.size)]
35
+ end
36
+
37
+ # cache frameworks for app generation
38
+ def frameworks
39
+ @@frameworks ||= client.frameworks(0)
40
+ end
41
+
42
+ # cache runtimes for app generation
43
+ def runtimes
44
+ @@runtimes ||= client.runtimes(0)
45
+ end
46
+
47
+ def with_random_app(space = client.current_space)
48
+ with_random_apps(space, 1) do |apps|
49
+ yield apps.first
50
+ end
51
+ end
52
+
53
+ # create 2-5 random apps, call the block, and then delete them
54
+ def with_random_apps(space = client.current_space, num = rand(3) + 2)
55
+ apps = []
56
+
57
+ num.times do |n|
58
+ app = client.app
59
+ app.name = "app-#{n + 1}-#{random_str}"
60
+ app.space = space
61
+ app.instances = rand(2)
62
+
63
+ app.framework = sample(frameworks)
64
+ app.runtime = sample(runtimes)
65
+ app.memory = sample([64, 128, 256, 512])
66
+ app.create!
67
+
68
+ apps << app
69
+ end
70
+
71
+ yield apps
72
+ ensure
73
+ apps.each(&:delete!)
74
+ end
75
+
76
+ def with_new_space(org = client.current_organization)
77
+ space = client.space
78
+ space.name = "space-#{random_str}"
79
+ space.organization = org
80
+ space.create!
81
+
82
+ yield space
83
+ ensure
84
+ space.delete!
85
+ end
86
+
87
+ def running(command, inputs = {}, given = {})
88
+ VMC::CLI.new.exit_status 0
89
+
90
+ before_in = $stdin
91
+ before_out = $stdout
92
+ before_err = $stderr
93
+ before_event = $vmc_event
94
+
95
+ tty = FakeTTY.new
96
+
97
+ $vmc_event = EventLog.new(tty)
98
+
99
+ $stdin = tty
100
+ $stdout = StringIO.new
101
+ $stderr = StringIO.new
102
+
103
+ main = Thread.current
104
+
105
+ thd = Thread.new do
106
+ begin
107
+ VMC::CLI.new.invoke(command, inputs, given)
108
+ rescue SystemExit => e
109
+ unless e.status == 0
110
+ raise <<EOF
111
+ execution failed with status #{e.status}!
112
+
113
+ stdout:
114
+ #{$stdout.string.inspect}
115
+
116
+ stderr:
117
+ #{$stderr.string}
118
+ EOF
119
+ end
120
+ rescue => e
121
+ $vmc_event.raised(e)
122
+ end
123
+ end
124
+
125
+ begin
126
+ $vmc_event.process = thd
127
+
128
+ yield $vmc_event
129
+
130
+ $vmc_event.should complete
131
+ ensure
132
+ thd.kill
133
+ end
134
+ ensure
135
+ $stdin = before_in
136
+ $stdout = before_out
137
+ $stderr = before_err
138
+ $vmc_event = before_event
139
+ end
140
+ end
141
+
142
+ module VMCMatchers
143
+ class Contain
144
+ def initialize(content)
145
+ @content = content
146
+ end
147
+
148
+ def matches?(actual)
149
+ @actual = actual
150
+ true
151
+ end
152
+
153
+ def failure_message
154
+ "expected '#@content' to be in the output"
155
+ end
156
+
157
+ def negative_failure_message
158
+ "expected '#@content' to NOT be in the output"
159
+ end
160
+ end
161
+
162
+ def contain(content)
163
+ Contain.new(content)
164
+ end
165
+
166
+ class Ask
167
+ def initialize(message)
168
+ @message = message
169
+ end
170
+
171
+ def matches?(log)
172
+ ev = log.wait_for_event(EventLog::Asked)
173
+
174
+ @actual = ev.message
175
+ @actual == @message
176
+ end
177
+
178
+ def failure_message
179
+ "expected to be asked '#@message', got '#@actual'"
180
+ end
181
+
182
+ def negative_failure_message
183
+ "expected to NOT be asked for #@message"
184
+ end
185
+ end
186
+
187
+ def ask(message)
188
+ Ask.new(message)
189
+ end
190
+
191
+ class HaveInput
192
+ def initialize(name, value = nil)
193
+ @name = name
194
+ @expected = value
195
+ end
196
+
197
+ def matches?(log)
198
+ @actual = log.wait_for_event(EventLog::GotInput).value
199
+ @actual == @expected
200
+ end
201
+
202
+ def failure_message
203
+ "expected to have input '#@name' as '#@expected', but got '#@actual'"
204
+ end
205
+
206
+ def negative_failure_message
207
+ "expected not to have input '#@name', but had it as '#@actual'"
208
+ end
209
+ end
210
+
211
+ def have_input(name, value = nil)
212
+ HaveInput.new(name, value)
213
+ end
214
+
215
+ class Output
216
+ def initialize(line)
217
+ @expected = line
218
+ end
219
+
220
+ def matches?(log)
221
+ @actual = log.wait_for_event(EventLog::Printed).line
222
+ @actual == @expected
223
+ end
224
+
225
+ def failure_message
226
+ "expected '#@expected' to be in the output, but got '#@actual'"
227
+ end
228
+
229
+ def negative_failure_message
230
+ "expected '#@expected' NOT to be in the output, but it was"
231
+ end
232
+ end
233
+
234
+ def output(line)
235
+ Output.new(line)
236
+ end
237
+
238
+ class Complete
239
+ def matches?(log)
240
+ @log = log
241
+
242
+ log.process.join(1)
243
+
244
+ log.process.status == false
245
+ end
246
+
247
+ def failure_message
248
+ pending = @log.pending_events
249
+
250
+ if @exception
251
+ "process existed with an exception: #@exception"
252
+ elsif !pending.empty?
253
+ "expected process to complete, but it's pending events #{pending}"
254
+ else
255
+ "process is blocked; status: #{@log.process.status}"
256
+ end
257
+ end
258
+
259
+ def negative_failure_message
260
+ "expected process to still be running, but it's completed"
261
+ end
262
+ end
263
+
264
+ def complete
265
+ Complete.new
266
+ end
267
+
268
+
269
+ class FailWith
270
+ def initialize(exception, predicate = nil)
271
+ @expected = exception
272
+ @predicate = predicate
273
+ end
274
+
275
+ def matches?(log)
276
+ @actual = log.wait_for_event(EventLog::Raised).exception
277
+
278
+ return false unless @actual.is_a?(@expected)
279
+
280
+ @predicate.call(@actual) if @predicate
281
+
282
+ true
283
+ end
284
+
285
+ def failure_message
286
+ "expected #@expected to be raised, but got #{@actual.class}: '#@actual'"
287
+ end
288
+
289
+ def negative_failure_message
290
+ "expected #@expected to NOT be raised, but it was"
291
+ end
292
+ end
293
+
294
+ def fail_with(exception, &blk)
295
+ FailWith.new(exception, blk)
296
+ end
297
+
298
+
299
+ class ProgressExpectation
300
+ def matches?(log)
301
+ @actual = log.wait_for_event(EventLog::Progress)
302
+ @actual == @expected
303
+ end
304
+
305
+ def failure_message
306
+ "expected to #{@expected.report}, but #{@actual.report_past} instead"
307
+ end
308
+
309
+ def negative_failure_message
310
+ "expected not to #{@expected.report}"
311
+ end
312
+ end
313
+
314
+ class Successfully < ProgressExpectation
315
+ def initialize(message)
316
+ @expected = EventLog::Did.new(message)
317
+ end
318
+ end
319
+
320
+ class Skip < ProgressExpectation
321
+ def initialize(message)
322
+ @expected = EventLog::Skipped.new(message)
323
+ end
324
+ end
325
+
326
+ class FailTo < ProgressExpectation
327
+ def initialize(message)
328
+ @expected = EventLog::FailedTo.new(message)
329
+ end
330
+ end
331
+
332
+ class GiveUp < ProgressExpectation
333
+ def initialize(message)
334
+ @expected = EventLog::GaveUp.new(message)
335
+ end
336
+ end
337
+
338
+ def successfully(message)
339
+ Successfully.new(message)
340
+ end
341
+
342
+ def skip(message)
343
+ Skip.new(message)
344
+ end
345
+
346
+ def fail_to(message)
347
+ FailTo.new(message)
348
+ end
349
+
350
+ def give_up(message)
351
+ GiveUp.new(message)
352
+ end
353
+
354
+
355
+ def asks(what)
356
+ $vmc_event.should ask(what)
357
+ end
358
+
359
+ def given(what)
360
+ $vmc_event.provide("#{what}\n")
361
+ end
362
+
363
+ def has_input(name, value = nil)
364
+ $vmc_event.should have_input(name, value)
365
+ end
366
+
367
+ def raises(exception, &blk)
368
+ $vmc_event.should fail_with(exception, &blk)
369
+ end
370
+
371
+ def finish
372
+ $vmc_event.should complete
373
+ end
374
+
375
+ def outputs(what)
376
+ $vmc_event.should output(what)
377
+ end
378
+
379
+ def does(what)
380
+ $vmc_event.should successfully(what)
381
+ end
382
+
383
+ def skips(what)
384
+ $vmc_event.should skip(what)
385
+ end
386
+
387
+ def fails_to(what)
388
+ $vmc_event.should fail_to(what)
389
+ end
390
+
391
+ def gives_up(what)
392
+ $vmc_event.should give_up(what)
393
+ end
394
+ end
395
+
396
+ RSpec.configure do |c|
397
+ c.include VMCHelpers
398
+ c.include VMCMatchers
399
+
400
+ c.before(:all) do
401
+ VMC::CLI.client = CFoundry::Client.new(TARGET)
402
+
403
+ client.login(:username => USER, :password => PASSWORD)
404
+ client.current_organization = client.organizations.first
405
+ client.current_space = client.current_organization.spaces.first
406
+ end
407
+ end
408
+
File without changes
File without changes
@@ -1,3 +1,3 @@
1
1
  module VMC
2
- VERSION = "0.4.0.beta.33"
2
+ VERSION = "0.4.0.beta.34"
3
3
  end
@@ -1,414 +1,7 @@
1
+ require "vmc/spec_helpers"
1
2
  require "simplecov"
2
3
 
3
4
  SimpleCov.start do
4
5
  root File.expand_path("../../", __FILE__)
5
6
  add_filter "spec/"
6
7
  end
7
-
8
- require "cfoundry"
9
- require "vmc"
10
-
11
- require File.expand_path("../eventlog", __FILE__)
12
- require File.expand_path("../patches", __FILE__)
13
-
14
-
15
- TARGET = ENV["VMC_TEST_TARGET"] || "http://localhost:8181"
16
- USER = ENV["VMC_TEST_USER"] || "sre@vmware.com"
17
- PASSWORD = ENV["VMC_TEST_PASSWORD"] || "test"
18
-
19
- module VMCHelpers
20
- def random_str
21
- format("%x", rand(1000000))
22
- end
23
-
24
- def client
25
- VMC::CLI.client
26
- end
27
-
28
- # invoke a block while logged out
29
- def without_auth
30
- proxy = client.proxy
31
- client.logout
32
- client.proxy = nil
33
- yield
34
- ensure
35
- client.login(USER, PASSWORD)
36
- client.proxy = proxy
37
- end
38
-
39
- # same as Ruby 1.9's Array#sample
40
- def sample(ary)
41
- ary[rand(ary.size)]
42
- end
43
-
44
- # cache frameworks for app generation
45
- def frameworks
46
- @@frameworks ||= client.frameworks(0)
47
- end
48
-
49
- # cache runtimes for app generation
50
- def runtimes
51
- @@runtimes ||= client.runtimes(0)
52
- end
53
-
54
- def with_random_app(space = client.current_space)
55
- with_random_apps(space, 1) do |apps|
56
- yield apps.first
57
- end
58
- end
59
-
60
- # create 2-5 random apps, call the block, and then delete them
61
- def with_random_apps(space = client.current_space, num = rand(3) + 2)
62
- apps = []
63
-
64
- num.times do |n|
65
- app = client.app
66
- app.name = "app-#{n + 1}-#{random_str}"
67
- app.space = space
68
- app.instances = rand(2)
69
-
70
- app.framework = sample(frameworks)
71
- app.runtime = sample(runtimes)
72
- app.memory = sample([64, 128, 256, 512])
73
- app.create!
74
-
75
- apps << app
76
- end
77
-
78
- yield apps
79
- ensure
80
- apps.each(&:delete!)
81
- end
82
-
83
- def with_new_space(org = client.current_organization)
84
- space = client.space
85
- space.name = "space-#{random_str}"
86
- space.organization = org
87
- space.create!
88
-
89
- yield space
90
- ensure
91
- space.delete!
92
- end
93
-
94
- def running(command, inputs = {}, given = {})
95
- VMC::CLI.new.exit_status 0
96
-
97
- before_in = $stdin
98
- before_out = $stdout
99
- before_err = $stderr
100
- before_event = $vmc_event
101
-
102
- tty = FakeTTY.new
103
-
104
- $vmc_event = EventLog.new(tty)
105
-
106
- $stdin = tty
107
- $stdout = StringIO.new
108
- $stderr = StringIO.new
109
-
110
- main = Thread.current
111
-
112
- thd = Thread.new do
113
- begin
114
- VMC::CLI.new.invoke(command, inputs, given)
115
- rescue SystemExit => e
116
- unless e.status == 0
117
- raise <<EOF
118
- execution failed with status #{e.status}!
119
-
120
- stdout:
121
- #{$stdout.string.inspect}
122
-
123
- stderr:
124
- #{$stderr.string}
125
- EOF
126
- end
127
- rescue => e
128
- $vmc_event.raised(e)
129
- end
130
- end
131
-
132
- begin
133
- $vmc_event.process = thd
134
-
135
- yield $vmc_event
136
-
137
- $vmc_event.should complete
138
- ensure
139
- thd.kill
140
- end
141
- ensure
142
- $stdin = before_in
143
- $stdout = before_out
144
- $stderr = before_err
145
- $vmc_event = before_event
146
- end
147
- end
148
-
149
- module VMCMatchers
150
- class Contain
151
- def initialize(content)
152
- @content = content
153
- end
154
-
155
- def matches?(actual)
156
- @actual = actual
157
- true
158
- end
159
-
160
- def failure_message
161
- "expected '#@content' to be in the output"
162
- end
163
-
164
- def negative_failure_message
165
- "expected '#@content' to NOT be in the output"
166
- end
167
- end
168
-
169
- def contain(content)
170
- Contain.new(content)
171
- end
172
-
173
- class Ask
174
- def initialize(message)
175
- @message = message
176
- end
177
-
178
- def matches?(log)
179
- ev = log.wait_for_event(EventLog::Asked)
180
-
181
- @actual = ev.message
182
- @actual == @message
183
- end
184
-
185
- def failure_message
186
- "expected to be asked '#@message', got '#@actual'"
187
- end
188
-
189
- def negative_failure_message
190
- "expected to NOT be asked for #@message"
191
- end
192
- end
193
-
194
- def ask(message)
195
- Ask.new(message)
196
- end
197
-
198
- class HaveInput
199
- def initialize(name, value = nil)
200
- @name = name
201
- @expected = value
202
- end
203
-
204
- def matches?(log)
205
- @actual = log.wait_for_event(EventLog::GotInput).value
206
- @actual == @expected
207
- end
208
-
209
- def failure_message
210
- "expected to have input '#@name' as '#@expected', but got '#@actual'"
211
- end
212
-
213
- def negative_failure_message
214
- "expected not to have input '#@name', but had it as '#@actual'"
215
- end
216
- end
217
-
218
- def have_input(name, value = nil)
219
- HaveInput.new(name, value)
220
- end
221
-
222
- class Output
223
- def initialize(line)
224
- @expected = line
225
- end
226
-
227
- def matches?(log)
228
- @actual = log.wait_for_event(EventLog::Printed).line
229
- @actual == @expected
230
- end
231
-
232
- def failure_message
233
- "expected '#@expected' to be in the output, but got '#@actual'"
234
- end
235
-
236
- def negative_failure_message
237
- "expected '#@expected' NOT to be in the output, but it was"
238
- end
239
- end
240
-
241
- def output(line)
242
- Output.new(line)
243
- end
244
-
245
- class Complete
246
- def matches?(log)
247
- @log = log
248
-
249
- log.process.join(1)
250
-
251
- log.process.status == false
252
- end
253
-
254
- def failure_message
255
- pending = @log.pending_events
256
-
257
- if @exception
258
- "process existed with an exception: #@exception"
259
- elsif !pending.empty?
260
- "expected process to complete, but it's pending events #{pending}"
261
- else
262
- "process is blocked; status: #{@log.process.status}"
263
- end
264
- end
265
-
266
- def negative_failure_message
267
- "expected process to still be running, but it's completed"
268
- end
269
- end
270
-
271
- def complete
272
- Complete.new
273
- end
274
-
275
-
276
- class FailWith
277
- def initialize(exception, predicate = nil)
278
- @expected = exception
279
- @predicate = predicate
280
- end
281
-
282
- def matches?(log)
283
- @actual = log.wait_for_event(EventLog::Raised).exception
284
-
285
- return false unless @actual.is_a?(@expected)
286
-
287
- @predicate.call(@actual) if @predicate
288
-
289
- true
290
- end
291
-
292
- def failure_message
293
- "expected #@expected to be raised, but got #{@actual.class}: '#@actual'"
294
- end
295
-
296
- def negative_failure_message
297
- "expected #@expected to NOT be raised, but it was"
298
- end
299
- end
300
-
301
- def fail_with(exception, &blk)
302
- FailWith.new(exception, blk)
303
- end
304
-
305
-
306
- class ProgressExpectation
307
- def matches?(log)
308
- @actual = log.wait_for_event(EventLog::Progress)
309
- @actual == @expected
310
- end
311
-
312
- def failure_message
313
- "expected to #{@expected.report}, but #{@actual.report_past} instead"
314
- end
315
-
316
- def negative_failure_message
317
- "expected not to #{@expected.report}"
318
- end
319
- end
320
-
321
- class Successfully < ProgressExpectation
322
- def initialize(message)
323
- @expected = EventLog::Did.new(message)
324
- end
325
- end
326
-
327
- class Skip < ProgressExpectation
328
- def initialize(message)
329
- @expected = EventLog::Skipped.new(message)
330
- end
331
- end
332
-
333
- class FailTo < ProgressExpectation
334
- def initialize(message)
335
- @expected = EventLog::FailedTo.new(message)
336
- end
337
- end
338
-
339
- class GiveUp < ProgressExpectation
340
- def initialize(message)
341
- @expected = EventLog::GaveUp.new(message)
342
- end
343
- end
344
-
345
- def successfully(message)
346
- Successfully.new(message)
347
- end
348
-
349
- def skip(message)
350
- Skip.new(message)
351
- end
352
-
353
- def fail_to(message)
354
- FailTo.new(message)
355
- end
356
-
357
- def give_up(message)
358
- GiveUp.new(message)
359
- end
360
-
361
-
362
- def asks(what)
363
- $vmc_event.should ask(what)
364
- end
365
-
366
- def given(what)
367
- $vmc_event.provide("#{what}\n")
368
- end
369
-
370
- def has_input(name, value = nil)
371
- $vmc_event.should have_input(name, value)
372
- end
373
-
374
- def raises(exception, &blk)
375
- $vmc_event.should fail_with(exception, &blk)
376
- end
377
-
378
- def finish
379
- $vmc_event.should complete
380
- end
381
-
382
- def outputs(what)
383
- $vmc_event.should output(what)
384
- end
385
-
386
- def does(what)
387
- $vmc_event.should successfully(what)
388
- end
389
-
390
- def skips(what)
391
- $vmc_event.should skip(what)
392
- end
393
-
394
- def fails_to(what)
395
- $vmc_event.should fail_to(what)
396
- end
397
-
398
- def gives_up(what)
399
- $vmc_event.should give_up(what)
400
- end
401
- end
402
-
403
- RSpec.configure do |c|
404
- c.include VMCHelpers
405
- c.include VMCMatchers
406
-
407
- c.before(:all) do
408
- VMC::CLI.client = CFoundry::Client.new(TARGET)
409
-
410
- client.login(:username => USER, :password => PASSWORD)
411
- client.current_organization = client.organizations.first
412
- client.current_space = client.current_organization.spaces.first
413
- end
414
- end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vmc
3
3
  version: !ruby/object:Gem::Version
4
- hash: -3286034684
4
+ hash: -4008089058
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
9
  - 0
10
10
  - beta
11
- - 33
12
- version: 0.4.0.beta.33
11
+ - 34
12
+ version: 0.4.0.beta.34
13
13
  platform: ruby
14
14
  authors:
15
15
  - VMware
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2012-08-17 00:00:00 Z
20
+ date: 2012-08-21 00:00:00 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: json_pure
@@ -249,12 +249,12 @@ dependencies:
249
249
  requirements:
250
250
  - - ~>
251
251
  - !ruby/object:Gem::Version
252
- hash: 59
252
+ hash: 57
253
253
  segments:
254
254
  - 0
255
255
  - 3
256
- - 20
257
- version: 0.3.20
256
+ - 21
257
+ version: 0.3.21
258
258
  type: :runtime
259
259
  version_requirements: *id014
260
260
  - !ruby/object:Gem::Dependency
@@ -398,6 +398,9 @@ files:
398
398
  - vmc-ng/lib/vmc/errors.rb
399
399
  - vmc-ng/lib/vmc/plugin.rb
400
400
  - vmc-ng/lib/vmc/spacing.rb
401
+ - vmc-ng/lib/vmc/spec_helpers/eventlog.rb
402
+ - vmc-ng/lib/vmc/spec_helpers/patches.rb
403
+ - vmc-ng/lib/vmc/spec_helpers.rb
401
404
  - vmc-ng/lib/vmc/version.rb
402
405
  - vmc-ng/lib/vmc.rb
403
406
  - vmc-ng/spec/app/app_spec.rb
@@ -406,9 +409,7 @@ files:
406
409
  - vmc-ng/spec/assets/hello-sinatra/Gemfile
407
410
  - vmc-ng/spec/assets/hello-sinatra/main.rb
408
411
  - vmc-ng/spec/assets/hello-sinatra/manifest.yml
409
- - vmc-ng/spec/eventlog.rb
410
412
  - vmc-ng/spec/helpers.rb
411
- - vmc-ng/spec/patches.rb
412
413
  - vmc-ng/spec/Rakefile
413
414
  - vmc-ng/spec/start/target_spec.rb
414
415
  - vmc-ng/bin/vmc