wavefront-cli 2.18.0 → 3.0.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 (104) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +7 -0
  4. data/.travis.yml +4 -5
  5. data/HISTORY.md +20 -1
  6. data/README.md +79 -29
  7. data/lib/wavefront-cli/base.rb +26 -2
  8. data/lib/wavefront-cli/commands/alert.rb +10 -10
  9. data/lib/wavefront-cli/commands/base.rb +15 -2
  10. data/lib/wavefront-cli/commands/cloudintegration.rb +3 -3
  11. data/lib/wavefront-cli/commands/config.rb +2 -1
  12. data/lib/wavefront-cli/commands/dashboard.rb +8 -6
  13. data/lib/wavefront-cli/commands/derivedmetric.rb +5 -5
  14. data/lib/wavefront-cli/commands/event.rb +3 -3
  15. data/lib/wavefront-cli/commands/integration.rb +5 -5
  16. data/lib/wavefront-cli/commands/link.rb +3 -3
  17. data/lib/wavefront-cli/commands/message.rb +2 -2
  18. data/lib/wavefront-cli/commands/metric.rb +1 -1
  19. data/lib/wavefront-cli/commands/notificant.rb +3 -3
  20. data/lib/wavefront-cli/commands/proxy.rb +3 -3
  21. data/lib/wavefront-cli/commands/query.rb +3 -3
  22. data/lib/wavefront-cli/commands/savedsearch.rb +3 -3
  23. data/lib/wavefront-cli/commands/settings.rb +22 -0
  24. data/lib/wavefront-cli/commands/source.rb +3 -3
  25. data/lib/wavefront-cli/commands/user.rb +4 -4
  26. data/lib/wavefront-cli/commands/usergroup.rb +5 -8
  27. data/lib/wavefront-cli/commands/webhook.rb +3 -3
  28. data/lib/wavefront-cli/commands/window.rb +3 -3
  29. data/lib/wavefront-cli/commands/write.rb +6 -4
  30. data/lib/wavefront-cli/config.rb +14 -0
  31. data/lib/wavefront-cli/controller.rb +2 -0
  32. data/lib/wavefront-cli/dashboard.rb +133 -14
  33. data/lib/wavefront-cli/display/base.rb +28 -7
  34. data/lib/wavefront-cli/display/dashboard.rb +32 -8
  35. data/lib/wavefront-cli/display/distribution.rb +4 -1
  36. data/lib/wavefront-cli/display/printer/long.rb +149 -140
  37. data/lib/wavefront-cli/display/printer/terse.rb +19 -42
  38. data/lib/wavefront-cli/display/query.rb +6 -0
  39. data/lib/wavefront-cli/display/settings.rb +21 -0
  40. data/lib/wavefront-cli/display/write.rb +12 -5
  41. data/lib/wavefront-cli/event.rb +1 -1
  42. data/lib/wavefront-cli/exception.rb +1 -0
  43. data/lib/wavefront-cli/settings.rb +37 -0
  44. data/lib/wavefront-cli/stdlib/array.rb +20 -0
  45. data/lib/wavefront-cli/stdlib/string.rb +8 -0
  46. data/lib/wavefront-cli/user.rb +1 -1
  47. data/lib/wavefront-cli/version.rb +1 -1
  48. data/lib/wavefront-cli/write.rb +310 -10
  49. data/spec/.rubocop.yml +3 -0
  50. data/spec/spec_helper.rb +81 -1
  51. data/spec/wavefront-cli/alert_spec.rb +1 -0
  52. data/spec/wavefront-cli/cloudintegration_spec.rb +1 -0
  53. data/spec/wavefront-cli/dashboard_spec.rb +47 -4
  54. data/spec/wavefront-cli/derivedmetric_spec.rb +1 -0
  55. data/spec/wavefront-cli/display/base_spec.rb +16 -9
  56. data/spec/wavefront-cli/display/printer/long_spec.rb +75 -106
  57. data/spec/wavefront-cli/display/printer/terse_spec.rb +33 -21
  58. data/spec/wavefront-cli/event_spec.rb +1 -0
  59. data/spec/wavefront-cli/externallink_spec.rb +1 -0
  60. data/spec/wavefront-cli/integration_spec.rb +1 -0
  61. data/spec/wavefront-cli/maintenancewindow_spec.rb +1 -0
  62. data/spec/wavefront-cli/proxy_spec.rb +2 -0
  63. data/spec/wavefront-cli/query_spec.rb +9 -0
  64. data/spec/wavefront-cli/resources/display/alert-human-long +24 -0
  65. data/spec/wavefront-cli/resources/display/alert-input.json +37 -0
  66. data/spec/wavefront-cli/resources/display/alerts-human-terse +9 -0
  67. data/spec/wavefront-cli/resources/display/alerts-input.json +1 -0
  68. data/spec/wavefront-cli/resources/display/user-human-long +19 -0
  69. data/spec/wavefront-cli/resources/display/user-human-long-no_sep +18 -0
  70. data/spec/wavefront-cli/resources/display/user-input.json +1 -0
  71. data/spec/wavefront-cli/resources/responses/README.md +2 -0
  72. data/spec/wavefront-cli/resources/responses/alert-list.json +1 -0
  73. data/spec/wavefront-cli/resources/responses/backups.json +1 -0
  74. data/spec/wavefront-cli/resources/responses/cloudintegration-list.json +1 -0
  75. data/spec/wavefront-cli/resources/responses/dashboard-list.json +1 -0
  76. data/spec/wavefront-cli/resources/responses/derivedmetric-list.json +1 -0
  77. data/spec/wavefront-cli/resources/responses/event-list.json +1 -0
  78. data/spec/wavefront-cli/resources/responses/integration-list.json +1 -0
  79. data/spec/wavefront-cli/resources/responses/link-list.json +1 -0
  80. data/spec/wavefront-cli/resources/responses/notificant-list.json +1 -0
  81. data/spec/wavefront-cli/resources/responses/proxy-list.json +1 -0
  82. data/spec/wavefront-cli/resources/responses/query-cpu.json +1 -0
  83. data/spec/wavefront-cli/resources/responses/savedsearch-list.json +1 -0
  84. data/spec/wavefront-cli/resources/responses/user-list.json +1 -0
  85. data/spec/wavefront-cli/resources/responses/usergroup-list.json +1 -0
  86. data/spec/wavefront-cli/resources/responses/webhook-list.json +1 -0
  87. data/spec/wavefront-cli/resources/responses/window-list.json +1 -0
  88. data/spec/wavefront-cli/savedsearch_spec.rb +1 -0
  89. data/spec/wavefront-cli/settings_spec.rb +19 -0
  90. data/spec/wavefront-cli/stdlib/array_spec.rb +20 -0
  91. data/spec/wavefront-cli/stdlib/string_spec.rb +13 -1
  92. data/spec/wavefront-cli/user_spec.rb +1 -0
  93. data/spec/wavefront-cli/usergroup_spec.rb +1 -0
  94. data/spec/wavefront-cli/webhook_spec.rb +1 -0
  95. data/spec/wavefront-cli/write_spec.rb +167 -0
  96. data/wavefront-cli.gemspec +3 -4
  97. metadata +65 -31
  98. data/.gitlab-ci.yml +0 -16
  99. data/lib/wavefront-cli/base_write.rb +0 -298
  100. data/lib/wavefront-cli/commands/report.rb +0 -37
  101. data/lib/wavefront-cli/display/printer/base.rb +0 -24
  102. data/lib/wavefront-cli/display/report.rb +0 -17
  103. data/lib/wavefront-cli/report.rb +0 -18
  104. data/spec/wavefront-cli/display/printer/base_spec.rb +0 -20
