kontena-cli 0.14.7 → 0.15.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -1
  3. data/VERSION +1 -1
  4. data/bin/kontena +3 -50
  5. data/examples/kontena-plugin-hello/.gitignore +9 -0
  6. data/examples/kontena-plugin-hello/Gemfile +4 -0
  7. data/examples/kontena-plugin-hello/README.md +3 -0
  8. data/examples/kontena-plugin-hello/bin/console +14 -0
  9. data/examples/kontena-plugin-hello/bin/setup +8 -0
  10. data/examples/kontena-plugin-hello/kontena-plugin-hello.gemspec +22 -0
  11. data/examples/kontena-plugin-hello/lib/kontena/plugin/hello.rb +7 -0
  12. data/examples/kontena-plugin-hello/lib/kontena/plugin/hello/world_command.rb +6 -0
  13. data/examples/kontena-plugin-hello/lib/kontena/plugin/hello_command.rb +9 -0
  14. data/examples/kontena-plugin-hello/lib/kontena_cli_plugin.rb +5 -0
  15. data/kontena-cli.gemspec +1 -3
  16. data/lib/kontena/cli/apps/build_command.rb +3 -0
  17. data/lib/kontena/cli/apps/common.rb +6 -1
  18. data/lib/kontena/cli/apps/deploy_command.rb +1 -1
  19. data/lib/kontena/cli/apps/docker_helper.rb +13 -14
  20. data/lib/kontena/cli/apps/service_generator.rb +19 -11
  21. data/lib/kontena/cli/apps/service_generator_v2.rb +1 -0
  22. data/lib/kontena/cli/apps/yaml/reader.rb +15 -0
  23. data/lib/kontena/cli/apps/yaml/service_extender.rb +28 -0
  24. data/lib/kontena/cli/apps/yaml/validations.rb +38 -24
  25. data/lib/kontena/cli/apps/yaml/validator.rb +7 -7
  26. data/lib/kontena/cli/apps/yaml/validator_v2.rb +7 -6
  27. data/lib/kontena/cli/certificate/authorize_command.rb +23 -0
  28. data/lib/kontena/cli/certificate/get_command.rb +25 -0
  29. data/lib/kontena/cli/certificate/register_command.rb +19 -0
  30. data/lib/kontena/cli/certificate_command.rb +14 -0
  31. data/lib/kontena/cli/containers/containers_helper.rb +22 -0
  32. data/lib/kontena/cli/containers/exec_command.rb +9 -2
  33. data/lib/kontena/cli/grids/logs_command.rb +14 -3
  34. data/lib/kontena/cli/master_command.rb +1 -12
  35. data/lib/kontena/cli/node_command.rb +0 -16
  36. data/lib/kontena/cli/plugin_command.rb +15 -0
  37. data/lib/kontena/cli/plugins/install_command.rb +28 -0
  38. data/lib/kontena/cli/plugins/list_command.rb +13 -0
  39. data/lib/kontena/cli/plugins/search_command.rb +29 -0
  40. data/lib/kontena/cli/plugins/uninstall_command.rb +30 -0
  41. data/lib/kontena/cli/registry/create_command.rb +1 -1
  42. data/lib/kontena/cli/services/create_command.rb +16 -0
  43. data/lib/kontena/cli/services/list_command.rb +17 -3
  44. data/lib/kontena/cli/services/logs_command.rb +63 -18
  45. data/lib/kontena/cli/services/services_helper.rb +47 -4
  46. data/lib/kontena/cli/services/update_command.rb +16 -0
  47. data/lib/kontena/cli/stack_command.rb +20 -0
  48. data/lib/kontena/cli/stacks/common.rb +39 -0
  49. data/lib/kontena/cli/stacks/create_command.rb +27 -0
  50. data/lib/kontena/cli/stacks/deploy_command.rb +26 -0
  51. data/lib/kontena/cli/stacks/list_command.rb +38 -0
  52. data/lib/kontena/cli/stacks/remove_command.rb +26 -0
  53. data/lib/kontena/cli/stacks/show_command.rb +38 -0
  54. data/lib/kontena/cli/stacks/update_command.rb +27 -0
  55. data/lib/kontena/client.rb +11 -4
  56. data/lib/kontena/command.rb +4 -0
  57. data/lib/kontena/main_command.rb +61 -0
  58. data/lib/kontena/plugin_manager.rb +38 -0
  59. data/lib/kontena/util.rb +17 -0
  60. data/lib/kontena_cli.rb +6 -0
  61. data/spec/fixtures/health.yml +26 -0
  62. data/spec/fixtures/kontena-build.yml +16 -0
  63. data/spec/fixtures/kontena_build_v2.yaml +26 -0
  64. data/spec/kontena/cli/app/build_command_spec.rb +13 -1
  65. data/spec/kontena/cli/app/common_spec.rb +11 -0
  66. data/spec/kontena/cli/app/deploy_command_spec.rb +1 -1
  67. data/spec/kontena/cli/app/docker_helper_spec.rb +45 -0
  68. data/spec/kontena/cli/app/service_generator_spec.rb +52 -1
  69. data/spec/kontena/cli/app/yaml/service_extender_spec.rb +24 -0
  70. data/spec/kontena/cli/app/yaml/validator_spec.rb +97 -14
  71. data/spec/kontena/cli/common_spec.rb +0 -5
  72. data/spec/kontena/cli/containers/containers_helper_spec.rb +16 -0
  73. data/spec/kontena/cli/services/services_helper_spec.rb +50 -1
  74. data/spec/kontena/cli/version_command_spec.rb +1 -1
  75. data/spec/kontena/client_spec.rb +156 -0
  76. data/spec/kontena/plugin_manager_spec.rb +22 -0
  77. data/spec/spec_helper.rb +1 -0
  78. metadata +54 -125
  79. data/lib/kontena/cli/master/aws/create_command.rb +0 -48
  80. data/lib/kontena/cli/master/aws_command.rb +0 -8
  81. data/lib/kontena/cli/master/azure/create_command.rb +0 -37
  82. data/lib/kontena/cli/master/azure_command.rb +0 -13
  83. data/lib/kontena/cli/master/digital_ocean/create_command.rb +0 -38
  84. data/lib/kontena/cli/master/digital_ocean_command.rb +0 -13
  85. data/lib/kontena/cli/master/packet/create_command.rb +0 -42
  86. data/lib/kontena/cli/master/packet_command.rb +0 -14
  87. data/lib/kontena/cli/master/upcloud/create_command.rb +0 -39
  88. data/lib/kontena/cli/master/upcloud_command.rb +0 -13
  89. data/lib/kontena/cli/master/vagrant/create_command.rb +0 -25
  90. data/lib/kontena/cli/master/vagrant/restart_command.rb +0 -20
  91. data/lib/kontena/cli/master/vagrant/ssh_command.rb +0 -15
  92. data/lib/kontena/cli/master/vagrant/start_command.rb +0 -20
  93. data/lib/kontena/cli/master/vagrant/stop_command.rb +0 -20
  94. data/lib/kontena/cli/master/vagrant/terminate_command.rb +0 -13
  95. data/lib/kontena/cli/master/vagrant_command.rb +0 -23
  96. data/lib/kontena/cli/nodes/aws/create_command.rb +0 -44
  97. data/lib/kontena/cli/nodes/aws/restart_command.rb +0 -29
  98. data/lib/kontena/cli/nodes/aws/terminate_command.rb +0 -21
  99. data/lib/kontena/cli/nodes/aws_command.rb +0 -15
  100. data/lib/kontena/cli/nodes/azure/create_command.rb +0 -38
  101. data/lib/kontena/cli/nodes/azure/restart_command.rb +0 -32
  102. data/lib/kontena/cli/nodes/azure/terminate_command.rb +0 -21
  103. data/lib/kontena/cli/nodes/azure_command.rb +0 -15
  104. data/lib/kontena/cli/nodes/digital_ocean/create_command.rb +0 -32
  105. data/lib/kontena/cli/nodes/digital_ocean/restart_command.rb +0 -27
  106. data/lib/kontena/cli/nodes/digital_ocean/terminate_command.rb +0 -19
  107. data/lib/kontena/cli/nodes/digital_ocean_command.rb +0 -15
  108. data/lib/kontena/cli/nodes/packet/create_command.rb +0 -35
  109. data/lib/kontena/cli/nodes/packet/restart_command.rb +0 -17
  110. data/lib/kontena/cli/nodes/packet/terminate_command.rb +0 -20
  111. data/lib/kontena/cli/nodes/packet_command.rb +0 -15
  112. data/lib/kontena/cli/nodes/upcloud/create_command.rb +0 -33
  113. data/lib/kontena/cli/nodes/upcloud/restart_command.rb +0 -20
  114. data/lib/kontena/cli/nodes/upcloud/terminate_command.rb +0 -20
  115. data/lib/kontena/cli/nodes/upcloud_command.rb +0 -15
  116. data/lib/kontena/cli/nodes/vagrant/create_command.rb +0 -27
  117. data/lib/kontena/cli/nodes/vagrant/restart_command.rb +0 -26
  118. data/lib/kontena/cli/nodes/vagrant/ssh_command.rb +0 -21
  119. data/lib/kontena/cli/nodes/vagrant/start_command.rb +0 -26
  120. data/lib/kontena/cli/nodes/vagrant/stop_command.rb +0 -26
  121. data/lib/kontena/cli/nodes/vagrant/terminate_command.rb +0 -17
  122. data/lib/kontena/cli/nodes/vagrant_command.rb +0 -21
  123. data/lib/kontena/machine/aws.rb +0 -13
  124. data/lib/kontena/machine/aws/cloudinit.yml +0 -71
  125. data/lib/kontena/machine/aws/cloudinit_master.yml +0 -118
  126. data/lib/kontena/machine/aws/common.rb +0 -58
  127. data/lib/kontena/machine/aws/master_provisioner.rb +0 -187
  128. data/lib/kontena/machine/aws/node_destroyer.rb +0 -51
  129. data/lib/kontena/machine/aws/node_provisioner.rb +0 -204
  130. data/lib/kontena/machine/azure.rb +0 -13
  131. data/lib/kontena/machine/azure/cloudinit.yml +0 -64
  132. data/lib/kontena/machine/azure/cloudinit_master.yml +0 -106
  133. data/lib/kontena/machine/azure/logger.rb +0 -27
  134. data/lib/kontena/machine/azure/master_provisioner.rb +0 -128
  135. data/lib/kontena/machine/azure/node_destroyer.rb +0 -53
  136. data/lib/kontena/machine/azure/node_provisioner.rb +0 -132
  137. data/lib/kontena/machine/digital_ocean.rb +0 -13
  138. data/lib/kontena/machine/digital_ocean/cloudinit.yml +0 -64
  139. data/lib/kontena/machine/digital_ocean/cloudinit_master.yml +0 -118
  140. data/lib/kontena/machine/digital_ocean/master_provisioner.rb +0 -99
  141. data/lib/kontena/machine/digital_ocean/node_destroyer.rb +0 -40
  142. data/lib/kontena/machine/digital_ocean/node_provisioner.rb +0 -88
  143. data/lib/kontena/machine/packet.rb +0 -17
  144. data/lib/kontena/machine/packet/cloudinit.yml +0 -66
  145. data/lib/kontena/machine/packet/cloudinit_master.yml +0 -118
  146. data/lib/kontena/machine/packet/master_provisioner.rb +0 -93
  147. data/lib/kontena/machine/packet/node_destroyer.rb +0 -42
  148. data/lib/kontena/machine/packet/node_provisioner.rb +0 -77
  149. data/lib/kontena/machine/packet/node_restarter.rb +0 -41
  150. data/lib/kontena/machine/packet/packet_common.rb +0 -89
  151. data/lib/kontena/machine/upcloud.rb +0 -9
  152. data/lib/kontena/machine/upcloud/cloudinit.yml +0 -64
  153. data/lib/kontena/machine/upcloud/cloudinit_master.yml +0 -118
  154. data/lib/kontena/machine/upcloud/master_provisioner.rb +0 -138
  155. data/lib/kontena/machine/upcloud/node_destroyer.rb +0 -85
  156. data/lib/kontena/machine/upcloud/node_provisioner.rb +0 -121
  157. data/lib/kontena/machine/upcloud/node_restarter.rb +0 -49
  158. data/lib/kontena/machine/upcloud/upcloud_common.rb +0 -74
  159. data/lib/kontena/machine/vagrant.rb +0 -12
  160. data/lib/kontena/machine/vagrant/Vagrantfile.master.rb.erb +0 -104
  161. data/lib/kontena/machine/vagrant/Vagrantfile.node.rb.erb +0 -32
  162. data/lib/kontena/machine/vagrant/cloudinit.yml +0 -73
  163. data/lib/kontena/machine/vagrant/master_destroyer.rb +0 -37
  164. data/lib/kontena/machine/vagrant/master_provisioner.rb +0 -79
  165. data/lib/kontena/machine/vagrant/node_destroyer.rb +0 -40
  166. data/lib/kontena/machine/vagrant/node_provisioner.rb +0 -68
