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,193 @@
1
+ require 'helper'
2
+ require 'http'
3
+
4
+ RSpec.describe Hyperb::Services 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 + '/services'
9
+ end
10
+
11
+ describe '#remove_container' do
12
+
13
+ it 'should raise ArgumentError when name is not provided' do
14
+ expect { @client.remove_service }.to raise_error(ArgumentError)
15
+ end
16
+
17
+ it 'request to the correct path should be made' do
18
+ path = @base_path + '/name'
19
+
20
+ stub_request(:delete, path)
21
+ .to_return(body: '')
22
+
23
+ @client.remove_service(name: 'name')
24
+ expect(a_request(:delete, path)).to have_been_made
25
+ end
26
+
27
+ it 'request to the correct path should be made with keep' do
28
+ path = @base_path + '/name?keep=true'
29
+
30
+ stub_request(:delete, path)
31
+ .to_return(body: '')
32
+
33
+ @client.remove_service(name: 'name', keep: true)
34
+ expect(a_request(:delete, path)).to have_been_made
35
+ end
36
+
37
+ end
38
+
39
+ describe '#create_service' do
40
+
41
+ it 'should raise ArgumentError when name is not provided' do
42
+ expect { @client.create_service image: 'nginx', labels: {} }.to raise_error(ArgumentError)
43
+ end
44
+
45
+ it 'should raise ArgumentError when image is not provided' do
46
+ expect { @client.create_service name: 'srvc1', service_port: 80, labels: {} }.to raise_error(ArgumentError)
47
+ end
48
+
49
+ it 'should raise ArgumentError when service_port is not provided' do
50
+ expect { @client.create_service }.to raise_error(ArgumentError)
51
+ end
52
+
53
+ it 'should raise ArgumentError when replicas is not provided' do
54
+ expect { @client.create_service name: 'name1', image: 'img' }.to raise_error(ArgumentError)
55
+ end
56
+
57
+ it 'should raise ArgumentError when labels is not provided' do
58
+ expect { @client.create_service }.to raise_error(ArgumentError)
59
+ end
60
+
61
+ it 'request to the correct path should be made with name' do
62
+ path = @base_path + '/create'
63
+ body = {
64
+ service_port: 80,
65
+ name: 'name1',
66
+ image: 'nginx',
67
+ replicas: 2,
68
+ container_port: 80,
69
+ labels: {}
70
+ }
71
+ stub_request(:post, path)
72
+ .with(body: body)
73
+ .to_return(body: fixture('create_service.json'))
74
+
75
+ @client.create_service(body)
76
+ expect(a_request(:post, path)).to have_been_made
77
+ end
78
+
79
+ it 'correct request should be made with entrypoint' do
80
+ path = @base_path + '/create'
81
+ body = {
82
+ service_port: 80,
83
+ name: 'name1',
84
+ image: 'nginx',
85
+ replicas: 2,
86
+ entrypoint: 'entry.sh',
87
+ container_port: 80,
88
+ labels: {}
89
+ }
90
+ stub_request(:post, path)
91
+ .with(body: body)
92
+ .to_return(body: fixture('create_service.json'))
93
+
94
+ @client.create_service(body)
95
+ expect(a_request(:post, path)).to have_been_made
96
+ end
97
+
98
+ it 'correct request should be made with cmd' do
99
+ path = @base_path + '/create'
100
+ body = {
101
+ service_port: 80,
102
+ name: 'name1',
103
+ image: 'nginx',
104
+ replicas: 2,
105
+ cmd: 'echo 1',
106
+ container_port: 80,
107
+ labels: {}
108
+ }
109
+ stub_request(:post, path)
110
+ .with(body: body)
111
+ .to_return(body: fixture('create_service.json'))
112
+
113
+ @client.create_service(body)
114
+ expect(a_request(:post, path)).to have_been_made
115
+ end
116
+
117
+ it 'correct request should be made with env' do
118
+ path = @base_path + '/create'
119
+ body = {
120
+ service_port: 80,
121
+ name: 'name1',
122
+ image: 'nginx',
123
+ replicas: 2,
124
+ env: ['ENV=123'],
125
+ container_port: 80,
126
+ labels: {}
127
+ }
128
+ stub_request(:post, path)
129
+ .with(body: body)
130
+ .to_return(body: fixture('create_service.json'))
131
+
132
+ @client.create_service(body)
133
+ expect(a_request(:post, path)).to have_been_made
134
+ end
135
+
136
+ it 'correct request should be made with protocol' do
137
+ path = @base_path + '/create'
138
+ body = {
139
+ service_port: 80,
140
+ name: 'name1',
141
+ image: 'nginx',
142
+ replicas: 2,
143
+ protocol: 'https',
144
+ container_port: 80,
145
+ labels: {}
146
+ }
147
+ stub_request(:post, path)
148
+ .with(body: body)
149
+ .to_return(body: fixture('create_service.json'))
150
+
151
+ @client.create_service(body)
152
+ expect(a_request(:post, path)).to have_been_made
153
+ end
154
+
155
+ it 'correct request should be made with algorithm' do
156
+ path = @base_path + '/create'
157
+ body = {
158
+ service_port: 80,
159
+ name: 'name1',
160
+ image: 'nginx',
161
+ replicas: 2,
162
+ container_port: 80,
163
+ algorithm: 'roundrobin',
164
+ labels: {}
165
+ }
166
+ stub_request(:post, path)
167
+ .with(body: body)
168
+ .to_return(body: fixture('create_service.json'))
169
+
170
+ @client.create_service(body)
171
+ expect(a_request(:post, path)).to have_been_made
172
+ end
173
+
174
+ it 'correct request should be made with workingdir' do
175
+ path = @base_path + '/create'
176
+ body = {
177
+ service_port: 80,
178
+ name: 'name1',
179
+ workingdir: '/path',
180
+ image: 'nginx',
181
+ replicas: 2,
182
+ container_port: 80,
183
+ labels: {}
184
+ }
185
+ stub_request(:post, path)
186
+ .with(body: body)
187
+ .to_return(body: fixture('create_service.json'))
188
+
189
+ @client.create_service(body)
190
+ expect(a_request(:post, path)).to have_been_made
191
+ end
192
+ end
193
+ end
@@ -0,0 +1,7 @@
1
+ require "helper"
2
+
3
+ RSpec.describe Hyperb do
4
+ it "has a version number" do
5
+ expect(Hyperb::VERSION).not_to be nil
6
+ end
7
+ end
@@ -0,0 +1,88 @@
1
+ require 'helper'
2
+ require 'http'
3
+
4
+ RSpec.describe Hyperb::Volumes 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 + '/volumes'
9
+ end
10
+
11
+ describe '#remove_volume' do
12
+
13
+ it 'should raise ArgumentError when id is not provided' do
14
+ expect { @client.remove_volume }.to raise_error(ArgumentError)
15
+ end
16
+
17
+ it 'request to the correct path should be made' do
18
+ path = @base_path + '/id'
19
+
20
+ stub_request(:delete, path)
21
+ .to_return(body: fixture('remove_container.json'))
22
+
23
+ @client.remove_volume id: 'id'
24
+ expect(a_request(:delete, path)).to have_been_made
25
+ end
26
+ end
27
+
28
+ describe '#inspect_volume' do
29
+
30
+ it 'should raise ArgumentError when id is not provided' do
31
+ expect { @client.inspect_volume }.to raise_error(ArgumentError)
32
+ end
33
+
34
+ it 'request to the correct path should be made' do
35
+ path = @base_path + '/id'
36
+
37
+ stub_request(:get, path)
38
+ .to_return(body: fixture('inspect_container.json'))
39
+
40
+ @client.inspect_volume id: 'id'
41
+ expect(a_request(:get, path)).to have_been_made
42
+ end
43
+
44
+ it 'correct attrs' do
45
+ path = @base_path + '/id'
46
+
47
+ stub_request(:get, path)
48
+ .to_return(body: fixture('inspect_container.json'))
49
+
50
+ vol = @client.inspect_volume id: 'id'
51
+ expect(vol.key?(:name)).to be true
52
+ expect(vol.key?(:driver)).to be true
53
+ end
54
+ end
55
+
56
+ describe '#inspect_volume' do
57
+
58
+ it 'request to the correct path should be made' do
59
+ stub_request(:get, @base_path)
60
+ .to_return(body: fixture('volumes.json'))
61
+
62
+ @client.volumes
63
+ expect(a_request(:get, @base_path)).to have_been_made
64
+ end
65
+
66
+ it 'return array of containers' do
67
+ stub_request(:get, @base_path)
68
+ .to_return(body: fixture('volumes.json'))
69
+
70
+ volumes = @client.volumes
71
+ expect(volumes).to be_a Array
72
+ expect(volumes[0]).to be_a Hyperb::Volume
73
+ end
74
+
75
+ it 'correct attrs' do
76
+ stub_request(:get, @base_path)
77
+ .to_return(body: fixture('volumes.json'))
78
+
79
+ @client.volumes.each do |vol|
80
+ expect(vol.name).to be_a String
81
+ expect(vol.driver).to be_a String
82
+ expect(vol.mountpoint).to be_a String
83
+ expect(vol.labels).to be_a Hash
84
+ end
85
+ end
86
+ end
87
+
88
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hyperb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - drish
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-11 00:00:00.000000000 Z
11
+ date: 2017-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
@@ -120,7 +120,78 @@ email:
120
120
  executables: []