data/spec/.rubocop.yml CHANGED
@@ -17,3 +17,6 @@ Metrics/AbcSize:
17
17
 
18
18
  Metrics/ClassLength:
19
19
  Max: 300
20
+
21
+ Metrics/CyclomaticComplexity:
22
+ Max: 10
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'json'
1
2
  require 'webmock/minitest'
2
3
  require 'spy/integration'
3
4
  require 'inifile'
@@ -76,7 +77,7 @@ CANNED_RESPONSE = DummyResponse.new
76
77
  # @param call [Hash]
77
78
  # rubocop:disable Metrics/AbcSize
78
79
  # rubocop:disable Metrics/PerceivedComplexity
79
- def cmd_to_call(word, args, call, sdk_class = nil)
80
+ def cmd_to_call(word, args, call, sdk_class = nil, extra_method = nil)
80
81
  headers = { 'Accept': /.*/,
81
82
  'Accept-Encoding': /.*/,
82
83
  'Authorization': 'Bearer 0123456789-ABCDEF',
@@ -114,6 +115,18 @@ def cmd_to_call(word, args, call, sdk_class = nil)
114
115
  end
115
116
 
116
117
  require "wavefront-sdk/#{sdk_class.name.split('::').last.downcase}"
118
+ # This lets us mock out methods which happen after the
119
+ # thing we're interested in. For instance when you
120
+ # favourite a dashboard, the CLI calls do_favs to display
121
+ # the new favourite list, sending another API call, which
122
+ # has been tested elsewhere.
123
+ #
124
+ if extra_method
125
+ Spy.on_instance_method(
126
+ Object.const_get(extra_method.first), extra_method.last
127
+ ).and_return(true)
128
+ end
129
+
117
130
  Spy.on_instance_method(
118
131
  Object.const_get('Wavefront::ApiCaller'), :respond
119
132
  ).and_return(CANNED_RESPONSE)
@@ -309,6 +322,36 @@ def load_raw_query_response
309
322
  symbolize_names: true)