@@ -100,5 +100,29 @@ describe Kontena::Cli::Apps::YAML::ServiceExtender do
100
100
  expect(result['secrets']).to eq([to_secret, from_secret])
101
101
  end
102
102
  end
103
+
104
+ context 'build args' do
105
+ it 'inherits build args from upper level' do
106
+ from = { 'build' => { 'args' => {'foo' => 'bar'}} }
107
+ to = {}
108
+ result = described_class.new(to).extend(from)
109
+ expect(result['build']['args']).to eq({'foo' => 'bar'})
110
+ end
111
+
112
+ it 'overrides values' do
113
+ from = { 'build' => { 'args' => {'foo' => 'bar'}} }
114
+ to = { 'build' => { 'args' => {'foo' => 'baz'}} }
115
+ result = described_class.new(to).extend(from)
116
+ expect(result['build']['args']).to eq({'foo' => 'baz'})
117
+ end
118
+
119
+ it 'combines variables' do
120
+ from = { 'build' => { 'args' => {'foo' => 'bar'}} }
121
+ to = { 'build' => { 'args' => {'baz' => 'baf'}} }
122
+ result = described_class.new(to).extend(from)
123
+ expect(result['build']['args']).to eq({'foo' => 'bar', 'baz' => 'baf'})
124
+ end
125
+ end
126
+
103
127
  end
