manageheroku 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c8af28afd8a378ba3db9360b88f200f128d98ccb
4
- data.tar.gz: b5fac04fda4bd793698bca29c908421d136a6d2c
3
+ metadata.gz: 8b8aa0c4756084dbb1374e23ec4063f00b0a65ef
4
+ data.tar.gz: 7d3ab4230196e8043445cf19f45b450047bc8b1c
5
5
  SHA512:
6
- metadata.gz: b1e334fb457f22fb4dd89b93c977b090361a1be2ec0cd5ec04367760d28c26df112d1c3c48b553f2dc5cd887a518e87488159386c7bfca4866bb66d67750adbf
7
- data.tar.gz: 6f35974bc33580d35ae78b67620fbc43ab2f25fd1a9d4d655d424cd187896fab32ddea1f668c0b11c7362b3f1fffd2add26bdc75e703cffee39a2f27123f4d2b
6
+ metadata.gz: 87198db67ae89278903ee28c35bb6401ed340ab8c67b8c47b28568c46967ec384656243375d7fb34496a5b3896872fcc2a2ee3fe6d60b884093f00dc65a32eb9
7
+ data.tar.gz: 02557908e8f65e50a73433ad64f654efb6a8b3441c5d7a63ae254cef2e159d6c6b4b1d90396e059a90f706a309390b932f7eccb3809ad2e291fd4273858fe1d8
@@ -1,14 +1,41 @@
1
1
  module Manageheroku
2
2
  class Heroku
3
- def initialize(conf_file)
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
- @heroku.formation.batch_update(*formation.update_params)
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
 
@@ -1,3 +1,3 @@
1
1
  module Manageheroku
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/test/conf_test.rb CHANGED
@@ -17,6 +17,7 @@ class ConfTest < MiniTest::Test
17
17
  ENV["TEST_VAL"] = "erb_is_great"
18
18
  conf = Manageheroku::Conf.new(File.join(File.dirname(__FILE__), 'sample_conf.yml'))
19
19
  conf.oauth_token.must_equal "erb_is_great"
20
+ ENV["TEST_VAL"] = nil
20
21
  end
21
22
  end
22
23
  end
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
@@ -1,3 +1,4 @@
1
1
  require 'minitest/autorun'
2
2
  require 'manageheroku'
3
+ require 'ostruct'
3
4
 
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.2
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-05 00:00:00.000000000 Z
11
+ date: 2016-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: platform-api