310
323
  end
311
324
 
325
+ # We keep a bunch of Wavefront API responses as text files alongside
326
+ # canned responses in various formats. This class groups helpers for
327
+ # doing that.
328
+ #
329
+ class OutputTester
330
+ # @param file [String] filename to load
331
+ # @param only_items [Bool] true for the items hash, false for the
332
+ # whole loadedobject
333
+ # @return [Object] canned raw responses used to test outputs
334
+ #
335
+ def load_input(file, only_items = true)
336
+ ret = JSON.parse(IO.read(RES_DIR + 'display' + file),
337
+ symbolize_names: true)
338
+ only_items ? ret[:items] : ret
339
+ end
340
+
341
+ # @param file [String] file to load
342
+ # @return [String]
343
+ #
344
+ def load_expected(file)
345
+ IO.read(RES_DIR + 'display' + file)
346
+ end
347
+
348
+ def in_and_out(input, expected, only_items = true)
349
+ [load_input(input, only_items), load_expected(expected)]
350
+ end
351
+ end
352
+
353
+ OUTPUT_TESTER = OutputTester.new
354
+
312
355
  # stdlib extensions
313
356
  #
314
357
  class Hash
@@ -318,3 +361,40 @@ class Hash
318
361
  Marshal.load(Marshal.dump(self))
319
362
  end
320
363
  end
364
+
365
+ require 'wavefront-sdk/core/response'
366
+ require_relative '../lib/wavefront-cli/base'
367
+
368
+ # For the given command word, loads up a canned API response and
369
+ # feeds it in to the appropriate display class, running the given
370
+ # method and returning standard out and standard error.
371
+ #
372
+ # @param word [String] command word, e.g. 'alert'
373
+ # @param method [Symbol] display method to run, e.g. :do_list
374
+ # @param klass [Class, Nil] CLI class. Worked out from the command
375
+ # word in most cases, but must be overriden for two-word things.
376
+ # @return [Array] [stdout, stderr]
377
+ #
378
+ def command_output(word, method, klass = nil, infile = nil)
379
+ infile ||= "#{word}-list.json"
380
+ json = IO.read(RES_DIR + 'responses' + infile)
381
+ resp = Wavefront::Response.new(json, 200)
382
+ klass ||= Object.const_get(format('WavefrontCli::%s', word.capitalize))
383
+ klass = klass.new(format: :human)
384
+
385
+ capture_io { klass.display(resp, method) }
386
+ end
387
+
388
+ def test_list_output(word, klass = nil)
389
+ it 'tests terse output' do
390
+ out, err = command_output(word, :do_list_brief, klass)
391
+ refute_empty(out)
392
+ assert_empty(err)
393
+ end
394
+
395
+ it 'tests long output' do
396
+ out, err = command_output(word, :do_list_long, klass)
397
+ refute_empty(out)
398
+ assert_empty(err)
399
+ end
400
+ end
@@ -89,4 +89,5 @@ describe "#{word} command" do
89
89
  cmd_to_call(word, 'queries', path: "/api/v2/#{word}?limit=999&offset=0")
