heroku-api 0.1.0

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.
Files changed (46) hide show
  1. data/.gitignore +4 -0
  2. data/.travis.yml +14 -0
  3. data/Gemfile +4 -0
  4. data/README.md +120 -0
  5. data/Rakefile +23 -0
  6. data/changelog.txt +4 -0
  7. data/heroku-api.gemspec +23 -0
  8. data/lib/heroku-api.rb +1 -0
  9. data/lib/heroku/api.rb +85 -0
  10. data/lib/heroku/api/addons.rb +47 -0
  11. data/lib/heroku/api/apps.rb +62 -0
  12. data/lib/heroku/api/collaborators.rb +33 -0
  13. data/lib/heroku/api/config_vars.rb +33 -0
  14. data/lib/heroku/api/domains.rb +33 -0
  15. data/lib/heroku/api/errors.rb +9 -0
  16. data/lib/heroku/api/keys.rb +42 -0
  17. data/lib/heroku/api/logs.rb +18 -0
  18. data/lib/heroku/api/mock.rb +176 -0
  19. data/lib/heroku/api/mock/addons.rb +153 -0
  20. data/lib/heroku/api/mock/apps.rb +184 -0
  21. data/lib/heroku/api/mock/cache/get_addons.json +1 -0
  22. data/lib/heroku/api/mock/collaborators.rb +55 -0
  23. data/lib/heroku/api/mock/config_vars.rb +46 -0
  24. data/lib/heroku/api/mock/domains.rb +71 -0
  25. data/lib/heroku/api/mock/keys.rb +46 -0
  26. data/lib/heroku/api/mock/logs.rb +20 -0
  27. data/lib/heroku/api/mock/processes.rb +191 -0
  28. data/lib/heroku/api/mock/releases.rb +124 -0
  29. data/lib/heroku/api/mock/stacks.rb +84 -0
  30. data/lib/heroku/api/processes.rb +77 -0
  31. data/lib/heroku/api/releases.rb +33 -0
  32. data/lib/heroku/api/stacks.rb +22 -0
  33. data/lib/heroku/api/vendor/okjson.rb +559 -0
  34. data/lib/heroku/api/version.rb +5 -0
  35. data/test/test_addons.rb +169 -0
  36. data/test/test_apps.rb +119 -0
  37. data/test/test_collaborators.rb +73 -0
  38. data/test/test_config_vars.rb +54 -0
  39. data/test/test_domains.rb +63 -0
  40. data/test/test_helper.rb +35 -0
  41. data/test/test_keys.rb +39 -0
  42. data/test/test_logs.rb +20 -0
  43. data/test/test_processes.rb +245 -0
  44. data/test/test_releases.rb +91 -0
  45. data/test/test_stacks.rb +49 -0
  46. metadata +134 -0
