manageheroku 0.0.2 → 0.0.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.
- checksums.yaml +4 -4
- data/lib/manageheroku/heroku.rb +30 -3
- data/lib/manageheroku/version.rb +1 -1
- data/test/conf_test.rb +1 -0
- data/test/heroku_test.rb +49 -0
- data/test/test_helper.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b8aa0c4756084dbb1374e23ec4063f00b0a65ef
|
4
|
+
data.tar.gz: 7d3ab4230196e8043445cf19f45b450047bc8b1c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87198db67ae89278903ee28c35bb6401ed340ab8c67b8c47b28568c46967ec384656243375d7fb34496a5b3896872fcc2a2ee3fe6d60b884093f00dc65a32eb9
|
7
|
+
data.tar.gz: 02557908e8f65e50a73433ad64f654efb6a8b3441c5d7a63ae254cef2e159d6c6b4b1d90396e059a90f706a309390b932f7eccb3809ad2e291fd4273858fe1d8
|
data/lib/manageheroku/heroku.rb
CHANGED
@@ -1,14 +1,41 @@
|
|
1
1
|
module Manageheroku
|
2
2
|
class Heroku
|
3
|
-
|
3
|
+
|
4
|
+
attr_reader :errors
|
5
|
+
def initialize(conf_file, api_object=nil)
|
4
6
|
@conf = Manageheroku::Conf.new(conf_file)
|
5
7
|
@formations = @conf.formations
|
6
|
-
@heroku = PlatformAPI.connect_oauth(@conf.oauth_token)
|
8
|
+
@heroku = api_object || PlatformAPI.connect_oauth(@conf.oauth_token)
|
9
|
+
@errors = []
|
7
10
|
end
|
8
11
|
|
9
12
|
def update!
|
10
13
|
@formations.each do |formation|
|
11
|
-
|
14
|
+
begin
|
15
|
+
@heroku.formation.batch_update(*formation.update_params)
|
16
|
+
rescue StandardError => e
|
17
|
+
if e.respond_to?(:response)
|
18
|
+
# errors with a response have good information that you miss in stacktrace form
|
19
|
+
status = e.response.status
|
20
|
+
status_line = e.response.status_line
|
21
|
+
response_body_id = nil
|
22
|
+
response_body_message = nil
|
23
|
+
begin
|
24
|
+
body_hash = JSON.parse(e.response.body)
|
25
|
+
response_body_id = body_hash["id"]
|
26
|
+
response_body_message = body_hash["message"]
|
27
|
+
rescue
|
28
|
+
response_body_message = e.response.body
|
29
|
+
end
|
30
|
+
error_string = <<-OUTPUT
|
31
|
+
Status: #{[status, status_line].join(";")}
|
32
|
+
Body: #{[response_body_id, response_body_message].join(";")}
|
33
|
+
OUTPUT
|
34
|
+
@errors << error_string
|
35
|
+
puts error_string #Heroku logs stdout
|
36
|
+
end
|
37
|
+
raise e
|
38
|
+
end
|
12
39
|
end
|
13
40
|
end
|
14
41
|
|
data/lib/manageheroku/version.rb
CHANGED
data/test/conf_test.rb
CHANGED
data/test/heroku_test.rb
CHANGED
@@ -7,6 +7,55 @@ class HerokuTest < MiniTest::Test
|
|
7
7
|
# heroku = Manageheroku::Heroku.new(conf_file_path)
|
8
8
|
# heroku.update!
|
9
9
|
# end
|
10
|
+
#
|
11
|
+
it "gives rich debug output if exception contains a response" do
|
12
|
+
api_stub = ApiStub422.new
|
13
|
+
conf_file_path = File.join(File.dirname(__FILE__), 'sample_conf.yml')
|
14
|
+
heroku = Manageheroku::Heroku.new(conf_file_path, api_stub)
|
15
|
+
assert_raises(Excon::Errors::UnprocessableEntity) do |exp|
|
16
|
+
heroku.update!
|
17
|
+
heroku.errors.first.must_match /Cannot update the same process twice/
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it "doesn't fail horribly if exception contains a response with no body" do
|
22
|
+
api_stub = ApiStubDegenerateCase.new
|
23
|
+
conf_file_path = File.join(File.dirname(__FILE__), 'sample_conf.yml')
|
24
|
+
heroku = Manageheroku::Heroku.new(conf_file_path, api_stub)
|
25
|
+
assert_raises(Excon::Errors::ServiceUnavailable) do |exp|
|
26
|
+
heroku.update!
|
27
|
+
heroku.errors.first.must_match /500/
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class ApiStub422
|
33
|
+
def formation
|
34
|
+
FormationStub.new
|
35
|
+
end
|
36
|
+
|
37
|
+
class FormationStub
|
38
|
+
def batch_update(*params)
|
39
|
+
response_params = {body: {"id"=>"Invalid params", "message"=>"Cannot update the same process twice"}.to_json,
|
40
|
+
status: "422"
|
41
|
+
}
|
42
|
+
raise Excon::Errors::UnprocessableEntity.new("Oh ye gods!", nil, Excon::Response.new(response_params))
|
43
|
+
end
|
44
|
+
end
|
10
45
|
end
|
46
|
+
|
47
|
+
class ApiStubDegenerateCase
|
48
|
+
def formation
|
49
|
+
FormationStub.new
|
50
|
+
end
|
51
|
+
|
52
|
+
class FormationStub
|
53
|
+
def batch_update(*params)
|
54
|
+
response_params = { status: "503" }
|
55
|
+
raise Excon::Errors::ServiceUnavailable.new("Et tu Heroku?", nil, Excon::Response.new(response_params))
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
11
60
|
end
|
12
61
|
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: manageheroku
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Cronemeyer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: platform-api
|