90
90
  tag_tests(word, id, bad_id)
91
91
  noop_tests(word, id, true)
92
+ test_list_output(word)
92
93
  end
@@ -38,4 +38,5 @@ describe 'cloudintegration command' do
38
38
  invalid_ids(word, ["describe #{bad_id}", "delete #{bad_id}",
39
39
  "undelete #{bad_id}", "disable #{bad_id}",
40
40
  "enable #{bad_id}"])
41
+ test_list_output(word, k)
41
42
  end
@@ -7,6 +7,28 @@ word = 'dashboard'
7
7
  require_relative '../spec_helper'
8
8
  require_relative "../../lib/wavefront-cli/#{word}"
9
9
 
10
+ # Method tests. CLI tests follow
11
+ #
12
+ class WavefrontCliDashboardTest < MiniTest::Test
13
+ attr_reader :wf
14
+
15
+ def setup
16
+ @wf = WavefrontCli::Dashboard.new({})
17
+ end
18
+
19
+ def test_user_lists
20
+ assert_equal({ modify: [],
21
+ view: [{ name: 'a@bc.com', id: 'a@bc.com' },
22
+ { name: 'x@yz.com', id: 'x@yz.com' }] },
23
+ wf.user_lists(:view, %w[a@bc.com x@yz.com]))
24
+
25
+ assert_equal({ view: [],
26
+ modify: [{ name: 'a@bc.com', id: 'a@bc.com' },
27
+ { name: 'x@yz.com', id: 'x@yz.com' }] },
28
+ wf.user_lists(:modify, %w[a@bc.com x@yz.com]))
29
+ end
30
+ end
31
+
10
32
  describe "#{word} command" do
11
33
  missing_creds(word, ['list', "describe #{id}", "delete #{id}",
12
34
  "undelete #{id}", "history #{id}"])
@@ -39,14 +61,35 @@ describe "#{word} command" do
39
61
  matchingMethod: 'EXACT' }],
40
62
  sort: { field: 'id', ascending: true } },
41
63
  headers: JSON_POST_HEADERS)
64
+ cmd_to_call(word,
65
+ 'favs',
66
+ method: :post,
67
+ path: "/api/v2/search/#{word}",
68
+ body: { limit: 999,
69
+ offset: 0,
70
+ query: [{ key: 'favorite',
71
+ value: 'true',
72
+ matchingMethod: 'EXACT' }],
73
+ sort: { field: 'id',
74
+ ascending: true } }.to_json)
75
+
76
+ cmd_to_call(word,
77
+ "fav #{id}",
78
+ { method: :post,
79
+ path: "/api/v2/#{word}/#{id}/favorite" },
80
+ nil,
81
+ ['WavefrontCli::Dashboard', :do_favs])
42
82
 
43
- cmd_to_call(word, "fav #{id}",
44
- method: :post, path: "/api/v2/#{word}/#{id}/favorite")
45
- cmd_to_call(word, "unfav #{id}",
46
- method: :post, path: "/api/v2/#{word}/#{id}/unfavorite")
83
+ cmd_to_call(word,
84
+ "unfav #{id}",
85
+ { method: :post,
86
+ path: "/api/v2/#{word}/#{id}/unfavorite" },
87
+ nil,
88
+ ['WavefrontCli::Dashboard', :do_favs])
47
89
  cmd_to_call(word, "undelete #{id}",
48
90
  method: :post, path: "/api/v2/#{word}/#{id}/undelete")
49
91
  invalid_ids(word, ["describe #{bad_id}", "delete #{bad_id}",
50
92
  "undelete #{bad_id}"])
51
93
  tag_tests(word, id, bad_id)
94
+ test_list_output(word)
52
95
  end
@@ -77,4 +77,5 @@ describe "#{word} command" do
77
77
  tags: %w[tag1 tag2],
78
78
  query: 'ts(series)' },
79
79
  headers: JSON_POST_HEADERS }, k)
80
+ test_list_output(word, k)
80
81
  end
