kontena-cli 1.3.0.pre1 → 1.3.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/bin/kontena +2 -1
  4. data/lib/kontena/callback.rb +1 -1
  5. data/lib/kontena/callbacks/auth/01_list_and_select_grid_after_master_auth.rb +1 -2
  6. data/lib/kontena/callbacks/master/01_clear_current_master_after_terminate.rb +2 -3
  7. data/lib/kontena/callbacks/master/deploy/01_show_logo_before_deploy.rb +1 -2
  8. data/lib/kontena/callbacks/master/deploy/05_before_deploy_configuration_wizard.rb +2 -2
  9. data/lib/kontena/callbacks/master/deploy/40_install_ssl_certificate_after_deploy.rb +2 -2
  10. data/lib/kontena/callbacks/master/deploy/50_authenticate_after_deploy.rb +9 -9
  11. data/lib/kontena/callbacks/master/deploy/55_create_initial_grid_after_deploy.rb +2 -2
  12. data/lib/kontena/callbacks/master/deploy/56_set_server_provider_after_deploy.rb +1 -2
  13. data/lib/kontena/callbacks/master/deploy/60_configure_auth_provider_after_deploy.rb +1 -2
  14. data/lib/kontena/callbacks/master/deploy/70_invite_self_after_deploy.rb +2 -3
  15. data/lib/kontena/callbacks/master/deploy/90_proptip_after_deploy.rb +2 -2
  16. data/lib/kontena/cli/apps/common.rb +0 -1
  17. data/lib/kontena/cli/apps/init_command.rb +2 -0
  18. data/lib/kontena/cli/apps/kontena_yml_generator.rb +2 -1
  19. data/lib/kontena/cli/apps/list_command.rb +10 -2
  20. data/lib/kontena/cli/apps/yaml/reader.rb +2 -1
  21. data/lib/kontena/cli/apps/yaml/service_extender.rb +0 -1
  22. data/lib/kontena/cli/cloud/login_command.rb +51 -7
  23. data/lib/kontena/cli/cloud/master/list_command.rb +14 -11
  24. data/lib/kontena/cli/common.rb +36 -83
  25. data/lib/kontena/cli/config.rb +46 -29
  26. data/lib/kontena/cli/containers/list_command.rb +30 -41
  27. data/lib/kontena/cli/etcd/list_command.rb +12 -7
  28. data/lib/kontena/cli/external_registries/list_command.rb +14 -8
  29. data/lib/kontena/cli/grids/list_command.rb +18 -10
  30. data/lib/kontena/cli/grids/trusted_subnets/list_command.rb +7 -5
  31. data/lib/kontena/cli/grids/users/list_command.rb +9 -7
  32. data/lib/kontena/cli/localhost_web_server.rb +3 -3
  33. data/lib/kontena/cli/log_formatters/compact.rb +65 -0
  34. data/lib/kontena/cli/log_formatters/strip_color.rb +13 -0
  35. data/lib/kontena/cli/master/config/import_command.rb +2 -1
  36. data/lib/kontena/cli/master/config/set_command.rb +1 -1
  37. data/lib/kontena/cli/master/list_command.rb +16 -10
  38. data/lib/kontena/cli/master/token/list_command.rb +23 -12
  39. data/lib/kontena/cli/master/user/invite_command.rb +1 -1
  40. data/lib/kontena/cli/master/user/list_command.rb +17 -6
  41. data/lib/kontena/cli/nodes/labels/list_command.rb +3 -0
  42. data/lib/kontena/cli/nodes/list_command.rb +58 -37
  43. data/lib/kontena/cli/nodes/show_command.rb +1 -1
  44. data/lib/kontena/cli/plugins/install_command.rb +2 -2
  45. data/lib/kontena/cli/plugins/list_command.rb +19 -5
  46. data/lib/kontena/cli/plugins/uninstall_command.rb +1 -1
  47. data/lib/kontena/cli/services/containers_command.rb +7 -0
  48. data/lib/kontena/cli/services/envs/list_command.rb +6 -4
  49. data/lib/kontena/cli/services/list_command.rb +47 -36
  50. data/lib/kontena/cli/services/services_helper.rb +9 -16
  51. data/lib/kontena/cli/services/stats_command.rb +2 -1
  52. data/lib/kontena/cli/spinner.rb +3 -5
  53. data/lib/kontena/cli/stacks/common.rb +4 -4
  54. data/lib/kontena/cli/stacks/list_command.rb +42 -33
  55. data/lib/kontena/cli/stacks/registry/search_command.rb +6 -0
  56. data/lib/kontena/cli/stacks/registry/show_command.rb +2 -0
  57. data/lib/kontena/cli/stacks/registry_command.rb +1 -2
  58. data/lib/kontena/cli/stacks/validate_command.rb +1 -0
  59. data/lib/kontena/cli/stacks/yaml/reader.rb +3 -2
  60. data/lib/kontena/cli/stacks/yaml/service_extender.rb +0 -1
  61. data/lib/kontena/cli/stacks/yaml/validations.rb +1 -1
  62. data/lib/kontena/cli/table_generator.rb +125 -0
  63. data/lib/kontena/cli/vault/export_command.rb +7 -4
  64. data/lib/kontena/cli/vault/import_command.rb +3 -0
  65. data/lib/kontena/cli/vault/list_command.rb +23 -10
  66. data/lib/kontena/cli/volumes/create_command.rb +8 -4
  67. data/lib/kontena/cli/volumes/list_command.rb +15 -7
  68. data/lib/kontena/client.rb +44 -33
  69. data/lib/kontena/command.rb +7 -4
  70. data/lib/kontena/debug_instrumentor.rb +10 -9
  71. data/lib/kontena/main_command.rb +1 -3
  72. data/lib/kontena/plugin_manager.rb +15 -7
  73. data/lib/kontena/stacks_cache.rb +7 -7
  74. data/lib/kontena/stacks_client.rb +24 -5
  75. data/lib/kontena/util.rb +43 -15
  76. data/lib/kontena_cli.rb +71 -14
  77. data/spec/kontena/cli/cloud/login_command_spec.rb +42 -0
  78. data/spec/kontena/cli/containers/list_command_spec.rb +1 -2
  79. data/spec/kontena/cli/nodes/list_command_spec.rb +153 -126
  80. data/spec/kontena/cli/registry/create_spec.rb +22 -0
  81. data/spec/kontena/cli/services/stats_command_spec.rb +22 -0
  82. data/spec/kontena/cli/table_generator_spec.rb +118 -0
  83. data/spec/kontena/cli/version_command_spec.rb +2 -2
  84. data/spec/kontena/client_spec.rb +4 -3
  85. data/spec/support/client_helpers.rb +3 -3
  86. data/spec/support/output_helpers.rb +54 -8
  87. metadata +11 -2
