hyperb 0.2.1 → 0.2.2

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 (73) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +12 -0
  3. data/.gitignore +12 -0
  4. data/.rspec +2 -0
  5. data/.rubocop.yml +41 -0
  6. data/Dockerfile +7 -0
  7. data/Gemfile +16 -0
  8. data/LICENSE.txt +21 -0
  9. data/Makefile +16 -0
  10. data/README.md +188 -0
  11. data/Rakefile +24 -0
  12. data/circle.yml +13 -0
  13. data/examples/README.md +367 -0
  14. data/examples/auth-gcr-registry.md +19 -0
  15. data/examples/compose.md +75 -0
  16. data/examples/handling-errors.md +54 -0
  17. data/examples/streaming-logs.md +28 -0
  18. data/examples/streaming-stats.md +25 -0
  19. data/hyperb.gemspec +30 -0
  20. data/lib/hyperb.rb +4 -0
  21. data/lib/hyperb/api.rb +22 -0
  22. data/lib/hyperb/auth_object.rb +42 -0
  23. data/lib/hyperb/client.rb +32 -0
  24. data/lib/hyperb/compose/compose.rb +116 -0
  25. data/lib/hyperb/containers/container.rb +27 -0
  26. data/lib/hyperb/containers/containers.rb +251 -0
  27. data/lib/hyperb/error.rb +44 -0
  28. data/lib/hyperb/hyper_version.rb +12 -0
  29. data/lib/hyperb/images/image.rb +13 -0
  30. data/lib/hyperb/images/images.rb +108 -0
  31. data/lib/hyperb/network/fips.rb +102 -0
  32. data/lib/hyperb/request.rb +129 -0
  33. data/lib/hyperb/services/services.rb +59 -0
  34. data/lib/hyperb/snapshots/snapshot.rb +12 -0
  35. data/lib/hyperb/snapshots/snapshots.rb +39 -0
  36. data/lib/hyperb/utils.rb +39 -0
  37. data/lib/hyperb/version.rb +3 -0
  38. data/lib/hyperb/volumes/volume.rb +16 -0
  39. data/lib/hyperb/volumes/volumes.rb +67 -0
  40. data/spec/auth_object_spec.rb +45 -0
  41. data/spec/client_spec.rb +27 -0
  42. data/spec/compose_spec.rb +145 -0
  43. data/spec/container_spec.rb +25 -0
  44. data/spec/containers_spec.rb +442 -0
  45. data/spec/create_snapshot.rb +30 -0
  46. data/spec/error_spec.rb +18 -0
  47. data/spec/fixtures/auth_obj.json +12 -0
  48. data/spec/fixtures/compose_rm.json +1 -0
  49. data/spec/fixtures/compose_up.json +1 -0
  50. data/spec/fixtures/container_stats.json +78 -0
  51. data/spec/fixtures/containers.json +160 -0
  52. data/spec/fixtures/create_container.json +4 -0
  53. data/spec/fixtures/create_image.json +1 -0
  54. data/spec/fixtures/create_service.json +35 -0
  55. data/spec/fixtures/create_snapshot.json +8 -0
  56. data/spec/fixtures/fip_allocate.json +7 -0
  57. data/spec/fixtures/fips_ls.json +14 -0
  58. data/spec/fixtures/images.json +32 -0
  59. data/spec/fixtures/inspect_container.json +159 -0
  60. data/spec/fixtures/inspect_image.json +89 -0
  61. data/spec/fixtures/inspect_volume.json +11 -0
  62. data/spec/fixtures/remove_container.json +1 -0
  63. data/spec/fixtures/remove_image.json +5 -0
  64. data/spec/fixtures/volumes.json +13 -0
  65. data/spec/helper.rb +36 -0
  66. data/spec/image_spec.rb +17 -0
  67. data/spec/images_spec.rb +133 -0
  68. data/spec/network_spec.rb +106 -0
  69. data/spec/request_spec.rb +41 -0
  70. data/spec/services_spec.rb +193 -0
  71. data/spec/version_spec.rb +7 -0
  72. data/spec/volumes_spec.rb +88 -0
  73. metadata +74 -3