@@ -21,17 +21,24 @@ class WavefrontDisplayBaseTest < MiniTest::Test
21
21
  @wff = WavefrontDisplay::Base.new(S_DATA, S_OPTIONS.merge(fields: 'id'))
22
22
  end
23
23
 
24
- def test_put_id_first
25
- assert_equal(wf.put_id_first(k1: 1, k2: 2, id: 3, k4: 4),
26
- id: 3, k1: 1, k2: 2, k4: 4)
27
- assert_equal(wf.put_id_first(id: 3, k1: 1, k2: 2, k4: 4),
28
- id: 3, k1: 1, k2: 2, k4: 4)
29
- assert_equal(wf.put_id_first(k2: 1, k1: 2, k4: 4),
30
- k2: 1, k1: 2, k4: 4)
24
+ def test_prioritise_keys
25
+ assert_equal({ a: 1, b: 2, c: 3, d: 4 },
26
+ wf.prioritize_keys({ b: 2, c: 3, a: 1, d: 4 }, %i[a b]))
27
+
28
+ assert_equal({ id: 'my id', name: 'my name', numbers: [1, 2, 3] },
29
+ wf.prioritize_keys({ name: 'my name',
30
+ numbers: [1, 2, 3],
31
+ id: 'my id' }, %i[id name]))
32
+
33
+ assert_equal({ name: 'my name', id: 'my id', numbers: [1, 2, 3] },
34
+ wf.prioritize_keys({ name: 'my name',
35
+ numbers: [1, 2, 3],
36
+ id: 'my id' }, %i[name id]))
37
+ assert_equal([{ a: 1, b: 2, c: 3, d: 4 }, { a: 5, b: 6 }],
38
+ wf.prioritize_keys([{ b: 2, c: 3, a: 1, d: 4 },
39
+ { b: 6, a: 5 }], %i[a b]))
31
40
  end
32
41
 
33
- def test_run; end
34
-
35
42
  def test_friendly_name
36
43
  assert_equal(wf.friendly_name, 'base')
37
44
  end
@@ -6,135 +6,104 @@ require_relative '../../../spec_helper'
6
6
 
7
7
  # Test verbose printing stuff
8
8
  #
9
- class WavefrontDisplayPrinterLong < MiniTest::Test
9
+ class TestWavefrontDisplayPrinterLong < MiniTest::Test
10
10
  attr_reader :wf
11
11
 
12
12
  def setup
13
13
  @wf = WavefrontDisplayPrinter::Long.new({})
14
14
  end
15
15
 
16
- def test_mk_line_1
17
- wf.instance_variable_set(:@kw, 5)
18
- wf.instance_variable_set(:@indent_str, '')
19
- assert_equal(' value', wf.mk_line('', 'value'))
20
- assert_equal(' value', wf.mk_line(nil, 'value'))
21
- assert_equal('key value', wf.mk_line('key', 'value'))
16
+ def test_preened_data
17
+ assert_equal([{ k1: 1 }], wf.preened_data([{ k1: 1, k2: 2 }], [:k1]))
18
+ assert_equal([{ k1: 1, k2: 2 }], wf.preened_data([{ k1: 1, k2: 2 }]))
19
+ assert_equal([{}], wf.preened_data([{ k1: 1, k2: 2 }], [:k3]))
20
+ assert_equal([{ k1: 1, k2: 2 }], wf.preened_data([{ k1: 1, k2: 2 }],
21
+ %i[k1 k2]))
22
+ assert_equal([{ k1: 1 }, { k1: 10 }],
23
+ wf.preened_data([{ k1: 1, k2: 2 }, { k1: 10, k2: 12 }],
24
+ [:k1]))
25
+
26
+ assert_equal([{ 'k1' => 1 }, { 'k1' => 10 }],
27
+ wf.preened_data([{ 'k1' => 1, 'k2' => 2 },
28
+ { 'k1' => 10, 'k2' => 12 }],
29
+ [:k1]))
22
30
  end
23
31
 