104
128
  end
@@ -10,8 +10,24 @@ describe Kontena::Cli::Apps::YAML::Validator do
10
10
  end
11
11
 
12
12
  describe '#validate_options' do
13
+ context 'build' do
14
+ it 'is optional' do
15
+ result = subject.validate_options({})
16
+ expect(result.success?).to be_truthy
17
+ expect(result.messages.key?('build')).to be_falsey
18
+ end
19
+
20
+ it 'must be string' do
21
+ result = subject.validate_options('build' => 12345)
22
+ expect(result.messages.key?('build')).to be_truthy
23
+
24
+ result = subject.validate_options('build' => '.')
25
+ expect(result.messages.key?('build')).to be_falsey
26
+ end
27
+ end
28
+
13
29
  context 'image' do
14
- it 'image is optional' do
30
+ it 'is optional' do
15
31
  result = subject.validate_options('build' => '.')
16
32
  expect(result.success?).to be_truthy
17
33
  expect(result.messages.key?('image')).to be_falsey
@@ -21,7 +37,7 @@ describe Kontena::Cli::Apps::YAML::Validator do
21
37
  result = subject.validate_options('image' => 10)
22
38
  expect(result.success?).to be_falsey
23
39
  expect(result.messages.key?('image')).to be_truthy
24
- end
40
+ end
25
41
  end