@@ -0,0 +1,118 @@
1
+ require 'kontena/cli/table_generator'
2
+ require 'kontena/command'
3
+ require 'kontena/cli/common'
4
+
5
+ describe Kontena::Cli::TableGenerator do
6
+ let(:data) { [{'a' => 'a1', 'b' => 'b1', 'c' => 'c1'}, {'a' => 'a2', 'b' => 'b2', 'c' => 'c2'}] }
7
+
8
+ context Kontena::Cli::TableGenerator::Helper do
9
+ let(:klass) { Class.new(Kontena::Command) }
10
+
11
+ it 'adds the quiet option' do
12
+ klass.include(described_class)
13
+ expect(klass.recognised_options.first.flag?).to be_truthy
14
+ expect(klass.recognised_options.first.long_switch).to eq '--quiet'
15
+ expect(klass.recognised_options.first.switches).to include '-q'
16
+ expect(klass.recognised_options.first.description).to match (/identifying column/)
17
+ end
18
+
19
+ context 'with the helper included' do
20
+
21
+ let(:subject) { klass.new([]) }
22
+
23
+ before(:each) do
24
+ klass.include(Kontena::Cli::Common)
25
+ klass.include(described_class)
26
+ end
27
+
28
+ it 'responds to print_table' do
29
+ expect(subject).to respond_to(:print_table)
30
+ end
31
+
32
+ it 'responds to generate_table' do
33
+ expect(subject).to respond_to(:print_table)
34
+ end
35
+
36
+ context '#print_table' do
37
+
38
+ include OutputHelpers
39
+
40
+ it 'outputs a table from an array and a list of fields' do
41
+ expect{subject.print_table(data, ['a', 'b'])}.to output_table([
42
+ ['a1', 'b1'],
43
+ ['a2', 'b2']
44
+ ]).with_header(['A', 'B'])
45
+ end
46
+
47
+ it 'outputs a table without a header when only one field' do
48
+ expect{subject.print_table(data, ['a'])}.to output_table([
49
+ ['a1'],
50
+ ['a2']
51
+ ]).without_header
52
+ end
53
+
54
+ it 'tries to read the fields from #fields method when none given' do
55
+ expect(subject).to receive(:fields).and_return(['a', 'b'])
56
+ expect{subject.print_table(data)}.to output_table([
57
+ ['a1', 'b1'],
58
+ ['a2', 'b2']
59
+ ]).with_header(['A', 'B'])
60
+ end
61
+
62
+ it 'tries to read render options from #render_options method' do
63
+ expect(subject).to receive(:render_options).and_return(mode: :ascii, border: { separator: '|' })
64
+ expect{subject.print_table(data)}.to output(/\|/).to_stdout
65
+ end
66
+ end
67
+ end
68
+ end
69
+
70
+ let(:klass) { described_class }
71
+
72
+ context 'with an array of hashes' do
73
+ context 'given a list of fields' do
74
+ it 'collects the fields listed from the hashes and capitalizes the field names' do
75
+ subject = klass.new(data, ['a', 'b'])
76
+ expect(subject).to receive(:create_table).with(['A', 'B'], [['a1', 'b1'], ['a2', 'b2']]).and_return(true)
77
+ subject.table
78
+ end
79
+ end
80
+
81
+ context 'given no list of fields' do
82
+ it 'uses all fields found in the data and creates field names for the header' do
83
+ data.each { |hash| expect(hash).to receive(:keys).and_call_original }
84
+ subject = klass.new(data)
85
+ expect(subject).to receive(:create_table).with(['A', 'B', 'C'], [['a1', 'b1', 'c1'], ['a2', 'b2', 'c2']]).and_return(true)
86
+ subject.table
87
+ end
88
+ end
89
+
90
+ context 'given one field' do
91
+ it 'creates a table of one column without a header (quiet mode)' do
92
+ subject = klass.new(data, 'a')
93
+ expect(subject).to receive(:create_table).with(nil, [['a1'], ['a2']]).and_return(true)
94
+ subject.table
95
+ end
96
+ end
97
+
98
+ context 'given a field mapping' do
99
+ it 'uses the field keys as header titles and values as data field keys' do
100
+ subject = klass.new(data, { 'First' => 'a', 'Third' => 'c' })
101
+ expect(subject).to receive(:create_table).with(['First', 'Third'], [['a1', 'c1'], ['a2', 'c2']]).and_return(true)
102
+ subject.table
103
+ end
104
+ end
105
+
106
+ context 'row formatting' do
107
+ it 'calls the format proc for all rows of data' do
108
+ format_proc = proc do |row|
109
+ row['d'] = [row['b'], row['c']].join('/')
110
+ end
111
+ expect(format_proc).to receive(:call).exactly(2).times.and_call_original
112
+ subject = klass.new(data, ['a', 'd'], row_format_proc: format_proc)
113
+ expect(subject).to receive(:create_table).with(['A', 'D'], [['a1', 'b1/c1'], ['a2', 'b2/c2']]).and_return(true)
114
+ subject.table
115
+ end
116
+ end
117
+ end
118
+ end
@@ -3,7 +3,7 @@ require "kontena/cli/version_command"
3
3
  describe Kontena::Cli::VersionCommand do