24
- def test_mk_line_2
25
- wf = WavefrontDisplayPrinter::Long.new({})
26
- wf.mk_indent(2)
27
- wf.instance_variable_set(:@kw, 5)
28
- assert_equal(' value', wf.mk_line('', 'value'))
29
- assert_equal(' value', wf.mk_line(nil, 'value'))
30
- assert_equal(' key value', wf.mk_line('key', 'value'))
32
+ def test_preened_value
33
+ assert_equal('test', wf.preened_value('test'))
34
+ assert_equal('test', wf.preened_value('<b>test</b>'))
35
+ assert_equal('test test', wf.preened_value('<b>test</b> <i>test</i>'))
31
36
  end
32
37
 
33
- def test_mk_line_3
34
- wf.instance_variable_set(:@kw, 7)
35
- wf.instance_variable_set(:@indent_str, ' ')
36
- assert_equal(' key value', wf.mk_line('key', 'value'))
37
- assert_equal(' value', wf.mk_line(nil, 'value'))
38
- assert_equal(' value', wf.mk_line('', 'value'))
39
- assert_equal(" key a long string which must be\n" \
40
- ' folded once',
41
- wf.mk_line('key', 'a long string which must be ' \
42
- 'folded once', 40))
43
- assert_equal(" key a very long string whose very length\n" \
44
- " means that the method is going to\n" \
45
- ' have to fold it twice',
46
- wf.mk_line('key', 'a very long string whose very ' \
47
- 'length means that the method is going to ' \
48
- 'have to fold it twice', 49))
38
+ def test_smart_value
39
+ wf1 = WavefrontDisplayPrinter::Long.new({}, nil, nil, none: false)
40
+ assert_equal('value', wf.smart_value('value'))
41
+ assert_equal('<none>', wf.smart_value(''))
42
+ assert_equal('', wf1.smart_value(''))
49
43
  end
50
44
 
51
- def test_mk_indent
52
- wf.mk_indent(2)
53
- assert_equal(wf.instance_variable_get(:@indent_str), ' ')
45
+ def test_opts
46
+ pr = WavefrontDisplayPrinter::Long.new({}, {})
47
+ assert_equal(pr.default_opts, pr.opts)
48
+
49
+ pr = WavefrontDisplayPrinter::Long.new({}, nil, nil,
50
+ indent: 4, padding: 3)
51
+ assert_equal({ indent: 4,
52
+ padding: 3,
53
+ separator: true,
54
+ none: true }, pr.opts)
55
+
56
+ pr = WavefrontDisplayPrinter::Long.new({}, nil, nil, none: false)
57
+ assert_equal({ indent: 2,
58
+ padding: 2,
59
+ separator: true,
60
+ none: false }, pr.opts)
54
61
  end
55
62
 
56
- def test_preen_fields
57
- assert_equal(wf.preen_fields({ k1: 1, k2: 2 }, [:k1]), k1: 1)
58
- assert_equal(wf.preen_fields(k1: 1, k2: 2), k1: 1, k2: 2)
59
- assert_equal(wf.preen_fields({ k1: 1, k2: 2 }, [:k3]), {})
60
- assert_equal(wf.preen_fields({ k1: 1, k2: 2 }, %i[k1 k2]),
61
- k1: 1, k2: 2)
62
- end
63
-
64
- def test_preen_value
65
- assert_equal(wf.preen_value('test'), 'test')
66
- assert_equal(wf.preen_value('<b>test</b>'), 'test')
67
- assert_equal(wf.preen_value('<b>test</b> <i>test</i>'), 'test test')
68
- end
69
-
70
- def test_blank?
71
- assert wf.blank?('')
72
- assert wf.blank?([])
73
- assert wf.blank?({})
74
- refute wf.blank?('test')
75
- refute wf.blank?(5)
76
- refute wf.blank?([1, 2])
77
- refute wf.blank?(a: 1)
78
- end
63
+ def test_longest_key_col
64
+ input = [['short', 'short', 0],
65
+ ['loooooooooooong', 'long', 1],
66
+ ['long-ish', 'longish', 0]]
79
67
 
80
- def test_parse_line_1
81
- assert_nil wf.parse_line(:k, [])
82
- spy = Spy.on(wf, :add_hash)
83
- wf.parse_line('key', k1: 1, k2: 2)
84
- assert spy.has_been_called_with?('key', k1: 1, k2: 2)
85
- end
68
+ pr = WavefrontDisplayPrinter::Long.new({})
69
+ assert_equal(19, pr.longest_key_col(input))
86
70
 