26
42
 
27
43
  it 'validates stateful is boolean' do
@@ -63,22 +79,58 @@ describe Kontena::Cli::Apps::YAML::Validator do
63
79
  end
64
80
 
65
81
  context 'deploy' do
66
- it 'validates interval' do
67
-
68
- result = subject.validate_options('deploy' => {'interval' => '1xyz'})
69
- expect(result.messages.key?('deploy')).to be_truthy
70
-
71
- result = subject.validate_options('deploy' => {'interval' => '1min'})
82
+ it 'is optional' do
83
+ result = subject.validate_options({})
72
84
  expect(result.messages.key?('deploy')).to be_falsey
85
+ end
73
86
 
74
- result = subject.validate_options('deploy' => {'interval' => '1h'})
75
- expect(result.messages.key?('deploy')).to be_falsey
87
+ context 'strategy' do
88
+ it 'accepts daemon' do
89
+ result = subject.validate_options('deploy' => {'strategy' => 'daemon'})
90
+ expect(result.messages.key?('deploy')).to be_falsey
91
+ end
76
92
 
77
- result = subject.validate_options('deploy' => {'interval' => '1d'})
78
- expect(result.messages.key?('deploy')).to be_falsey
93
+ it 'accepts random' do
94
+ result = subject.validate_options('deploy' => {'strategy' => 'random'})
95
+ expect(result.messages.key?('deploy')).to be_falsey
96
+ end
79
97
 
