samorau 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -16,7 +16,7 @@ begin
16
16
  gemspec.add_dependency(%q<term-ansicolor>, ["~> 1.0"])
17
17
  gemspec.add_dependency(%q<launchy>, [">= 0.3.2"])
18
18
 
19
- gemspec.version = '0.2.0'
19
+ gemspec.version = '0.3.0'
20
20
  end
21
21
  rescue LoadError
22
22
  puts "Jeweler not available. Install it with: gem install jeweler"
data/bin/samorau CHANGED
@@ -84,11 +84,11 @@ when "test"
84
84
  run ManifestCheck, fn
85
85
  when "provision"
86
86
  run ManifestCheck, fn
87
- run CreateCheck, fn, :async => async, :env => env
87
+ run ProvisionCheck, fn, :async => async, :env => env
88
88
  when "deprovision"
89
89
  id = ARGV.shift || abort("! no id specified; see usage")
90
90
  run ManifestCheck, fn
91
- run DeleteCheck, fn, :id => id, :async => async, :env => env
91
+ run DeprovisionCheck, fn, :id => id, :async => async, :env => env
92
92
  when "sso"
93
93
  id = ARGV.shift || abort("! no id specified; see usage")
94
94
  run ManifestCheck, fn
@@ -10,35 +10,43 @@ module Heroku
10
10
  module Manifest
11
11
 
12
12
  def self.init(filename)
13
- json = Yajl::Encoder.encode(skeleton, :pretty => true)
14
- open(filename, 'w') {|f| f << json }
13
+ open(filename, 'w') {|f| f << skeleton_str }
15
14
  end
16
15
 
17
16
  def self.skeleton
18
- {
19
- "name" => "myaddon",
20
-
21
- "api" => {
22
- "username" => "heroku",
23
- "password" => generate_password,
24
- "sso_salt" => generate_password(40),
25
- "test" => "http://localhost:4567/",
26
- "production" => "https://yourapp.com/",
27
- "config_vars" => ["MYADDON_URL"]
28
- },
29
-
30
- "plans" => [
31
- {
32
- "name" => "Basic",
33
- "price" => "0",
34
- "price_unit" => "month"
35
- }
36
- ]
37
- }
17
+ Yajl::Parser.parse(skeleton_str)
38
18
  end
39
19
 
20
+ def self.skeleton_str
21
+ return <<EOJSON
22
+ {
23
+ "id": "myaddon",
24
+ "name": "My Addon",
25
+ "plans": [
26
+ {
27
+ "id": "basic",
28
+ "name": "Basic",
29
+ "price": "0",
30
+ "price_unit": "month"
31
+ }
32
+ ],
33
+ "api": {
34
+ "config_vars": [
35
+ "MYADDON_URL"
36
+ ],
37
+ "production": "https://yourapp.com/",
38
+ "test": "http://localhost:4567/",
39
+ "username": "heroku",
40
+ "password": "#{generate_password(16)}",
41
+ "sso_salt": "#{generate_password(16)}"
42
+ }
43
+ }
44
+ EOJSON
45
+ end
46
+
47
+ PasswordChars = chars = ['a'..'z', 'A'..'Z', '0'..'9'].map { |r| r.to_a }.flatten
40
48
  def self.generate_password(size=16)
41
- Array.new(size/2) { rand(256) }.pack('C*').unpack('H*').first
49
+ Array.new(size) { PasswordChars[rand(PasswordChars.size)] }.join
42
50
  end
43
51
 
44
52
  end
@@ -116,6 +124,17 @@ module Heroku
116
124
  ValidPriceUnits = %w[month dyno_hour]
117
125
 
118
126
  def call!
127
+ test "manifest id key"
128
+ check "if exists" do
129
+ data.has_key?("id")
130
+ end
131
+ check "is a string" do
132
+ data["id"].is_a?(String)
133
+ end
134
+ check "is not blank" do
135
+ !data["id"].empty?
136
+ end
137
+
119
138
  test "manifest name key"
120
139
  check "if exists" do
121
140
  data.has_key?("name")
@@ -178,6 +197,13 @@ module Heroku
178
197
  check "all plans are a hash" do
179
198
  data["plans"].all? {|plan| plan.is_a?(Hash) }
180
199
  end
200
+ check "all plans must have an id" do
201
+ data["plans"].all? {|plan| plan.has_key?("id") }
202
+ end
203
+ check "all plans have an unique id" do
204
+ ids = data["plans"].map {|plan| plan["id"] }
205
+ ids.size == ids.uniq.size
206
+ end
181
207
  check "all plans have a name" do
182
208
  data["plans"].all? {|plan| plan.has_key?("name") }
183
209
  end
@@ -208,10 +234,10 @@ module Heroku
208
234
  end
209
235
 
210
236
 