@@ -0,0 +1,45 @@
1
+ require 'helper'
2
+
3
+ RSpec.describe Hyperb::AuthObject do
4
+
5
+ it '#valid? with invalid object' do
6
+ auth_object = Hyperb::AuthObject.new(username: '')
7
+ expect(auth_object.valid?).to be false
8
+ end
9
+
10
+ it '#valid? with valid object' do
11
+ auth_object = Hyperb::AuthObject.new(username: 'l', email: 't@t.com', password: fixture('auth_obj.json'), serveraddress: 'https://gcr.io')
12
+ expect(auth_object.valid?).to be true
13
+ end
14
+
15
+ it '#attrs' do
16
+ auth_object = Hyperb::AuthObject.new(username: 'l', email: 't@t.com', password: fixture('auth_obj.json'), serveraddress: 'https://gcr.io')
17
+ expect(auth_object.attrs).to be_a Hash
18
+ expect(auth_object.attrs[:username]).to eql('l')
19
+ expect(auth_object.attrs[:email]).to eql('t@t.com')
20
+ expect(auth_object.attrs[:password]).to eql(fixture('auth_obj.json').read)
21
+ expect(auth_object.attrs[:serveraddress]).to eql('https://gcr.io')
22
+ end
23
+
24
+ it '#password should read contents of file when File' do
25
+ auth_object = Hyperb::AuthObject.new(username: 'l', email: 't@t.com', password: fixture('auth_obj.json'))
26
+ expect(auth_object.attrs[:password]).to eql(fixture('auth_obj.json').read)
27
+ end
28
+
29
+ it '#password should also accept a String' do
30
+ auth_object = Hyperb::AuthObject.new(username: 'l', email: 't@t.com', password: fixture('auth_obj.json').read)
31
+ expect(auth_object.attrs[:password]).to eql(fixture('auth_obj.json').read)
32
+ end
33
+
34
+ it '#encode' do
35
+ auth_object = Hyperb::AuthObject.new(username: 'l', email: 't@t.com', password: fixture('auth_obj.json'))
36
+ expect(auth_object.encode).not_to be nil
37
+ end
38
+
39
+ it '#build' do
40
+ auth_object = Hyperb::AuthObject.new(username: 'l', email: 't@t.com', password: fixture('auth_obj.json'))
41
+ expect(auth_object.build).to be_a Hash
42
+ expect(auth_object.build.has_key?(:x_registry_auth)).to be true
43
+ end
44
+
45
+ end
@@ -0,0 +1,27 @@
1
+ require "helper"
2
+
3
+ RSpec.describe Hyperb::Client do
4
+
5
+ it 'simple init' do
6
+ client = Hyperb::Client.new do |c|
7
+ c.access_key = 'k'
8
+ c.secret_key = 's'
9
+ end
10
+ expect(client.access_key).to eq 'k'
11
+ expect(client.secret_key).to eq 's'
12
+ end
13
+
14
+ describe '#credentials?' do
15
+
16
+ it 'returns true if all credentials are set' do
17
+ client = Hyperb::Client.new(secret_key: 'SK', access_key: 'AK')
18
+ expect(client.credentials?).to be true
19
+ end
20
+
21
+ it 'returns false if some credential is not set' do
22
+ client = Hyperb::Client.new(secret_key: 'SK')
23
+ expect(client.credentials?).to be false
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,145 @@
1
+ require 'helper'
2
+ require 'http'
3
+
4
+ RSpec.describe Hyperb::Compose do
5
+
6
+ before do
7
+ @client = Hyperb::Client.new(access_key: 'key', secret_key: '123')
8
+ @base_path = Hyperb::Request::BASE_URL + Hyperb::Request::VERSION + '/compose/'
9
+ end
10
+
11
+ describe '#compose_down' do
12
+
13
+ it 'should raise ArgumentError when project is not provided' do
14
+ expect { @client.compose_down }.to raise_error(ArgumentError)
15
+ end
16
+
17
+ it 'request to the correct path should be made' do
18
+ path = @base_path + 'down?project=app'
19
+ stub_request(:post, path)
20
+ .to_return(body: "")
21
+
22
+ @client.compose_down(project: 'app')
23
+ expect(a_request(:post, path)).to have_been_made
24
+ end
25
+
26
+ it 'request to the correct path should be made with rmi' do
27
+ path = @base_path + 'down?project=app&rmi=all'
28
+ stub_request(:post, path)
29
+ .to_return(body: "")
30
+
31
+ @client.compose_down(project: 'app', rmi: 'all')
32
+ expect(a_request(:post, path)).to have_been_made
33
+ end
34
+
35
+ it 'request to the correct path should be made with rmi' do
36
+ path = @base_path + 'down?project=app&rmi=local'
37
+ stub_request(:post, path)
38
+ .to_return(body: "")
39
+
40
+ @client.compose_down(project: 'app', rmi: 'local')
41
+ expect(a_request(:post, path)).to have_been_made
42
+ end
43
+
44
+ it 'request to the correct path should be made with rmorphans' do
45
+ path = @base_path + 'down?project=app&rmorphans=true'
46
+ stub_request(:post, path)
47
+ .to_return(body: "")
48
+
49
+ @client.compose_down(project: 'app', rmorphans: true)
50
+ expect(a_request(:post, path)).to have_been_made
51
+ end
52
+
53
+ it 'request to the correct path should be made with rmorphans' do
54
+ path = @base_path + 'down?project=app&vol=true'
55
+ stub_request(:post, path)
56
+ .to_return(body: "")
57
+
58
+ @client.compose_down(project: 'app', vol: true)
59
+ expect(a_request(:post, path)).to have_been_made
60
+ end
61
+
62
+ end
63
+
64
+ describe '#compose_create' do
65
+
66
+ before do
67
+ @serviceconfigs = {
68
+ 'web': {
69
+ 'image': 'rails'
70
+ },
71
+ 'db': {
72
+ 'image': 'mariadb'
73
+ }
74
+ }
75
+ end
76
+
77
+ it 'should raise ArgumentError when project is not provided' do
78
+ expect { @client.compose_create }.to raise_error(ArgumentError)
79
+ end
80
+
81
+ it 'request to the correct path should be made' do
82
+ path = @base_path + 'create?project=app'
83
+ stub_request(:post, path)
84
+ .to_return(body: fixture('compose_up.json'))
85
+
86
+ @client.compose_create(project: 'app', serviceconfigs: @serviceconfigs)
87
+ expect(a_request(:post, path)).to have_been_made
88
+ end
89
+ end
90
+
91
+ describe '#compose_up' do
92
+
93
+ before do
94
+ @serviceconfigs = {
95
+ 'web': {
96
+ 'image': 'rails'
97
+ },
98
+ 'db': {
99
+ 'image': 'mariadb'
100
+ }
101
+ }
102
+ end
103
+
104
+ it 'should raise ArgumentError when project is not provided' do
105
+ expect { @client.compose_up }.to raise_error(ArgumentError)
106
+ end
107
+
108
+ it 'request to the correct path should be made' do
109
+ path = @base_path + 'up?project=app'
110
+ stub_request(:post, path)
111
+ .to_return(body: fixture('compose_up.json'))
112
+
113
+ @client.compose_up(project: 'app', serviceconfigs: @serviceconfigs)
114
+ expect(a_request(:post, path)).to have_been_made
115
+ end
116
+ end
117
+
118
+ describe '#compose_rm' do
119
+
120
+ it 'should raise ArgumentError when project is not provided' do
121
+ expect { @client.compose_rm }.to raise_error(ArgumentError)
122
+ end
123
+
124
+ it 'correct request should be made' do
125
+ path = @base_path + 'rm?project=blog'
126
+
127
+ stub_request(:post, path)
128
+ .to_return(body: fixture('compose_rm.json'))
129
+
130
+ @client.compose_rm(project: 'blog')
131
+ expect(a_request(:post, path)).to have_been_made
132
+ end
133
+
134
+ it 'correct request should be made with rmvol' do
135
+ path = @base_path + 'rm?project=blog&rmvol=true'
136
+
137
+ stub_request(:post, path)
138
+ .to_return(body: fixture('compose_rm.json'))
139
+
140
+ @client.compose_rm(project: 'blog', rmvol: true)
141
+ expect(a_request(:post, path)).to have_been_made
142
+ end
143
+
144
+ end
145
+ end
@@ -0,0 +1,25 @@
1
+ require 'helper'
2
+
3
+ RSpec.describe Hyperb::Container do
4
+
5
+ describe '#created' do
6
+
7
+ it 'returns timestamp when created is set' do
8
+ container = Hyperb::Container.new(id: '736cbb24edca6b366feb9975aaf34f330ba0d02b181d5227f8acb4a162b8fb44', created: 1420064636)
9
+ expect(container.created).to be_a Fixnum
10
+ end
11
+
12
+ it 'returns nil when created is not set' do
13
+ container = Hyperb::Container.new(id: 1)
14
+ expect(container.created).to be_nil
15
+ end
16
+ end
17
+
18
+ describe '#running?' do
19
+ it 'returns false if container is not running' do
20
+ container = Hyperb::Container.new(id: 1, state: 'stopped')
21
+ expect(container.running?).to be false
22
+ end
23
+ end
24
+
25
+ end
@@ -0,0 +1,442 @@
1
+ require 'helper'
2
+ require 'http'
3
+
4
+ RSpec.describe Hyperb::Containers do
5
+
6
+ before do
7
+ @client = Hyperb::Client.new(access_key: 'key', secret_key: '123')
8
+
9
+ @containers_base_path = Hyperb::Request::BASE_URL + Hyperb::Request::VERSION + '/containers/'
10
+ @containers_path = @containers_base_path + 'json'
11
+ @remove_container_path = @containers_base_path
12
+ @create_container_path = @containers_base_path + 'create'
13
+ end
14
+
15
+ describe '#containers' do
16
+
17
+ it 'request to the correct path should be made' do
18
+
19
+ stub_request(:get, @containers_path)
20
+ .to_return(body: fixture('containers.json'))
21
+
22
+ @client.containers
23
+ expect(a_request(:get, @containers_path)).to have_been_made
24
+ end
25
+
26
+ it 'request to the correct path should be made with all=true' do
27
+ stub_request(:get, @containers_path + '?all=true')
28
+ .to_return(body: fixture('containers.json'))
29
+
30
+ @client.containers(all: true)
31
+ expect(a_request(:get, @containers_path + '?all=true')).to have_been_made
32
+ end
33
+
34
+ it 'request to the correct path should be made with limit=5' do
35
+ stub_request(:get, @containers_path + '?limit=5')
36
+ .to_return(body: fixture('containers.json'))
37
+
38
+ @client.containers(limit: 5)
39
+ expect(a_request(:get, @containers_path + '?limit=5')).to have_been_made
40
+ end
41
+
42
+ it 'request to the correct path should be made with since=someId' do
43
+ stub_request(:get, @containers_path + '?since=3afff57')
44
+ .to_return(body: fixture('containers.json'))
45
+
46
+ @client.containers(since: '3afff57')
47
+ expect(a_request(:get, @containers_path + '?since=3afff57')).to have_been_made
48
+ end
49
+
50
+ it 'request to the correct path should be made with before=someId' do
51
+ stub_request(:get, @containers_path + '?before=3afff57')
52
+ .to_return(body: fixture('containers.json'))
53
+
54
+ @client.containers(before: '3afff57')
55
+ expect(a_request(:get, @containers_path + '?before=3afff57')).to have_been_made
56
+ end
57
+
58
+ it 'request to the correct path should be made with all=true and since=someId' do
59
+ stub_request(:get, @containers_path + '?all=true&since=3afff57')
60
+ .to_return(body: fixture('containers.json'))
61
+
62
+ @client.containers(all: true, since: '3afff57')
63
+ expect(a_request(:get, @containers_path + '?all=true&since=3afff57')).to have_been_made
64
+ end
65
+
66
+ it 'request to the correct path should be made with size=true' do
67
+ stub_request(:get, @containers_path + '?size=true')
68
+ .to_return(body: fixture('containers.json'))
69
+
70
+ @client.containers(size: true)
71
+ expect(a_request(:get, @containers_path + '?size=true')).to have_been_made
72
+ end
73
+
74
+ it 'return array of containers' do
75
+ stub_request(:get, @containers_path + '?all=true')
76
+ .to_return(body: fixture('containers.json'))
77
+
78
+ containers = @client.containers(all: true)
79
+ expect(containers).to be_a Array
80
+ expect(containers[0]).to be_a Hyperb::Container
81
+ end
82
+
83
+ it 'correct attrs' do
84
+ stub_request(:get, @containers_path)
85
+ .to_return(body: fixture('containers.json'))
86
+
87
+ @client.containers.each do |container|
88
+ expect(container.id).to be_a String
89
+ expect(container.created).to be_a Fixnum
90
+ expect(container.command).to be_a String
91
+ expect(container.networksettings).to be_a Hash
92
+ expect(container.hostconfig).to be_a Hash
93
+ end
94
+ end
95
+ end
96
+
97
+ describe '#inspect_container' do
98
+
99
+ before do
100
+ stub_request(:get, @containers_base_path + 'name/json')
101
+ .to_return(body: fixture('inspect_container.json'))
102
+ end
103
+
104
+ it 'should raise ArgumentError when id is missing' do
105
+ expect { @client.inspect_container }.to raise_error(ArgumentError)
106
+ end
107
+
108
+ it 'request to the correct path should be made' do
109
+ @client.inspect_container id: 'name'
110
+ expect(a_request(:get, @containers_base_path + 'name/json')).to have_been_made
111
+ end
112
+
113
+ it 'return a hash with symbolized attrs' do
114
+ res = @client.inspect_container(id: 'name')
115
+ expect(res).to be_a Hash
116
+ expect(res.has_key?(:args)).to be true
117
+ expect(res.has_key?(:config)).to be true
118
+ expect(res.has_key?(:created)).to be true
119
+ end
120
+
121
+ end
122
+
123
+ describe '#remove_container' do
124
+
125
+ it 'should raise ArgumentError when id is not provided' do
126
+ stub_request(:delete, @remove_container_path)
127
+ .to_return(body: fixture('remove_container.json'))
128
+
129
+ expect { @client.remove_container }.to raise_error(ArgumentError)
130
+ end
131
+
132
+ it 'request to the correct path should be made with id=fffff' do
133
+ stub_request(:delete, @remove_container_path + 'fffff')
134
+ .to_return(body: fixture('remove_container.json'))
135
+
136
+ @client.remove_container(id: 'fffff')
137
+ expect(a_request(:delete, @remove_container_path + 'fffff')).to have_been_made
138
+ end
139
+
140
+ it 'request to the correct path should be made with force=true' do
141
+ stub_request(:delete, @remove_container_path + 'fffff?force=true')
142
+ .to_return(body: fixture('remove_container.json'))
143
+
144
+ @client.remove_container(id: 'fffff', force: true)
145
+ expect(a_request(:delete, @remove_container_path + 'fffff?force=true')).to have_been_made
146
+ end
147
+
148
+ it 'request to the correct path should be made with v=true' do
149
+ stub_request(:delete, @remove_container_path + 'fffff?v=true')
150
+ .to_return(body: fixture('remove_container.json'))
151
+
152
+ @client.remove_container(id: 'fffff', v: true)
153
+ expect(a_request(:delete, @remove_container_path + 'fffff?v=true')).to have_been_made
154
+ end
155
+
156
+ it 'request to the correct path should be made with v=true and force=true' do
157
+ stub_request(:delete, @remove_container_path + 'fffff?force=true&v=true')
158
+ .to_return(body: fixture('remove_container.json'))
159
+
160
+ @client.remove_container(id: 'fffff', v: true, force: true)
161
+ expect(a_request(:delete, @remove_container_path + 'fffff?force=true&v=true')).to have_been_made
162
+ end
163
+ end
164
+
165
+ describe '#create_container' do
166
+
167
+ it 'should raise ArgumentError when image is not provided' do
168
+ stub_request(:post, @create_container_path)
169
+ .to_return(body: fixture('create_container.json'))
170
+
171
+ expect { @client.create_container }.to raise_error(ArgumentError)
172
+ end
173
+
174
+ it 'request to the correct path should be made with name' do
175
+ stub_request(:post, @create_container_path + '?name=container_name')
176
+ .with(body: { image: 'image', labels: { sh_hyper_instancetype: 's1' } })
177
+ .to_return(body: fixture('create_container.json'))
178
+
179
+ @client.create_container(image: 'image', name: 'container_name')
180
+ expect(a_request(:post, @create_container_path + '?name=container_name')).to have_been_made
181
+ end
182
+
183
+ it 'correct request should be made with hostname' do
184
+ path = @create_container_path + '?name=container_name'
185
+
186
+ stub_request(:post, path)
187
+ .with(body: { image: 'image', hostname: 'hostnamy', labels: { sh_hyper_instancetype: 's1' }})
188
+ .to_return(body: fixture('create_container.json'))
189
+
190
+ @client.create_container(image: 'image', name: 'container_name', hostname: 'hostnamy')
191
+ expect(a_request(:post, path)
192
+ .with(body: { image: 'image', hostname: 'hostnamy', labels: { sh_hyper_instancetype: 's1' }})).to have_been_made
193
+ end
194
+
195
+ it 'correct request should be made with entrypoint' do
196
+ path = @create_container_path
197
+
198
+ stub_request(:post, path)
199
+ .with(body: { image: 'image', entrypoint: 'test entry', labels: { sh_hyper_instancetype: 's1' }})
200
+ .to_return(body: fixture('create_container.json'))
201
+
202
+ @client.create_container(image: 'image', entrypoint: 'test entry')
203
+ expect(a_request(:post, path)
204
+ .with(body: { image: 'image', entrypoint: 'test entry', labels: { sh_hyper_instancetype: 's1' } })).to have_been_made
205
+ end
206
+
207
+ it 'correct request should be made with cmd' do
208
+ path = @create_container_path
209
+
210
+ stub_request(:post, path)
211
+ .with(body: { image: 'image', cmd: 'test cmd', labels: { sh_hyper_instancetype: 's1' } })
212
+ .to_return(body: fixture('create_container.json'))
213
+
214
+ @client.create_container(image: 'image', cmd: 'test cmd')
215
+ expect(a_request(:post, path)
216
+ .with(body: { image: 'image', cmd: 'test cmd', labels: { sh_hyper_instancetype: 's1' } })).to have_been_made
217
+ end
218
+
219
+ it 'correct request should be made with network mode' do
220
+ path = @create_container_path
221
+
222
+ stub_request(:post, path)
223
+ .with(body: { image: 'image', networkmode: 'bridge', labels: { sh_hyper_instancetype: 's1' } })
224
+ .to_return(body: fixture('create_container.json'))
225
+
226
+ @client.create_container(image: 'image', networkmode: 'bridge')
227
+ expect(a_request(:post, path)
228
+ .with(body: { image: 'image', networkmode: 'bridge', labels: { sh_hyper_instancetype: 's1' } })).to have_been_made
229
+ end
230
+
231
+ it 'correct request should be made with mounts' do
232
+ path = @create_container_path
233
+
234
+ stub_request(:post, path)
235
+ .with(body: { image: 'image', mounts: [], labels: { sh_hyper_instancetype: 's1' } })
236
+ .to_return(body: fixture('create_container.json'))
237
+
238
+ @client.create_container(image: 'image', mounts: [])
239
+ expect(a_request(:post, path)
240
+ .with(body: { image: 'image', mounts: [], labels: { sh_hyper_instancetype: 's1' } })).to have_been_made
241
+ end
242
+
243
+ it 'correct request should be made with exposed ports' do
244
+ path = @create_container_path
245
+
246
+ stub_request(:post, path)
247
+ .with(body: { image: 'image', exposedports: { '22/tcp': {} }, labels: { sh_hyper_instancetype: 's1' } })
248
+ .to_return(body: fixture('create_container.json'))
249
+
250
+ @client.create_container(image: 'image', exposedports: { '22/tcp': {} })
251
+ expect(a_request(:post, path)
252
+ .with(body: { image: 'image', exposedports: { '22/tcp': {} }, labels: { sh_hyper_instancetype: 's1' } })).to have_been_made
253
+ end
254
+
255
+ it 'correct request should be made with workingdir' do
256
+ path = @create_container_path
257
+
258
+ stub_request(:post, path)
259
+ .with(body: { image: 'image', workingdir: '/path/', labels: { sh_hyper_instancetype: 's1' } })
260
+ .to_return(body: fixture('create_container.json'))
261
+
262
+ @client.create_container(image: 'image', workingdir: '/path/')
263
+ expect(a_request(:post, path)
264
+ .with(body: { image: 'image', workingdir: '/path/', labels: { sh_hyper_instancetype: 's1' } })).to have_been_made
265
+ end
266
+ end
267
+
268
+ describe '#start_container' do
269
+
270
+ it 'should raise ArgumentError when id is not provided' do
271
+ expect { @client.start_container }.to raise_error(ArgumentError)
272
+ end
273
+
274
+ it 'correct request should be made' do
275
+ path = @containers_base_path + 'id/start'
276
+
277
+ stub_request(:post, path)
278
+ .to_return(body: "")
279
+
280
+ @client.start_container(id: 'id')
281
+ expect(a_request(:post, path)
282
+ .with(body: "")).to have_been_made
283
+ end
284
+
285
+ end
286
+
287
+ describe '#container_logs' do
288
+
289
+ it 'should raise ArgumentError when id is not provided' do
290
+ expect { @client.container_logs }.to raise_error(ArgumentError)
291
+ end
292
+
293
+ it 'correct request should be made with follow' do
294
+ path = @containers_base_path + 'id/logs?follow=true'
295
+
296
+ stub_request(:get, path)
297
+ .to_return(body: "")
298
+
299
+ @client.container_logs(id: 'id', follow: true)
300
+ expect(a_request(:get, path)
301
+ .with(body: "")).to have_been_made
302
+ end
303
+
304
+ it 'correct request should be made with stderr' do
305
+ path = @containers_base_path + 'id/logs?stderr=true'
306
+
307
+ stub_request(:get, path)
308
+ .to_return(body: "")
309
+
310
+ @client.container_logs(id: 'id', stderr: true)
311
+ expect(a_request(:get, path)
312
+ .with(body: "")).to have_been_made
313
+ end
314
+
315
+ it 'correct request should be made with since' do
316
+ path = @containers_base_path + 'id/logs?since=someid'
317
+
318
+ stub_request(:get, path)
319
+ .to_return(body: "")
320
+
321
+ @client.container_logs(id: 'id', since: 'someid')
322
+ expect(a_request(:get, path)
323
+ .with(body: "")).to have_been_made
324
+ end
325
+
326
+ it 'correct request should be made with timestamps' do
327
+ path = @containers_base_path + 'id/logs?timestamps=true'
328
+
329
+ stub_request(:get, path)
330
+ .to_return(body: "")
331
+
332
+ @client.container_logs(id: 'id', timestamps: true)
333
+ expect(a_request(:get, path)
334
+ .with(body: "")).to have_been_made
335
+ end
336
+ end
337
+
338
+ describe '#stop_container' do
339
+
340
+ it 'should raise ArgumentError when id is not provided' do
341
+ expect { @client.stop_container }.to raise_error(ArgumentError)
342
+ end
343
+
344
+ it 'correct request should be made' do
345
+ path = @containers_base_path + 'id/stop'
346
+
347
+ stub_request(:post, path)
348
+ .to_return(body: "")
349
+
350
+ @client.stop_container(id: 'id')
351
+ expect(a_request(:post, path)
352
+ .with(body: "")).to have_been_made
353
+ end
354
+
355
+ it 'correct request should be made with t' do
356
+ path = @containers_base_path + 'id/stop?t=50'
357
+
358
+ stub_request(:post, path)
359
+ .to_return(body: "")
360
+
361
+ @client.stop_container(id: 'id', t: 50)
362
+ expect(a_request(:post, path)
363
+ .with(body: "")).to have_been_made
364
+ end
365
+ end
366
+
367
+ describe '#container_stats' do
368
+
369
+ it 'should raise ArgumentError when id is not provided' do
370
+ expect { @client.container_stats }.to raise_error(ArgumentError)
371
+ end
372
+
373
+ it 'correct request should be made' do
374
+ path = @containers_base_path + 'id/stats'
375
+
376
+ stub_request(:get, path)
377
+ .to_return(body: fixture('container_stats.json'))
378
+
379
+ @client.container_stats(id: 'id')
380
+ expect(a_request(:get, path)).to have_been_made
381
+ end
382
+
383
+ it 'correct request should be made with stream' do
384
+ path = @containers_base_path + 'id/stats?stream=false'
385
+
386
+ stub_request(:get, path)
387
+ .to_return(body: fixture('container_stats.json'))
388
+
389
+ @client.container_stats(id: 'id', stream: false)
390
+ expect(a_request(:get, path)).to have_been_made
391
+ end
392
+
393
+ end
394
+
395
+ describe '#kill_container' do
396
+
397
+ it 'should raise ArgumentError when id is not provided' do
398
+ expect { @client.kill_container }.to raise_error(ArgumentError)
399
+ end
400
+
401
+ it 'correct request should be made' do
402
+ path = @containers_base_path + 'id/kill'
403
+
404
+ stub_request(:post, path)
405
+ .to_return(body: "")
406
+
407
+ @client.kill_container(id: 'id')
408
+ expect(a_request(:post, path)).to have_been_made
409
+ end
410
+
411
+ it 'correct request should be made with signal' do
412
+ path = @containers_base_path + 'id/kill?signal=signal'
413
+
414
+ stub_request(:post, path)
415
+ .to_return(body: "")
416
+
417
+ @client.kill_container(id: 'id', signal: 'signal')
418
+ expect(a_request(:post, path)).to have_been_made
419
+ end
420
+ end
421
+
422
+ describe '#rename_container' do
423
+
424
+ it 'should raise ArgumentError when id is not provided' do
425
+ expect { @client.rename_container id: 'id' }.to raise_error(ArgumentError)
426
+ end
427
+
428
+ it 'should raise ArgumentError when name is not provided' do
429
+ expect { @client.rename_container name: 'name' }.to raise_error(ArgumentError)
430
+ end
431
+
432
+ it 'correct request should be made' do
433
+ path = @containers_base_path + 'id/rename?name=name'
434
+
435
+ stub_request(:post, path)
436
+ .to_return(body: "")
437
+
438
+ @client.rename_container(id: 'id', name: 'name')
439
+ expect(a_request(:post, path)).to have_been_made
440
+ end
441
+ end
442
+ end