80
- result = subject.validate_options('deploy' => {'interval' => '100'})
81
- expect(result.messages.key?('deploy')).to be_falsey
98
+ it 'accepts ha' do
99
+ result = subject.validate_options('deploy' => {'strategy' => 'ha'})
100
+ expect(result.messages.key?('deploy')).to be_falsey
101
+ end
102
+
103
+ it 'rejects invalid values' do
104
+ result = subject.validate_options('deploy' => {'strategy' => 'global'})
105
+ expect(result.messages.key?('deploy')).to be_truthy
106
+ end
107
+ end
108
+
109
+ context 'interval' do
110
+ it 'rejects wrong format' do
111
+ result = subject.validate_options('deploy' => {'interval' => '1xyz'})
112
+ expect(result.messages.key?('deploy')).to be_truthy
113
+ end
114
+
115
+ it 'accepts 1min as value' do
116
+ result = subject.validate_options('deploy' => {'interval' => '1min'})
117
+ expect(result.messages.key?('deploy')).to be_falsey
118
+ end
119
+
120
+ it 'accepts 1h as value' do
121
+ result = subject.validate_options('deploy' => {'interval' => '1h'})
122
+ expect(result.messages.key?('deploy')).to be_falsey
123
+ end
124
+
125
+ it 'accepts 1d as value' do
126
+ result = subject.validate_options('deploy' => {'interval' => '1d'})
127
+ expect(result.messages.key?('deploy')).to be_falsey
128
+ end
129
+
130
+ it 'accepts integer as value' do
131
+ result = subject.validate_options('deploy' => {'interval' => '100'})
132
+ expect(result.messages.key?('deploy')).to be_falsey
133
+ end
82
134
  end
83
135
  end
84
136
 
@@ -279,5 +331,36 @@ describe Kontena::Cli::Apps::YAML::Validator do
279
331
  end
280
332
  end
281
333
  end
334
+
335
+ context 'validates health_check' do
336
+ it 'validates health_check' do
337
+ result = subject.validate_options('health_check' => {})
338
+ expect(result.messages.key?('health_check')).to be_truthy
339
+ end
340
+
341
+ it 'validates health_check port ' do
342
+ result = subject.validate_options('health_check' => { 'protocol' => 'http', 'port' => 'abc'})
343
+ expect(result.messages.key?('health_check')).to be_truthy
344
+
345
+ result = subject.validate_options('health_check' => { 'protocol' => 'http', 'port' => 8080})
346
+ expect(result.messages.key?('health_check')).to be_falsey
347
+ end
348
+
349
+ it 'validates health_check uri' do
350
+ result = subject.validate_options('health_check' => { 'protocol' => 'http', 'port' => 8080, 'uri' => 'foobar'})
351
+ expect(result.messages.key?('health_check')).to be_truthy
352
+
353
+ result = subject.validate_options('health_check' => { 'protocol' => 'http', 'port' => 8080, 'uri' => '/health/foo/bar'})
354
+ expect(result.messages.key?('health_check')).to be_falsey
355
+ end
356
+
357
+ it 'validates health_check protocol' do
358
+ result = subject.validate_options('health_check' => { 'protocol' => 'foo', 'port' => 8080, 'uri' => 'foobar'})
359
+ expect(result.messages.key?('health_check')).to be_truthy
360
+
361
+ result = subject.validate_options('health_check' => { 'protocol' => 'tcp', 'port' => 3306 })
362
+ expect(result.messages.key?('health_check')).to be_falsey
363
+ end
364
+ end
282
365
  end