121
121
  extensions: []
122
122
  extra_rdoc_files: []
123
- files: []
123
+ files:
124
+ - ".codeclimate.yml"
125
+ - ".gitignore"
126
+ - ".rspec"
127
+ - ".rubocop.yml"
128
+ - Dockerfile
129
+ - Gemfile
130
+ - LICENSE.txt
131
+ - Makefile
132
+ - README.md
133
+ - Rakefile
134
+ - circle.yml
135
+ - examples/README.md
136
+ - examples/auth-gcr-registry.md
137
+ - examples/compose.md
138
+ - examples/handling-errors.md
139
+ - examples/streaming-logs.md
140
+ - examples/streaming-stats.md
141
+ - hyperb.gemspec
142
+ - lib/hyperb.rb
143
+ - lib/hyperb/api.rb
144
+ - lib/hyperb/auth_object.rb
145
+ - lib/hyperb/client.rb
146
+ - lib/hyperb/compose/compose.rb
147
+ - lib/hyperb/containers/container.rb
148
+ - lib/hyperb/containers/containers.rb
149
+ - lib/hyperb/error.rb
150
+ - lib/hyperb/hyper_version.rb
151
+ - lib/hyperb/images/image.rb
152
+ - lib/hyperb/images/images.rb
153
+ - lib/hyperb/network/fips.rb
154
+ - lib/hyperb/request.rb
155
+ - lib/hyperb/services/services.rb
156
+ - lib/hyperb/snapshots/snapshot.rb
157
+ - lib/hyperb/snapshots/snapshots.rb
158
+ - lib/hyperb/utils.rb
159
+ - lib/hyperb/version.rb
160
+ - lib/hyperb/volumes/volume.rb
161
+ - lib/hyperb/volumes/volumes.rb
162
+ - spec/auth_object_spec.rb
163
+ - spec/client_spec.rb
164
+ - spec/compose_spec.rb
165
+ - spec/container_spec.rb
166
+ - spec/containers_spec.rb
167
+ - spec/create_snapshot.rb
168
+ - spec/error_spec.rb
169
+ - spec/fixtures/auth_obj.json
170
+ - spec/fixtures/compose_rm.json
171
+ - spec/fixtures/compose_up.json
172
+ - spec/fixtures/container_stats.json
173
+ - spec/fixtures/containers.json
174
+ - spec/fixtures/create_container.json
175
+ - spec/fixtures/create_image.json
176
+ - spec/fixtures/create_service.json
177
+ - spec/fixtures/create_snapshot.json
178
+ - spec/fixtures/fip_allocate.json
179
+ - spec/fixtures/fips_ls.json
180
+ - spec/fixtures/images.json
181
+ - spec/fixtures/inspect_container.json
182
+ - spec/fixtures/inspect_image.json
183
+ - spec/fixtures/inspect_volume.json
184
+ - spec/fixtures/remove_container.json
185
+ - spec/fixtures/remove_image.json
186
+ - spec/fixtures/volumes.json
187
+ - spec/helper.rb
188
+ - spec/image_spec.rb
189
+ - spec/images_spec.rb
190
+ - spec/network_spec.rb
191
+ - spec/request_spec.rb
192
+ - spec/services_spec.rb
193
+ - spec/version_spec.rb
194
+ - spec/volumes_spec.rb
124
195
  homepage: https://github.com/drish/hyperb
125
196
  licenses:
126
197
  - MIT