211
- class CreateResponseCheck < Check
237
+ class ProvisionResponseCheck < Check
212
238
 
213
239
  def call!
214
- response = data[:create_response]
240
+ response = data[:provision_response]
215
241
  test "response"
216
242
  check "contains an id" do
217
243
  response.has_key?("id")
@@ -304,11 +330,12 @@ module Heroku
304
330
  end
305
331
  end
306
332
 
307
- class CreateCheck < ApiCheck
333
+ class ProvisionCheck < ApiCheck
308
334
  include HTTP
309
335
 
310
336
  READLEN = 1024 * 10
311
337
  APPID = "app123@heroku.com"
338
+ APPNAME = "myapp"
312
339
 
313
340
  def call!
314
341
  json = nil
@@ -322,7 +349,8 @@ module Heroku
322
349
 
323
350
  payload = {
324
351
  :heroku_id => APPID,
325
- :plan => "Basic",
352
+ :appname => APPNAME,
353
+ :plan => @data['plans'].first['id'],
326
354
  :callback_url => callback
327
355
  }
328
356
 
@@ -383,9 +411,9 @@ module Heroku
383
411
  true
384
412
  end
385
413
 
386
- data[:create_response] = response
414
+ data[:provision_response] = response
387
415
 
388
- run CreateResponseCheck, data
416
+ run ProvisionResponseCheck, data
389
417
  end
390
418
 
391
419
  ensure
@@ -394,7 +422,7 @@ module Heroku
394
422
  end
395
423
 
396
424
 
397
- class DeleteCheck < ApiCheck
425
+ class DeprovisionCheck < ApiCheck
398
426
  include HTTP
399
427
 
400
428
  def call!
@@ -492,9 +520,9 @@ module Heroku
492
520
 
493
521
  def call!
494
522
  args = data[:args]
495
- run CreateCheck, data
523
+ run ProvisionCheck, data
496
524
 
497
- response = data[:create_response]
525
+ response = data[:provision_response]
498
526
  data.merge!(:id => response["id"])
499
527
  config = response["config"] || Hash.new
500
528
 
@@ -509,8 +537,7 @@ module Heroku
509
537
  screen.message "End of #{args.first}"
510
538
  end
511
539
 
512
- run SsoCheck, data
513
- run DeleteCheck, data
540
+ run DeprovisionCheck, data
514
541
  end
515
542
 
516
543
  def run_in_env(env)
data/samorau.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{samorau}
8
- s.version = "0.2.0"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Blake Mizerany", "Pedro Belo", "Adam Wiggins"]
12
- s.date = %q{2010-03-04}
12
+ s.date = %q{2010-03-17}
13
13
  s.default_executable = %q{samorau}
14
14
  s.description = %q{}
15
15
  s.email = %q{pedro@heroku.com}
@@ -28,11 +28,11 @@ Gem::Specification.new do |s|
28
28
  "samorau.gemspec",
29
29
  "server.rb",
30
30
  "set-env.sh",
31
- "test/create_check_test.rb",
32
- "test/create_response_check_test.rb",
33
- "test/delete_check.rb",
31
+ "test/deprovision_check.rb",
34
32
  "test/helper.rb",
35
33
  "test/manifest_check_test.rb",
34
+ "test/provision_check_test.rb",
35
+ "test/provision_response_check_test.rb",
36
36
  "test/sso_check_test.rb"
37
37
  ]
38
38
  s.homepage = %q{http://heroku.com}
@@ -41,11 +41,11 @@ Gem::Specification.new do |s|
41
41
  s.rubygems_version = %q{1.3.6}
42
42
  s.summary = %q{}
43
43
  s.test_files = [
44
- "test/create_check_test.rb",
45
- "test/create_response_check_test.rb",
46
- "test/delete_check.rb",
44
+ "test/deprovision_check.rb",
47
45
  "test/helper.rb",
48
46
  "test/manifest_check_test.rb",
47
+ "test/provision_check_test.rb",
48
+ "test/provision_response_check_test.rb",
49
49
  "test/sso_check_test.rb"
50
50
  ]
51
51
 
@@ -1,7 +1,7 @@
1
1
  require File.dirname(__FILE__) + "/helper"
2
2
  require "heroku/samorau"
3
3
 
4
- class DeleteCheckTest < Test::Unit::TestCase
4
+ class DeprovisionCheckTest < Test::Unit::TestCase
5
5
  include Heroku::Samorau
6
6
 
7
7
  setup do
@@ -12,7 +12,7 @@ class DeleteCheckTest < Test::Unit::TestCase
12
12
  ]
13
13
  end
14
14
 
15
- def check ; DeleteCheck ; end
15
+ def check ; DeprovisionCheck ; end
16
16
 
17
17
  test "valid on 200" do
18
18
  assert_valid do |check|
