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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +7 -0
- data/.travis.yml +4 -5
- data/HISTORY.md +20 -1
- data/README.md +79 -29
- data/lib/wavefront-cli/base.rb +26 -2
- data/lib/wavefront-cli/commands/alert.rb +10 -10
- data/lib/wavefront-cli/commands/base.rb +15 -2
- data/lib/wavefront-cli/commands/cloudintegration.rb +3 -3
- data/lib/wavefront-cli/commands/config.rb +2 -1
- data/lib/wavefront-cli/commands/dashboard.rb +8 -6
- data/lib/wavefront-cli/commands/derivedmetric.rb +5 -5
- data/lib/wavefront-cli/commands/event.rb +3 -3
- data/lib/wavefront-cli/commands/integration.rb +5 -5
- data/lib/wavefront-cli/commands/link.rb +3 -3
- data/lib/wavefront-cli/commands/message.rb +2 -2
- data/lib/wavefront-cli/commands/metric.rb +1 -1
- data/lib/wavefront-cli/commands/notificant.rb +3 -3
- data/lib/wavefront-cli/commands/proxy.rb +3 -3
- data/lib/wavefront-cli/commands/query.rb +3 -3
- data/lib/wavefront-cli/commands/savedsearch.rb +3 -3
- data/lib/wavefront-cli/commands/settings.rb +22 -0
- data/lib/wavefront-cli/commands/source.rb +3 -3
- data/lib/wavefront-cli/commands/user.rb +4 -4
- data/lib/wavefront-cli/commands/usergroup.rb +5 -8
- data/lib/wavefront-cli/commands/webhook.rb +3 -3
- data/lib/wavefront-cli/commands/window.rb +3 -3
- data/lib/wavefront-cli/commands/write.rb +6 -4
- data/lib/wavefront-cli/config.rb +14 -0
- data/lib/wavefront-cli/controller.rb +2 -0
- data/lib/wavefront-cli/dashboard.rb +133 -14
- data/lib/wavefront-cli/display/base.rb +28 -7
- data/lib/wavefront-cli/display/dashboard.rb +32 -8
- data/lib/wavefront-cli/display/distribution.rb +4 -1
- data/lib/wavefront-cli/display/printer/long.rb +149 -140
- data/lib/wavefront-cli/display/printer/terse.rb +19 -42
- data/lib/wavefront-cli/display/query.rb +6 -0
- data/lib/wavefront-cli/display/settings.rb +21 -0
- data/lib/wavefront-cli/display/write.rb +12 -5
- data/lib/wavefront-cli/event.rb +1 -1
- data/lib/wavefront-cli/exception.rb +1 -0
- data/lib/wavefront-cli/settings.rb +37 -0
- data/lib/wavefront-cli/stdlib/array.rb +20 -0
- data/lib/wavefront-cli/stdlib/string.rb +8 -0
- data/lib/wavefront-cli/user.rb +1 -1
- data/lib/wavefront-cli/version.rb +1 -1
- data/lib/wavefront-cli/write.rb +310 -10
- data/spec/.rubocop.yml +3 -0
- data/spec/spec_helper.rb +81 -1
- data/spec/wavefront-cli/alert_spec.rb +1 -0
- data/spec/wavefront-cli/cloudintegration_spec.rb +1 -0
- data/spec/wavefront-cli/dashboard_spec.rb +47 -4
- data/spec/wavefront-cli/derivedmetric_spec.rb +1 -0
- data/spec/wavefront-cli/display/base_spec.rb +16 -9
- data/spec/wavefront-cli/display/printer/long_spec.rb +75 -106
- data/spec/wavefront-cli/display/printer/terse_spec.rb +33 -21
- data/spec/wavefront-cli/event_spec.rb +1 -0
- data/spec/wavefront-cli/externallink_spec.rb +1 -0
- data/spec/wavefront-cli/integration_spec.rb +1 -0
- data/spec/wavefront-cli/maintenancewindow_spec.rb +1 -0
- data/spec/wavefront-cli/proxy_spec.rb +2 -0
- data/spec/wavefront-cli/query_spec.rb +9 -0
- data/spec/wavefront-cli/resources/display/alert-human-long +24 -0
- data/spec/wavefront-cli/resources/display/alert-input.json +37 -0
- data/spec/wavefront-cli/resources/display/alerts-human-terse +9 -0
- data/spec/wavefront-cli/resources/display/alerts-input.json +1 -0
- data/spec/wavefront-cli/resources/display/user-human-long +19 -0
- data/spec/wavefront-cli/resources/display/user-human-long-no_sep +18 -0
- data/spec/wavefront-cli/resources/display/user-input.json +1 -0
- data/spec/wavefront-cli/resources/responses/README.md +2 -0
- data/spec/wavefront-cli/resources/responses/alert-list.json +1 -0
- data/spec/wavefront-cli/resources/responses/backups.json +1 -0
- data/spec/wavefront-cli/resources/responses/cloudintegration-list.json +1 -0
- data/spec/wavefront-cli/resources/responses/dashboard-list.json +1 -0
- data/spec/wavefront-cli/resources/responses/derivedmetric-list.json +1 -0
- data/spec/wavefront-cli/resources/responses/event-list.json +1 -0
- data/spec/wavefront-cli/resources/responses/integration-list.json +1 -0
- data/spec/wavefront-cli/resources/responses/link-list.json +1 -0
- data/spec/wavefront-cli/resources/responses/notificant-list.json +1 -0
- data/spec/wavefront-cli/resources/responses/proxy-list.json +1 -0
- data/spec/wavefront-cli/resources/responses/query-cpu.json +1 -0
- data/spec/wavefront-cli/resources/responses/savedsearch-list.json +1 -0
- data/spec/wavefront-cli/resources/responses/user-list.json +1 -0
- data/spec/wavefront-cli/resources/responses/usergroup-list.json +1 -0
- data/spec/wavefront-cli/resources/responses/webhook-list.json +1 -0
- data/spec/wavefront-cli/resources/responses/window-list.json +1 -0
- data/spec/wavefront-cli/savedsearch_spec.rb +1 -0
- data/spec/wavefront-cli/settings_spec.rb +19 -0
- data/spec/wavefront-cli/stdlib/array_spec.rb +20 -0
- data/spec/wavefront-cli/stdlib/string_spec.rb +13 -1
- data/spec/wavefront-cli/user_spec.rb +1 -0
- data/spec/wavefront-cli/usergroup_spec.rb +1 -0
- data/spec/wavefront-cli/webhook_spec.rb +1 -0
- data/spec/wavefront-cli/write_spec.rb +167 -0
- data/wavefront-cli.gemspec +3 -4
- metadata +65 -31
- data/.gitlab-ci.yml +0 -16
- data/lib/wavefront-cli/base_write.rb +0 -298
- data/lib/wavefront-cli/commands/report.rb +0 -37
- data/lib/wavefront-cli/display/printer/base.rb +0 -24
- data/lib/wavefront-cli/display/report.rb +0 -17
- data/lib/wavefront-cli/report.rb +0 -18
- data/spec/wavefront-cli/display/printer/base_spec.rb +0 -20
data/spec/.rubocop.yml
CHANGED
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
|
|
@@ -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,
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
|
@@ -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
|
|
25
|
-
assert_equal(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
|
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
|
|
17
|
-
wf.
|
|
18
|
-
wf.
|
|
19
|
-
assert_equal(
|
|
20
|
-
assert_equal(
|
|
21
|
-
|
|
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
|
|
25
|
-
wf
|
|
26
|
-
wf.
|
|
27
|
-
wf.
|
|
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
|
|
34
|
-
|
|
35
|
-
wf.
|
|
36
|
-
assert_equal('
|
|
37
|
-
assert_equal('
|
|
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
|
|
52
|
-
|
|
53
|
-
assert_equal(
|
|
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
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
81
|
-
|
|
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
|
-
|
|
88
|
-
|
|
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
|
-
|
|
94
|
-
|
|
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
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|