283
366
  end
@@ -2,11 +2,6 @@ require_relative "../../spec_helper"
2
2
  require "kontena/cli/common"
3
3
 
4
4
  describe Kontena::Cli::Common do
5
-
6
- let(:masters) do
7
-
8
- end
9
-
10
5
  let(:subject) do
11
6
  Class.new do
12
7
  include Kontena::Cli::Common
@@ -0,0 +1,16 @@
1
+ require "kontena/cli/containers/containers_helper"
2
+
3
+ describe Kontena::Cli::Containers::ContainersHelper do
4
+ let(:subject) do
5
+ Class.new { include Kontena::Cli::Containers::ContainersHelper }.new
6
+ end
7
+
8
+ describe '#build_command' do
9
+ it 'parses commands correctly' do
10
+ expect(subject.build_command(['echo $ID'])).to eq('echo $ID')
11
+ expect(subject.build_command(['echo', 'ID', '$ID'])).to eq('echo ID $ID')
12
+ expect(subject.build_command(['echo', 'ID: $ID'])).to eq('echo "ID: $ID"')
13
+ expect(subject.build_command(['echo', '{"ID": "123"}'])).to eq('echo "{\\"ID\\": \\"123\\"}"')
14
+ end
15
+ end
16
+ end
@@ -85,11 +85,45 @@ module Kontena::Cli::Services
85
85
 
86
86
  it 'returns hash of port options' do
87
87
  valid_result = [{
88
+ ip: '0.0.0.0',
89
+ container_port: '80',
90
+ node_port: '80',
91
+ protocol: 'tcp'
92
+ }]
93
+ port_options = subject.parse_ports(['80:80'])
94
+ expect(port_options).to eq(valid_result)
95
+ end
96
+
97
+ it 'returns hash of port options with protocol' do
98
+ valid_result = [{
99
+ ip: '0.0.0.0',
100
+ container_port: '80',
101
+ node_port: '80',
102
+ protocol: 'udp'
103
+ }]
104
+ port_options = subject.parse_ports(['80:80/udp'])
105
+ expect(port_options).to eq(valid_result)
106
+ end
107
+
108
+ it 'returns hash of port options with ip' do
109
+ valid_result = [{
110
+ ip: '1.2.3.4',
88
111
  container_port: '80',
89
112
  node_port: '80',
90
113
  protocol: 'tcp'
91
114
  }]
92
- port_options = subject.parse_ports(['80:80'])
115
+ port_options = subject.parse_ports(['1.2.3.4:80:80'])
116
+ expect(port_options).to eq(valid_result)
117
+ end
118
+
119
+ it 'returns hash of port options with ip and protocol' do
120
+ valid_result = [{
121
+ ip: '1.2.3.4',
122
+ container_port: '80',
123
+ node_port: '80',
124
+ protocol: 'udp'
125
+ }]
126
+ port_options = subject.parse_ports(['1.2.3.4:80:80/udp'])
93
127
  expect(port_options).to eq(valid_result)
94
128
  end
95
129
  end
@@ -174,5 +208,20 @@ module Kontena::Cli::Services
174
208
  expect(subject.parse_relative_time("600")).to eq(600)
175
209
  end
176
210
  end