@@ -8,12 +8,23 @@ class ManifestCheckTest < Test::Unit::TestCase
8
8
 
9
9
  setup do
10
10
  @data = Manifest.skeleton
11
+ @data["plans"] << {
12
+ "id" => "advanced",
13
+ "name" => "Advanced",
14
+ "price" => "100",
15
+ "price_unit" => "month"
16
+ }
11
17
  end
12
18
 
13
19
  test "is valid if no errors" do
14
20
  assert_valid
15
21
  end
16
22
 
23
+ test "has an id" do
24
+ @data.delete("id")
25
+ assert_invalid
26
+ end
27
+
17
28
  test "has a name" do
18
29
  @data.delete("name")
19
30
  assert_invalid
@@ -89,13 +100,23 @@ class ManifestCheckTest < Test::Unit::TestCase
89
100
  assert_invalid
90
101
  end
91
102
 
103
+ test "all plans have an id" do
104
+ @data["plans"].first.delete("id")
105
+ assert_invalid
106
+ end
107
+
108
+ test "all plans have an unique id" do
109
+ @data["plans"].first["id"] = @data["plans"].last["id"]
110
+ assert_invalid
111
+ end
112
+
92
113
  test "all plans have a name" do
93
114
  @data["plans"].first.delete("name")
94
115
  assert_invalid
95
116
  end
96
117
 
97
118
  test "all plans have a unique name" do
98
- @data["plans"] << @data["plans"].first.dup
119
+ @data["plans"].first["name"] = @data["plans"].last["name"]
99
120
  assert_invalid
100
121
  end
101
122
 
@@ -1,7 +1,7 @@
1
1
  require File.dirname(__FILE__) + "/helper"
2
2
  require "heroku/samorau"
3
3
 
4
- class CreateCheckTest < Test::Unit::TestCase
4
+ class ProvisionCheckTest < Test::Unit::TestCase
5
5
  include Heroku::Samorau
6
6
 
7
7
  setup do
@@ -12,7 +12,7 @@ class CreateCheckTest < Test::Unit::TestCase
12
12
  ]
13
13
  end
14
14
 
15
- def check ; CreateCheck ; end
15
+ def check ; ProvisionCheck ; end
16
16
 
17
17
  test "valid on 200 for the regular check, and 401 for the auth check" do
18
18
  assert_valid do |check|
@@ -34,7 +34,7 @@ class CreateCheckTest < Test::Unit::TestCase
34
34
  end
35
35
  end
36
36
 
37
- test "runs create response check" do
37
+ test "runs provision response check" do
38
38
  @responses[0] = [200, to_json({ :noid => 456 })]
39
39
  assert_invalid do |check|
40
40
  stub :post, check, @responses
@@ -1,14 +1,14 @@
1
1
  require File.dirname(__FILE__) + "/helper"
2
2
  require 'heroku/samorau'
3
3
 
4
- class CreateResponseCheckTest < Test::Unit::TestCase
4
+ class ProvisionResponseCheckTest < Test::Unit::TestCase
5
5
  include Heroku::Samorau
6
6
 
7
- def check ; CreateResponseCheck ; end
7
+ def check ; ProvisionResponseCheck ; end
8
8
 
9
9
  setup do
10
10
  @response = { "id" => "123" }
11
- @data = Manifest.skeleton.merge(:create_response => @response)
11
+ @data = Manifest.skeleton.merge(:provision_response => @response)
12
12
  end
13
13
 
14
14
  test "is valid if no errors" do
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
7
+ - 3
8
8
  - 0
9
- version: 0.2.0
9
+ version: 0.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Blake Mizerany
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-03-04 00:00:00 -08:00
19
+ date: 2010-03-17 00:00:00 -07:00
20
20
  default_executable: samorau
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -129,11 +129,11 @@ files:
129
129
  - samorau.gemspec
130
130
  - server.rb
131
131
  - set-env.sh
132
- - test/create_check_test.rb
133
- - test/create_response_check_test.rb
134
- - test/delete_check.rb
132
+ - test/deprovision_check.rb
135
133
  - test/helper.rb
136
134
  - test/manifest_check_test.rb
135
+ - test/provision_check_test.rb
136
+ - test/provision_response_check_test.rb
137
137
  - test/sso_check_test.rb
138
138
  has_rdoc: true
139
139
  homepage: http://heroku.com
@@ -166,9 +166,9 @@ signing_key:
166
166
  specification_version: 3
167
167
  summary: ""
168
168
  test_files:
169
- - test/create_check_test.rb
170
- - test/create_response_check_test.rb
171
- - test/delete_check.rb
169
+ - test/deprovision_check.rb
172
170
  - test/helper.rb
173
171
  - test/manifest_check_test.rb
172
+ - test/provision_check_test.rb
173
+ - test/provision_response_check_test.rb
174
174
  - test/sso_check_test.rb