4
4
 
5
5
  include ClientHelpers
6
-
6
+
7
7
  let :http_client do
8
8
  double(:http_client)
9
9
  end
@@ -13,7 +13,7 @@ describe Kontena::Cli::VersionCommand do
13
13
  expect(client).to receive(:http_client).and_return(http_client)
14
14
  expect(http_client).to receive(:get).with(path: '/').and_return(double(body: '{"version": "0.1"}'))
15
15
 
16
- expect { subject.run([]) }.to output("cli: #{Kontena::Cli::VERSION}\nmaster: 0.1 (someurl)\n").to_stdout
16
+ expect { subject.run([]) }.to output("cli: #{Kontena::Cli::VERSION}\nmaster: 0.1 (#{subject.current_master.url})\n").to_stdout
17
17
  end
18
18
  end
19
19
  end
@@ -246,6 +246,7 @@ describe Kontena::Client do
246
246
  },
247
247
  double(:response,
248
248
  status: 418,
249
+ path: '/foo',
249
250
  reason_phrase: "I'm a teapot",
250
251
  headers: {
251
252
  'Content-Type' => 'short/stout',
@@ -257,7 +258,7 @@ describe Kontena::Client do
257
258
  end
258
259
 
259
260
  it "raises StandardError with the status phrase" do
260
- expect{subject.request(http_method: :brew, path: 'coffee')}.to raise_error(Kontena::Errors::StandardError, "I'm a teapot")
261
+ expect{subject.request(http_method: :brew, path: 'coffee')}.to raise_error(Kontena::Errors::StandardError, /I'm a teapot/)
261
262
  end
262
263
  end
263
264
 
@@ -272,7 +273,7 @@ describe Kontena::Client do
272
273
  end
273
274
 
274
275
  it "raises StandardError with the server error message" do
275
- expect{subject.post('print', { 'code' => "8A/HyA==" })}.to raise_error(Kontena::Errors::StandardError, "lp0 (printer) on fire")
276
+ expect{subject.post('print', { 'code' => "8A/HyA==" })}.to raise_error(Kontena::Errors::StandardError, /lp0 \(printer\) on fire/)
276
277
  end
277
278
  end
278
279
 
@@ -290,7 +291,7 @@ describe Kontena::Client do
290
291
  end
291
292
 
292
293
  it "raises StandardError with the server error message" do
293
- expect{subject.get('test')}.to raise_error(Kontena::Errors::StandardError, "You are wrong")
294
+ expect{subject.get('test')}.to raise_error(Kontena::Errors::StandardError, /You are wrong/)
294
295
  end
295
296
  end
296
297
 
@@ -21,8 +21,8 @@ module ClientHelpers
21
21
  {'current_server' => 'alias',
22
22
  'current_account' => 'kontena',
23
23
  'servers' => [
24
- {'name' => 'some_master', 'url' => 'some_master'},
25
- {'name' => 'alias', 'url' => 'someurl', 'token' => token, 'account' => 'master', 'grid' => current_grid},
24
+ {'name' => 'some_master', 'url' => 'http://someurl.example.com'},
25
+ {'name' => 'alias', 'url' => 'http://someurl.example.com/', 'token' => token, 'account' => 'master', 'grid' => current_grid},
26
26
  ]
27
27
  }
28
28
  end
@@ -31,7 +31,7 @@ module ClientHelpers
31
31
  RSpec::Mocks.space.proxy_for(File).reset
32
32
  allow(subject).to receive(:client).and_return(client)
33
33
  allow(subject).to receive(:current_grid).and_return(current_grid)
34
- allow(File).to receive(:exist?).with(File.join(Dir.home, '.kontena/certs/.pem')).and_return(false)
34
+ allow(File).to receive(:exist?).with(File.join(Dir.home, '.kontena/certs/someurl.example.com.pem')).and_return(false)
35
35
  allow(File).to receive(:exist?).with(File.join(Dir.home, '.kontena_client.json')).and_return(true)
36
36
  allow(File).to receive(:readable?).with(File.join(Dir.home, '.kontena_client.json')).and_return(true)
37
37
  allow(File).to receive(:read).and_call_original
@@ -5,6 +5,7 @@ module OutputHelpers
5
5
  supports_block_expectations
6
6
 
7
7
  match do |block|
8
+ @expected = expected
8
9
  stdout = lines.flatten.join("\n") + "\n"
9
10
 
10
11
  begin
@@ -14,7 +15,7 @@ module OutputHelpers
14
15
 
15
16
  return false
16
17
  else
17
- return values_match? expected, @return
18
+ return values_match? @expected, @return
18
19
  end
19
20
  end
20
21
 
@@ -22,7 +23,7 @@ module OutputHelpers
22
23
  if @error
23
24
  return @error
24
25
  else
25
- return "expected #{block} to return #{expected}, but returned #{@return}"
26
+ return "expected #{block} to return #{@expected}, but returned #{@return}"
26
27
  end
27
28
  end
28
29
  end
@@ -31,18 +32,51 @@ module OutputHelpers
31
32
  supports_block_expectations
32
33
 
33
34
  match do |block|
34
- stdout = Regexp.new('^' + lines.map{|fields| fields.join('\s+')}.join('\n') + '\n$', Regexp::MULTILINE)
35
-
36
-
35
+ @expected = lines
37
36
  begin
38
- expect{@return = block.call}.to output(stdout).to_stdout
37
+ @real = CaptureStdoutLines.capture(block)
39
38
  rescue Exception => error
40
39
  @error = error
41
-
42
40
  return false
41
+ end
42
+
43
+ if @expected_header
44
+ @expected.unshift(@expected_header)
45
+ elsif @no_header
46
+ nil
43
47
  else
44
- return true
48
+ @real.shift
49
+ end
50
+
51
+ if @expected.size == @real.size
52
+ line = 0
53
+ @real.zip(@expected) do |real, expected|
54
+ line += 1
55
+ error = values_match?(real.split(/\S+/), expected)
56
+ if error
57
+ @error ||= ""
58
+ @error << "\n#{error}"
59
+ @error.strip!
60
+ end
61
+ end
62
+ else
63
+ @error = "expected #{@expected.size} lines but got #{@real.size} lines instead:\n"
64
+ @error += "Expected:\n#{@expected.map(&:inspect).join("\n")}"
65
+ @error += "Received:\n#{@real.map(&:inspect).join("\n")}"
45
66
  end
67
+ @error.nil?
68
+ end
69
+
70
+ failure_message do |block|
71
+ @error
72
+ end
73
+
74
+ chain :with_header do |header|
75
+ @expected_header = header
76
+ end
77
+
78
+ chain :without_header do
79
+ @no_header = true
46
80
  end
47
81
 
48
82
  failure_message do |block|
@@ -71,4 +105,16 @@ module OutputHelpers
71
105
  return @error
72
106
  end
73
107
  end
108
+
109
+ module CaptureStdoutLines
110
+ def self.capture(block)
111
+ capture = StringIO.new
112
+ original = $stdout
113
+ $stdout = capture
114
+ block.call
115
+ capture.string.split(/[\r\n]/)
116
+ ensure
117
+ $stdout = original
118
+ end
119
+ end
74
120
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kontena-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0.pre1
4
+ version: 1.3.0.pre2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kontena, Inc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-24 00:00:00.000000000 Z
11
+ date: 2017-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -342,6 +342,8 @@ files:
342
342
  - lib/kontena/cli/helpers/health_helper.rb
343
343
  - lib/kontena/cli/helpers/log_helper.rb
344
344
  - lib/kontena/cli/localhost_web_server.rb
345
+ - lib/kontena/cli/log_formatters/compact.rb
346
+ - lib/kontena/cli/log_formatters/strip_color.rb
345
347
  - lib/kontena/cli/logout_command.rb
346
348
  - lib/kontena/cli/master/audit_log_command.rb
347
349
  - lib/kontena/cli/master/config/export_command.rb
@@ -466,6 +468,7 @@ files:
466
468
  - lib/kontena/cli/stacks/yaml/validations.rb
467
469
  - lib/kontena/cli/stacks/yaml/validator_v3.rb
468
470
  - lib/kontena/cli/subcommand_loader.rb
471
+ - lib/kontena/cli/table_generator.rb
469
472
  - lib/kontena/cli/vault/export_command.rb
470
473
  - lib/kontena/cli/vault/import_command.rb
471
474
  - lib/kontena/cli/vault/list_command.rb
@@ -602,6 +605,7 @@ files:
602
605
  - spec/kontena/cli/nodes/health_command_spec.rb
603
606
  - spec/kontena/cli/nodes/list_command_spec.rb
604
607
  - spec/kontena/cli/nodes/ssh_command_spec.rb
608
+ - spec/kontena/cli/registry/create_spec.rb
605
609
  - spec/kontena/cli/services/containers_command_spec.rb
606
610
  - spec/kontena/cli/services/events_command_spec.rb
607
611
  - spec/kontena/cli/services/exec_command_spec.rb
@@ -611,6 +615,7 @@ files:
611
615
  - spec/kontena/cli/services/secrets/link_command_spec.rb
612
616
  - spec/kontena/cli/services/secrets/unlink_command_spec.rb
613
617
  - spec/kontena/cli/services/services_helper_spec.rb
618
+ - spec/kontena/cli/services/stats_command_spec.rb
614
619
  - spec/kontena/cli/services/unlink_command_spec.rb
615
620
  - spec/kontena/cli/services/update_command_spec.rb
616
621
  - spec/kontena/cli/stacks/build_command_spec.rb
@@ -633,6 +638,7 @@ files:
633
638
  - spec/kontena/cli/stacks/yaml/reader_spec.rb
634
639
  - spec/kontena/cli/stacks/yaml/service_extender_spec.rb
635
640
  - spec/kontena/cli/stacks/yaml/validator_v3_spec.rb
641
+ - spec/kontena/cli/table_generator_spec.rb
636
642
  - spec/kontena/cli/vault/export_spec.rb
637
643
  - spec/kontena/cli/vault/import_spec.rb
638
644
  - spec/kontena/cli/vault/update_command_spec.rb
@@ -751,6 +757,7 @@ test_files:
751
757
  - spec/kontena/cli/nodes/health_command_spec.rb
752
758
  - spec/kontena/cli/nodes/list_command_spec.rb
753
759
  - spec/kontena/cli/nodes/ssh_command_spec.rb
760
+ - spec/kontena/cli/registry/create_spec.rb
754
761
  - spec/kontena/cli/services/containers_command_spec.rb
755
762
  - spec/kontena/cli/services/events_command_spec.rb
756
763
  - spec/kontena/cli/services/exec_command_spec.rb
@@ -760,6 +767,7 @@ test_files:
760
767
  - spec/kontena/cli/services/secrets/link_command_spec.rb
761
768
  - spec/kontena/cli/services/secrets/unlink_command_spec.rb
762
769
  - spec/kontena/cli/services/services_helper_spec.rb
770
+ - spec/kontena/cli/services/stats_command_spec.rb
763
771
  - spec/kontena/cli/services/unlink_command_spec.rb
764
772
  - spec/kontena/cli/services/update_command_spec.rb
765
773
  - spec/kontena/cli/stacks/build_command_spec.rb
@@ -782,6 +790,7 @@ test_files:
782
790
  - spec/kontena/cli/stacks/yaml/reader_spec.rb
783
791
  - spec/kontena/cli/stacks/yaml/service_extender_spec.rb
784
792
  - spec/kontena/cli/stacks/yaml/validator_v3_spec.rb
793
+ - spec/kontena/cli/table_generator_spec.rb
785
794
  - spec/kontena/cli/vault/export_spec.rb
786
795
  - spec/kontena/cli/vault/import_spec.rb
787
796
  - spec/kontena/cli/vault/update_command_spec.rb