211
+
212
+ describe '#parse_build_args' do
213
+ it'parses array args' do
214
+ expect(subject.parse_build_args(['foo=bar', 'baz=baf'])).to eq({'foo' => 'bar', 'baz' => 'baf'})
215
+ end
216
+
217
+ it'parses hash args' do
218
+ expect(subject.parse_build_args({'foo' => 'bar', 'baz' => 'baf'})).to eq({'foo' => 'bar', 'baz' => 'baf'})
219
+ end
220
+
221
+ it'parses hash args and replaces empty value from env' do
222
+ expect(ENV).to receive(:[]).with('baz').and_return('baf')
223
+ expect(subject.parse_build_args({'foo' => 'bar', 'baz' => nil})).to eq({'foo' => 'bar', 'baz' => 'baf'})
224
+ end
225
+ end
177
226
  end
178
227
  end
@@ -11,7 +11,7 @@ describe Kontena::Cli::VersionCommand do
11
11
  end
12
12
 
13
13
  it 'runs without errors' do
14
- subject.run([])
14
+ expect { subject.run([]) }.not_to raise_error
15
15
  end
16
16
  end
17
17
  end
@@ -0,0 +1,156 @@
1
+ require_relative '../spec_helper'
2
+ require 'kontena_cli'
3
+
4
+ describe Kontena::Client do
5
+
6
+ let(:subject) { described_class.new('https://localhost/v1/') }
7
+ let(:http_client) { double(:http_client) }
8
+
9
+ before(:each) do
10
+ allow(subject).to receive(:http_client)
11
+ end
12
+
13
+ describe '#get' do
14
+ it 'passes path to client' do
15
+ allow(subject).to receive(:http_client).and_return(http_client)
16
+ expect(http_client).to receive(:get).with(
17
+ hash_including(path: '/v1/foo')
18
+ ).and_return(spy(:response, status: 200))
19
+ subject.get('foo')
20
+ end
21
+
22
+ it 'passes params to client' do
23
+ allow(subject).to receive(:http_client).and_return(http_client)
24
+ expect(http_client).to receive(:get).with(
25
+ hash_including(query: {bar: 'baz'})
26
+ ).and_return(spy(:response, status: 200))
27
+ subject.get('foo', {bar: 'baz'})
28
+ end
29
+
30
+ it 'passes params to client' do
31
+ allow(subject).to receive(:http_client).and_return(http_client)
32
+ expect(http_client).to receive(:get).with(
33
+ hash_including(headers: hash_including(:'Some-Header' => 'value'))
34
+ ).and_return(spy(:response, status: 200))
35
+ subject.get('foo', nil, {:'Some-Header' => 'value'})
36
+ end
37
+ end
38
+
39
+ describe '#get_stream' do
40
+ let(:response_block) { Proc.new{ } }
41
+
42
+ it 'passes path & response_block to client' do
43
+ allow(subject).to receive(:http_client).and_return(http_client)
44
+ expect(http_client).to receive(:get).with(
45
+ hash_including(path: '/v1/foo', response_block: response_block)
46
+ ).and_return(spy(:response, status: 200))
47
+ subject.get_stream('foo', response_block)
48
+ end
49
+
50
+ it 'passes params to client' do
51
+ allow(subject).to receive(:http_client).and_return(http_client)
52
+ expect(http_client).to receive(:get).with(
53
+ hash_including(query: {bar: 'baz'})
54
+ ).and_return(spy(:response, status: 200))
55
+ subject.get_stream('foo', response_block, {bar: 'baz'})
56
+ end
57
+
58
+ it 'passes params to client' do
59
+ allow(subject).to receive(:http_client).and_return(http_client)
60
+ expect(http_client).to receive(:get).with(
61
+ hash_including(headers: hash_including(:'Some-Header' => 'value'))
62
+ ).and_return(spy(:response, status: 200))
63
+ subject.get_stream('foo', response_block, nil, {:'Some-Header' => 'value'})
64
+ end
65
+ end
66
+
67
+ describe '#post' do
68
+ let(:data) do
69
+ { foo: 'bar' }
70
+ end
71
+
72
+ it 'passes path and object to client' do
73
+ allow(subject).to receive(:http_client).and_return(http_client)
74
+ expect(http_client).to receive(:post).with(
75
+ hash_including(path: '/v1/foo', body: kind_of(String))
76
+ ).and_return(spy(:response, status: 200))
77
+ subject.post('foo', data)
78
+ end
79
+
80
+ it 'passes params to client' do
81
+ allow(subject).to receive(:http_client).and_return(http_client)
82
+ expect(http_client).to receive(:post).with(
83
+ hash_including(query: {bar: 'baz'})
84
+ ).and_return(spy(:response, status: 200))
85
+ subject.post('foo', data, {bar: 'baz'})
86
+ end
87
+
88
+ it 'passes params to client' do
89
+ allow(subject).to receive(:http_client).and_return(http_client)
90
+ expect(http_client).to receive(:post).with(
91
+ hash_including(headers: hash_including(:'Some-Header' => 'value'))
92
+ ).and_return(spy(:response, status: 200))
93
+ subject.post('foo', data, nil, {:'Some-Header' => 'value'})
94
+ end
95
+ end
96
+
97
+ describe '#put' do
98
+ let(:data) do
99
+ { foo: 'bar' }
100
+ end
101
+
102
+ it 'passes path and object to client' do
103
+ allow(subject).to receive(:http_client).and_return(http_client)
104
+ expect(http_client).to receive(:put).with(
105
+ hash_including(path: '/v1/foo', body: kind_of(String))
106
+ ).and_return(spy(:response, status: 200))
107
+ subject.put('foo', data)
108
+ end
109
+
110
+ it 'passes params to client' do
111
+ allow(subject).to receive(:http_client).and_return(http_client)
112
+ expect(http_client).to receive(:put).with(
113
+ hash_including(query: {bar: 'baz'})
114
+ ).and_return(spy(:response, status: 200))
115
+ subject.put('foo', data, {bar: 'baz'})
116
+ end
117
+
118
+ it 'passes params to client' do
119
+ allow(subject).to receive(:http_client).and_return(http_client)
120
+ expect(http_client).to receive(:put).with(
121
+ hash_including(headers: hash_including(:'Some-Header' => 'value'))
122
+ ).and_return(spy(:response, status: 200))
123
+ subject.put('foo', data, nil, {:'Some-Header' => 'value'})
124
+ end
125
+ end
126
+
127
+ describe '#delete' do
128
+ let(:data) do
129
+ { foo: 'bar' }
130
+ end
131
+
132
+ it 'passes path to client' do
133
+ allow(subject).to receive(:http_client).and_return(http_client)
134
+ expect(http_client).to receive(:delete).with(
135
+ hash_including(path: '/v1/foo')
136
+ ).and_return(spy(:response, status: 200))
137
+ subject.delete('foo')
138
+ end
139
+
140
+ it 'passes params to client' do
141
+ allow(subject).to receive(:http_client).and_return(http_client)
142
+ expect(http_client).to receive(:delete).with(
143
+ hash_including(query: {bar: 'baz'})
144
+ ).and_return(spy(:response, status: 200))
145
+ subject.delete('foo', nil, {bar: 'baz'})
146
+ end
147
+
148
+ it 'passes params to client' do
149
+ allow(subject).to receive(:http_client).and_return(http_client)
150
+ expect(http_client).to receive(:delete).with(
151
+ hash_including(headers: hash_including(:'Some-Header' => 'value'))
152
+ ).and_return(spy(:response, status: 200))
153
+ subject.delete('foo', nil, nil, {:'Some-Header' => 'value'})
154
+ end
155
+ end
156
+ end
@@ -0,0 +1,22 @@
1
+ require_relative '../spec_helper'
2
+ require 'kontena_cli'
3
+
4
+ describe Kontena::PluginManager do
5
+
6
+ let(:subject) { described_class.instance }
7
+
8
+ describe '#load_plugins' do
9
+ it 'includes hello plugin' do
10
+ plugins = subject.load_plugins
11
+ expect(plugins.any?{ |p| p.name == 'kontena-plugin-hello' }).to be_truthy
12
+ end
13
+
14
+ it 'allows plugin to register as a sub-command' do
15
+ plugins = subject.load_plugins
16
+ main = Kontena::MainCommand.new(File.basename($0))
17
+ expect {
18
+ main.run(['hello'])
19
+ }.to raise_error(Clamp::HelpWanted)
20
+ end
21
+ end
22
+ end