@@ -0,0 +1,35 @@
1
+ require "#{File.dirname(__FILE__)}/../lib/heroku/api"
2
+
3
+ require 'rubygems'
4
+ gem 'minitest' # ensure we are using the gem version
5
+ require 'minitest/autorun'
6
+ require 'time'
7
+
8
+ MOCK = ENV['MOCK'] != 'false'
9
+
10
+ def heroku
11
+ # ENV['HEROKU_API_KEY'] used for :api_key
12
+ Heroku::API.new(:mock => MOCK)
13
+ end
14
+
15
+ def random_name
16
+ "heroku-rb-#{SecureRandom.hex(10)}"
17
+ end
18
+
19
+ def random_email_address
20
+ "email@#{random_name}.com"
21
+ end
22
+
23
+ def with_app(params={}, &block)
24
+ begin
25
+ data = heroku.post_app(params).body
26
+ @name = data['name']
27
+ ready = false
28
+ until ready
29
+ ready = heroku.request(:method => :put, :path => "/apps/#{@name}/status").status == 201
30
+ end
31
+ yield(data)
32
+ ensure
33
+ heroku.delete_app(@name) rescue nil
34
+ end
35
+ end
data/test/test_keys.rb ADDED
@@ -0,0 +1,39 @@
1
+ require "#{File.dirname(__FILE__)}/test_helper"
2
+
3
+ class TestKeys < MiniTest::Unit::TestCase
4
+ KEY_DATA = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCz29znMi/UJX/nvkRSO5FFugKhU9DkkI53E0vXUnP8zeLFxMgyUqmXryPVjWtGzz2LRWqjm14SbqHAmM44pGHVfBIp6wCKBWSUYGv/FxOulwYgtWzz4moxWLZrFyWWgJAnehcVUifHNgzKwT2ovWm2ns52681Z8yFK3K8/uLStDjLIaPePEOaxaTvgIxZNsfyEoXoHcyTPwdR1GtQuDTuDYqYmjmPCoKybYnXrTQ1QFuQxDneBkswQYSl0H2aLf3uBK4F01hr+azXQuSe39eSV4I/TqzmNJlanpILT9Jz3/J1i4r6brpF3AxLnFnb9ufIbzQAIa/VZIulfrZkcBsUl david@carbon.local"
5
+
6
+ def test_delete_key_key_not_found
7
+ assert_raises(Heroku::API::Errors::NotFound) do
8
+ heroku.delete_key(random_name)
9
+ end
10
+ end
11
+
12
+ def test_delete_key
13
+ heroku.post_key(KEY_DATA)
14
+ response = heroku.delete_key('david@carbon.local')
15
+
16
+ assert_equal(200, response.status)
17
+ end
18
+
19
+ def test_delete_keys
20
+ response = heroku.delete_keys
21
+
22
+ assert_equal(200, response.status)
23
+ end
24
+
25
+ def test_get_keys
26
+ response = heroku.get_keys
27
+
28
+ assert_equal(200, response.status)
29
+ end
30
+
31
+ def test_post_key
32
+ response = heroku.post_key(KEY_DATA)
33
+
34
+ assert_equal(200, response.status)
35
+
36
+ heroku.delete_key('david@carbon.local')
37
+ end
38
+
39
+ end
data/test/test_logs.rb ADDED
@@ -0,0 +1,20 @@
1
+ require "#{File.dirname(__FILE__)}/test_helper"
2
+
3
+ class TestLogs < MiniTest::Unit::TestCase
4
+
5
+ def test_get_logs
6
+ with_app do |app_data|
7
+ response = heroku.get_logs(app_data['name'], 'logplex' => true)
8
+
9
+ assert_equal(200, response.status)
10
+ assert_match(%r{^https://logplex\.heroku\.com/sessions/[-a-zA-Z0-9]*\?srv=[0-9]*$}, response.body)
11
+ end
12
+ end
13
+
14
+ def test_get_logs_app_not_found
15
+ assert_raises(Heroku::API::Errors::NotFound) do
16
+ heroku.get_logs(random_name, 'logplex' => true)
17
+ end
18
+ end
19
+
20
+ end
@@ -0,0 +1,245 @@
1
+ require "#{File.dirname(__FILE__)}/test_helper"
2
+
3
+ class TestProcesses < MiniTest::Unit::TestCase
4
+
5
+ def test_get_ps
6
+ with_app do |app_data|
7
+ response = heroku.get_ps(app_data['name'])
8
+ ps = response.body.first
9
+
10
+ assert_equal(200, response.status)
11
+ assert_equal('up', ps['action'])
12
+ assert_equal(app_data['name'], ps['app_name'])
13
+ assert_equal(false, ps['attached'])
14
+ assert_equal('thin -p $PORT -e $RACK_ENV -R $HEROKU_RACK start', ps['command'])
15
+ # elapsed
16
+ # pretty_state
17
+ assert_equal('web.1', ps['process'])
18
+ assert_equal(nil, ps['rendevous_url'])
19
+ assert_equal('NONE', ps['slug'])
20
+ assert_equal('created', ps['state'])
21
+ # transitioned_at
22
+ assert_equal('Dyno', ps['type'])
23
+ # upid
24
+ end
25
+ end
26
+
27
+ def test_get_ps_app_not_found
28
+ assert_raises(Heroku::API::Errors::NotFound) do
29
+ heroku.get_ps(random_name)
30
+ end
31
+ end
32
+
33
+ def test_post_ps
34
+ with_app do |app_data|
35
+ command = 'pwd'
36
+ response = heroku.post_ps(app_data['name'], command)
37
+ ps = response.body
38
+
39
+ assert_equal(200, response.status)
40
+ assert_equal('complete', ps['action'])
41
+ refute(ps['attached'])
42
+ assert_equal(command, ps['command'])
43
+ # elapsed
44
+ # pretty_state
45
+ assert_equal('run.1', ps['process'])
46
+ assert_nil(ps['rendevous_url'])
47
+ assert_equal('NONE', ps['slug'])
48
+ # depending on timing it will be one of these two states
49
+ assert_includes(['created', 'starting'], ps['state'])
50
+ # transitioned_at
51
+ assert_equal('Ps', ps['type'])
52
+ # upid
53
+ end
54
+ end
55
+
56
+ def test_post_ps_with_attach
57
+ with_app do |app_data|
58
+ command = 'pwd'
59
+ response = heroku.post_ps(app_data['name'], command, 'attach' => true)
60
+ ps = response.body
61
+
62
+ assert_equal(200, response.status)
63
+ assert_equal('complete', ps['action'])
64
+ assert(ps['attached'])
65
+ assert_equal(command, ps['command'])
66
+ # elapsed
67
+ # pretty_state
68
+ assert_equal('run.1', ps['process'])
69
+ refute_nil(ps['rendezvous_url'])
70
+ assert_equal('NONE', ps['slug'])
71
+ # depending on timing it will be one of these two states
72
+ assert_includes(['created', 'starting'], ps['state'])
73
+ # transitioned_at
74
+ assert_equal('Ps', ps['type'])
75
+ # upid
76
+ end
77
+ end
78
+
79
+ def test_post_ps_app_not_found
80
+ assert_raises(Heroku::API::Errors::NotFound) do
81
+ heroku.post_ps(random_name, 'pwd')
82
+ end
83
+ end
84
+
85
+ def test_post_ps_restart
86
+ with_app do |app_data|
87
+ response = heroku.post_ps_restart(app_data['name'])
88
+
89
+ assert_equal(200, response.status)
90
+ assert_equal('ok', response.body)
91
+ end
92
+ end
93
+
94
+ def test_post_ps_restart_with_ps
95
+ with_app do |app_data|
96
+ response = heroku.post_ps_restart(app_data['name'], 'ps' => 'web.1')
97
+
98
+ assert_equal(200, response.status)
99
+ assert_equal('ok', response.body)
100
+ end
101
+ end
102
+
103
+ def test_post_ps_restart_with_type
104
+ with_app do |app_data|
105
+ response = heroku.post_ps_restart(app_data['name'], 'type' => 'web')
106
+
107
+ assert_equal(200, response.status)
108
+ assert_equal('ok', response.body)
109
+ end
110
+ end
111
+
112
+ def test_post_ps_restart_app_not_found
113
+ assert_raises(Heroku::API::Errors::NotFound) do
114
+ heroku.post_ps_restart(random_name)
115
+ end
116
+ end
117
+
118
+ def test_post_ps_scale_app_not_found
119
+ assert_raises(Heroku::API::Errors::NotFound) do
120
+ heroku.post_ps_scale(random_name, 'web', 2)
121
+ end
122
+ end
123
+
124
+ def test_post_ps_scale_down
125
+ with_app('stack' => 'cedar') do |app_data|
126
+ heroku.post_ps_scale(app_data['name'], 'web', 2)
127
+ response = heroku.post_ps_scale(app_data['name'], 'web', 1)
128
+
129
+ assert_equal(200, response.status)
130
+ assert_equal(1, response.body)
131
+ end
132
+ end
133
+
134
+ def test_post_ps_scale_type_not_found
135
+ assert_raises(Heroku::API::Errors::Error) do
136
+ with_app('stack' => 'cedar') do |app_data|
137
+ heroku.post_ps_scale(app_data['name'], 'run', 2)
138
+ end
139
+ end
140
+ end
141
+
142
+ def test_post_ps_scale_up
143
+ with_app('stack' => 'cedar') do |app_data|
144
+ response = heroku.post_ps_scale(app_data['name'], 'web', 2)
145
+
146
+ assert_equal(200, response.status)
147
+ assert_equal(2, response.body)
148
+ end
149
+ end
150
+
151
+ def test_post_ps_scale_without_cedar
152
+ assert_raises(Heroku::API::Errors::Error) do
153
+ with_app do |app_data|
154
+ heroku.post_ps_scale(app_data['name'], 'web', 2)
155
+ end
156
+ end
157
+ end
158
+
159
+ def test_post_ps_stop
160
+ assert_raises(Heroku::API::Errors::Error) do
161
+ with_app do |app_data|
162
+ heroku.post_ps_stop(app_data['name'], {})
163
+ end
164
+ end
165
+ end
166
+
167
+ def test_post_ps_stop_with_ps
168
+ with_app do |app_data|
169
+ response = heroku.post_ps_stop(app_data['name'], 'ps' => 'web.1')
170
+
171
+ assert_equal(200, response.status)
172
+ assert_equal('ok', response.body)
173
+ end
174
+ end
175
+
176
+ def test_post_ps_stop_with_type
177
+ with_app do |app_data|
178
+ response = heroku.post_ps_stop(app_data['name'], 'type' => 'web')
179
+
180
+ assert_equal(200, response.status)
181
+ assert_equal('ok', response.body)
182
+ end
183
+ end
184
+
185
+ def test_post_ps_stop_app_not_found
186
+ assert_raises(Heroku::API::Errors::NotFound) do
187
+ heroku.post_ps_stop(random_name, {})
188
+ end
189
+ end
190
+
191
+ def test_put_dynos
192
+ with_app do |app_data|
193
+ dynos = 1
194
+ response = heroku.put_dynos(app_data['name'], dynos)
195
+
196
+ assert_equal(200, response.status)
197
+ assert_equal({
198
+ 'name' => app_data['name'],
199
+ 'dynos' => dynos
200
+ }, response.body)
201
+ end
202
+ end
203
+
204
+ def test_put_dynos_app_not_found
205
+ assert_raises(Heroku::API::Errors::NotFound) do
206
+ heroku.put_dynos(random_name, 1)
207
+ end
208
+ end
209
+
210
+ def test_put_dynos_with_cedar
211
+ assert_raises(Heroku::API::Errors::Error) do
212
+ with_app('stack' => 'cedar') do |app_data|
213
+ heroku.put_dynos(app_data['name'], 2)
214
+ end
215
+ end
216
+ end
217
+
218
+ def test_put_workers
219
+ with_app do |app_data|
220
+ workers = 1
221
+ response = heroku.put_workers(app_data['name'], workers)
222
+
223
+ assert_equal(200, response.status)
224
+ assert_equal({
225
+ 'name' => app_data['name'],
226
+ 'workers' => workers
227
+ }, response.body)
228
+ end
229
+ end
230
+
231
+ def test_put_workers_app_not_found
232
+ assert_raises(Heroku::API::Errors::NotFound) do
233
+ heroku.put_workers(random_name, 1)
234
+ end
235
+ end
236
+
237
+ def test_put_workers_with_cedar
238
+ assert_raises(Heroku::API::Errors::Error) do
239
+ with_app('stack' => 'cedar') do |app_data|
240
+ heroku.put_workers(app_data['name'], 2)
241
+ end
242
+ end
243
+ end
244
+
245
+ end
@@ -0,0 +1,91 @@
1
+ require "#{File.dirname(__FILE__)}/test_helper"
2
+
3
+ class TestReleases < MiniTest::Unit::TestCase
4
+
5
+ def test_get_releases
6
+ with_app do |app_data|
7
+ heroku.post_addon(app_data['name'], 'releases:basic')
8
+ response = heroku.get_releases(app_data['name'])
9
+
10
+ assert_equal(200, response.status)
11
+ # body assertion?
12
+ end
13
+ end
14
+
15
+ def test_get_releases_app_not_found
16
+ assert_raises(Heroku::API::Errors::NotFound) do
17
+ heroku.get_releases(random_name)
18
+ end
19
+ end
20
+
21
+ def test_get_releases_addon_not_installed
22
+ with_app do |app_data|
23
+ assert_raises(Heroku::API::Errors::Error) do
24
+ heroku.get_releases(app_data['name'])
25
+ end
26
+ end
27
+ end
28
+
29
+ def test_get_release
30
+ with_app do |app_data|
31
+ heroku.post_addon(app_data['name'], 'releases:basic')
32
+ current = heroku.get_releases(app_data['name']).body.last['name']
33
+ response = heroku.get_release(app_data['name'], current)
34
+
35
+ assert_equal(200, response.status)
36
+ # body assertion?
37
+ end
38
+ end
39
+
40
+ def test_get_release_app_not_found
41
+ assert_raises(Heroku::API::Errors::NotFound) do
42
+ heroku.get_release(random_name, 'v2')
43
+ end
44
+ end
45
+
46
+ def test_get_release_addon_not_installed
47
+ with_app do |app_data|
48
+ assert_raises(Heroku::API::Errors::Error) do
49
+ heroku.get_release(app_data['name'], 'v2')
50
+ end
51
+ end
52
+ end
53
+
54
+ def test_get_release_release_not_found
55
+ assert_raises(Heroku::API::Errors::NotFound) do
56
+ heroku.get_release(random_name, 'v0')
57
+ end
58
+ end
59
+
60
+ def test_post_release
61
+ with_app do |app_data|
62
+ heroku.post_addon(app_data['name'], 'releases:basic')
63
+ current = heroku.get_releases(app_data['name']).body.last['name']
64
+ response = heroku.post_release(app_data['name'], current)
65
+
66
+ assert_equal(200, response.status)
67
+ # body assertion?
68
+ end
69
+ end
70
+
71
+ def test_post_release_app_not_found
72
+ assert_raises(Heroku::API::Errors::NotFound) do
73
+ heroku.post_release(random_name, 'v3')
74
+ end
75
+ end
76
+
77
+ def test_post_release_addon_not_installed
78
+ with_app do |app_data|
79
+ assert_raises(Heroku::API::Errors::Error) do
80
+ heroku.post_release(app_data['name'], 'v3')
81
+ end
82
+ end
83
+ end
84
+
85
+ def test_post_release_release_not_found
86
+ assert_raises(Heroku::API::Errors::NotFound) do
87
+ heroku.post_release(random_name, 'v0')
88
+ end
89
+ end
90
+
91
+ end
@@ -0,0 +1,49 @@
1
+ require "#{File.dirname(__FILE__)}/test_helper"
2
+
3
+ class TestStacks < MiniTest::Unit::TestCase
4
+
5
+ def test_get_stack
6
+ with_app do |app_data|
7
+ response = heroku.get_stack(app_data['name'])
8
+
9
+ assert_equal(200, response.status)
10
+ end
11
+ end
12
+
13
+ def test_get_stack_app_not_found
14
+ assert_raises(Heroku::API::Errors::NotFound) do
15
+ heroku.get_stack(random_name)
16
+ end
17
+ end
18
+
19
+ def test_put_stack
20
+ with_app do |app_data|
21
+ response = heroku.put_stack(app_data['name'], 'bamboo-ree-1.8.7')
22
+
23
+ assert_equal(200, response.status)
24
+ end
25
+ end
26
+
27
+ def test_put_stack_app_not_found
28
+ assert_raises(Heroku::API::Errors::NotFound) do
29
+ heroku.put_stack(random_name, 'bamboo-ree-1.8.7')
30
+ end
31
+ end
32
+
33
+ def test_put_stack_stack_not_found
34
+ with_app do |app_data|
35
+ assert_raises(Heroku::API::Errors::NotFound) do
36
+ heroku.put_stack(app_data['name'], random_name)
37
+ end
38
+ end
39
+ end
40
+
41
+ def test_put_stack_cedar
42
+ with_app do |app_data|
43
+ assert_raises(Heroku::API::Errors::Error) do
44
+ heroku.put_stack(app_data['name'], 'cedar')
45
+ end
46
+ end
47
+ end
48
+
49
+ end