87
- def test_parse_line_2
88
- spy = Spy.on(wf, :add_array)
89
- wf.parse_line('key', [1, 2, 3, 4])
90
- assert spy.has_been_called_with?('key', [1, 2, 3, 4])
91
- end
71
+ pr = WavefrontDisplayPrinter::Long.new({}, nil, nil, indent: 4)
72
+ assert_equal(21, pr.longest_key_col(input))
92
73
 
93
- def test_parse_line_3
94
- spy = Spy.on(wf, :add_line)
95
- wf.parse_line('key', 'value')
96
- assert spy.has_been_called_with?('key', 'value')
74
+ pr = WavefrontDisplayPrinter::Long.new({}, nil, nil, padding: 5)
75
+ assert_equal(22, pr.longest_key_col(input))
97
76
  end
98
77
 
99
- def test_add_array
100
- spy = Spy.on(wf, :add_line)
101
- wf.add_array('key', %w[value1 value2 value3 value4])
102
- assert spy.has_been_called_with?('key', 'value1')
103
- assert spy.has_been_called_with?(nil, 'value2')
104
- assert spy.has_been_called_with?(nil, 'value3')
105
- assert spy.has_been_called_with?(nil, 'value4')
106
- end
78
+ def test_to_s
79
+ assert_equal("today\n weather sunny\n day Tuesday",
80
+ WavefrontDisplayPrinter::Long.new(
81
+ today: { weather: 'sunny', day: :Tuesday }
82
+ ).to_s)
107
83
 
108
- def test_add_hash_1
109
- hash = { sk1: 'value1', sk2: 'value2' }
110
- wf.instance_variable_set(:@kw, 10)
111
- wf.instance_variable_set(:@indent_step, 2)
112
- tc_spy = Spy.on(wf, :_two_columns)
113
- hr_spy = Spy.on(wf, :add_rule)
114
- wf.add_hash('key', hash)
115
- assert tc_spy.has_been_called_with?([hash], 6)
116
- refute hr_spy.has_been_called?
84
+ assert_equal("key1 val1\nkey2 val2",
85
+ WavefrontDisplayPrinter::Long.new(
86
+ key1: 'val1', key2: 'val2'
87
+ ).to_s)
117
88
  end
118
89
 
119
- def test_add_hash_2
120
- hash = { sk1: 'value1', sk2: 'value2' }
121
- wf.instance_variable_set(:@kw, 10)
122
- wf.instance_variable_set(:@indent_step, 2)
123
- tc_spy = Spy.on(wf, :_two_columns)
124
- hr_spy = Spy.on(wf, :add_rule)
125
- wf.add_hash('key', hash, 3, 1)
126
- assert tc_spy.has_been_called_with?([hash], 6)
127
- assert hr_spy.has_been_called?
90
+ def test_end_to_end
91
+ input, expected = OUTPUT_TESTER.in_and_out('user-input.json',
92
+ 'user-human-long')
93
+ output = WavefrontDisplayPrinter::Long.new(input).to_s
94
+ assert_equal(expected, output + "\n")
95
+
96
+ input, expected = OUTPUT_TESTER.in_and_out('user-input.json',
97
+ 'user-human-long-no_sep')
98
+ output = WavefrontDisplayPrinter::Long.new(input, nil, nil,
99
+ separator: false).to_s
100
+ assert_equal(expected, output + "\n")
128
101
  end
129
102
 
130
- def test_add_hash_3
131
- hash = { sk1: 'value1', sk2: 'value2' }
132
- wf.instance_variable_set(:@kw, 10)
133
- wf.instance_variable_set(:@indent_step, 2)
134
- tc_spy = Spy.on(wf, :_two_columns)
135
- hr_spy = Spy.on(wf, :add_rule)
136
- wf.add_hash('key', hash, 3, 2)
137
- assert tc_spy.has_been_called_with?([hash], 6)
138
- refute hr_spy.has_been_called?
103
+ def test_end_to_end_fold
104
+ input, expected = OUTPUT_TESTER.in_and_out('alert-input.json',
105
+ 'alert-human-long')
106
+ output = WavefrontDisplayPrinter::Long.new(input).to_s
107
+ assert_equal(expected, output + "\n")
139
108
  end
140
109
  end