wavefront-cli 0.0.5 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -1
- data/Gemfile +1 -1
- data/README.md +21 -21
- data/Rakefile +2 -2
- data/bin/{wavefront → wf} +6 -2
- data/lib/wavefront-cli/alert.rb +7 -6
- data/lib/wavefront-cli/base.rb +27 -6
- data/lib/wavefront-cli/commands/alert.rb +2 -1
- data/lib/wavefront-cli/commands/base.rb +54 -29
- data/lib/wavefront-cli/commands/dashboard.rb +1 -0
- data/lib/wavefront-cli/commands/event.rb +7 -3
- data/lib/wavefront-cli/commands/integration.rb +2 -1
- data/lib/wavefront-cli/commands/link.rb +2 -2
- data/lib/wavefront-cli/commands/proxy.rb +2 -1
- data/lib/wavefront-cli/commands/savedsearch.rb +2 -1
- data/lib/wavefront-cli/commands/source.rb +3 -2
- data/lib/wavefront-cli/commands/webhook.rb +2 -1
- data/lib/wavefront-cli/commands/window.rb +2 -1
- data/lib/wavefront-cli/commands/write.rb +10 -6
- data/lib/wavefront-cli/constants.rb +1 -1
- data/lib/wavefront-cli/controller.rb +6 -4
- data/lib/wavefront-cli/dashboard.rb +6 -6
- data/lib/wavefront-cli/display/alert.rb +8 -4
- data/lib/wavefront-cli/display/base.rb +115 -170
- data/lib/wavefront-cli/display/cloudintegration.rb +2 -2
- data/lib/wavefront-cli/display/event.rb +1 -1
- data/lib/wavefront-cli/display/maintenancewindow.rb +1 -1
- data/lib/wavefront-cli/display/metric.rb +6 -7
- data/lib/wavefront-cli/display/printer/base.rb +24 -0
- data/lib/wavefront-cli/display/printer/long.rb +186 -0
- data/lib/wavefront-cli/display/printer/terse.rb +55 -0
- data/lib/wavefront-cli/display/query.rb +1 -2
- data/lib/wavefront-cli/display/savedsearch.rb +1 -1
- data/lib/wavefront-cli/display/source.rb +7 -3
- data/lib/wavefront-cli/display/webhook.rb +3 -4
- data/lib/wavefront-cli/event.rb +62 -23
- data/lib/wavefront-cli/exception.rb +1 -1
- data/lib/wavefront-cli/opt_handler.rb +6 -6
- data/lib/wavefront-cli/query.rb +5 -6
- data/lib/wavefront-cli/source.rb +5 -1
- data/lib/wavefront-cli/string.rb +59 -0
- data/lib/wavefront-cli/version.rb +1 -1
- data/lib/wavefront-cli/write.rb +4 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/wavefront-cli/alert_spec.rb +16 -5
- data/spec/wavefront-cli/base_spec.rb +5 -2
- data/spec/wavefront-cli/cli_help_spec.rb +7 -5
- data/spec/wavefront-cli/cloudintegration_spec.rb +9 -0
- data/spec/wavefront-cli/commands/alert_spec.rb +16 -0
- data/spec/wavefront-cli/commands/base_spec.rb +133 -0
- data/spec/wavefront-cli/commands/dashboard_spec.rb +16 -0
- data/spec/wavefront-cli/commands/event_spec.rb +17 -0
- data/spec/wavefront-cli/commands/integration_spec.rb +21 -0
- data/spec/wavefront-cli/commands/link_spec.rb +21 -0
- data/spec/wavefront-cli/commands/message_spec.rb +16 -0
- data/spec/wavefront-cli/commands/metric_spec.rb +16 -0
- data/spec/wavefront-cli/commands/proxy_spec.rb +16 -0
- data/spec/wavefront-cli/commands/query_spec.rb +16 -0
- data/spec/wavefront-cli/commands/spec_helper.rb +4 -0
- data/spec/wavefront-cli/commands/webhook_spec.rb +16 -0
- data/spec/wavefront-cli/commands/window_spec.rb +21 -0
- data/spec/wavefront-cli/commands/write_spec.rb +17 -0
- data/spec/wavefront-cli/dashboard_spec.rb +14 -4
- data/spec/wavefront-cli/display/base_spec.rb +162 -0
- data/spec/wavefront-cli/display/printer/base_spec.rb +20 -0
- data/spec/wavefront-cli/display/printer/long_spec.rb +137 -0
- data/spec/wavefront-cli/display/printer/terse_spec.rb +46 -0
- data/spec/wavefront-cli/display/spec_helper.rb +5 -0
- data/spec/wavefront-cli/event_spec.rb +9 -0
- data/spec/wavefront-cli/externallink_spec.rb +9 -0
- data/spec/wavefront-cli/maintanancewindow_spec.rb +10 -0
- data/spec/wavefront-cli/proxy_spec.rb +9 -0
- data/spec/wavefront-cli/savedsearch_spec.rb +9 -0
- data/spec/wavefront-cli/source_spec.rb +13 -1
- data/spec/wavefront-cli/string_spec.rb +51 -0
- data/spec/wavefront-cli/user_spec.rb +2 -2
- data/spec/wavefront-cli/webhook_spec.rb +9 -0
- data/wavefront-cli.gemspec +5 -5
- metadata +59 -22
- data/Gemfile.lock +0 -65
@@ -26,6 +26,8 @@ DISP_DATA = {
|
|
26
26
|
b: %w(list_1 list_2)
|
27
27
|
}.freeze
|
28
28
|
|
29
|
+
# Test base class
|
30
|
+
#
|
29
31
|
class WavefrontCliBaseTest < MiniTest::Test
|
30
32
|
attr_reader :wf, :wf_cmd
|
31
33
|
|
@@ -37,11 +39,12 @@ class WavefrontCliBaseTest < MiniTest::Test
|
|
37
39
|
|
38
40
|
def test_mk_creds
|
39
41
|
assert_equal wf.mk_creds, endpoint: 'test.wavefront.com',
|
40
|
-
token: '0123456789-ABCDEF'
|
42
|
+
token: '0123456789-ABCDEF',
|
43
|
+
agent: "wavefront-cli-#{WF_CLI_VERSION}"
|
41
44
|
end
|
42
45
|
|
43
46
|
def test_dispatch
|
44
47
|
assert_raises(WavefrontCli::Exception::UnhandledCommand) { wf.dispatch }
|
45
|
-
#assert_equal(wf_cmd.dispatch, nil)
|
48
|
+
# assert_equal(wf_cmd.dispatch, nil)
|
46
49
|
end
|
47
50
|
end
|
@@ -11,8 +11,8 @@ class WavefrontCliHelpTest < MiniTest::Test
|
|
11
11
|
rescue SystemExit => e
|
12
12
|
assert_equal(1, e.status)
|
13
13
|
assert_match(/^Usage/, e.message)
|
14
|
-
assert_match(/^
|
15
|
-
assert_match(/^
|
14
|
+
assert_match(/^ \w+ --version$/, e.message)
|
15
|
+
assert_match(/^ \w+ --help$/, e.message)
|
16
16
|
end
|
17
17
|
|
18
18
|
def test_version
|
@@ -27,20 +27,22 @@ class WavefrontCliHelpTest < MiniTest::Test
|
|
27
27
|
rescue SystemExit => e
|
28
28
|
assert_equal(1, e.status)
|
29
29
|
assert_match(/^Commands:$/, e.message)
|
30
|
-
CMDS.each
|
31
|
-
assert_match(/^ #{cmd} /, e.message)
|
32
|
-
end
|
30
|
+
CMDS.each { |cmd| assert_match(/^ #{cmd} /, e.message) }
|
33
31
|
end
|
34
32
|
|
33
|
+
# rubocop:disable Metrics/AbcSize
|
34
|
+
# rubocop:disable Metrics/MethodLength
|
35
35
|
def test_command_help
|
36
36
|
CMDS.each do |cmd|
|
37
37
|
begin
|
38
38
|
WavefrontCliController.new([cmd, '--help'])
|
39
39
|
rescue SystemExit => e
|
40
|
+
assert(e.message.split("\n").map(&:size).max <= TW)
|
40
41
|
assert_equal(1, e.status)
|
41
42
|
assert_match(/^Usage:/, e.message)
|
42
43
|
assert_match(/^ #{CMD} #{cmd} /, e.message)
|
43
44
|
assert_match(/^ #{CMD} #{cmd} --help$/, e.message)
|
45
|
+
next
|
44
46
|
end
|
45
47
|
end
|
46
48
|
end
|
@@ -16,6 +16,15 @@ describe 'integration command' do
|
|
16
16
|
{ path: "/api/v2/cloudintegration/#{id}" }, k)
|
17
17
|
cmd_to_call(word, "delete #{id}",
|
18
18
|
{ method: :delete, path: "/api/v2/cloudintegration/#{id}" }, k)
|
19
|
+
cmd_to_call(word, "search -L 100 id~#{id}",
|
20
|
+
{ method: :post, path: "/api/v2/search/cloudintegration",
|
21
|
+
body: { limit: "100",
|
22
|
+
offset: 0,
|
23
|
+
query: [{key: 'id',
|
24
|
+
value: id,
|
25
|
+
matchingMethod: 'CONTAINS'}],
|
26
|
+
sort: {field: 'id', ascending: true}},
|
27
|
+
headers: JSON_POST_HEADERS }, WavefrontCli::CloudIntegration)
|
19
28
|
cmd_to_call(word, "undelete #{id}",
|
20
29
|
{ method: :post,
|
21
30
|
path: "/api/v2/cloudintegration/#{id}/undelete" }, k)
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'pathname'
|
4
|
+
require_relative(File.join('../../../lib/wavefront-cli/commands',
|
5
|
+
Pathname.new(__FILE__).basename
|
6
|
+
.to_s.sub('_spec.rb', '')))
|
7
|
+
require_relative './base_spec'
|
8
|
+
|
9
|
+
# Test Alert commands and options
|
10
|
+
#
|
11
|
+
class WavefrontCommmandAlertTest < WavefrontCommmandBaseTest
|
12
|
+
def setup
|
13
|
+
@wf = WavefrontCommandAlert.new
|
14
|
+
@col_width = 21
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
CMD = 'test'.freeze
|
4
|
+
|
5
|
+
require 'pathname'
|
6
|
+
require_relative(File.join('../../../lib/wavefront-cli/commands',
|
7
|
+
Pathname.new(__FILE__).basename
|
8
|
+
.to_s.sub('_spec.rb', '')))
|
9
|
+
require_relative './spec_helper'
|
10
|
+
|
11
|
+
# Test base class for commands
|
12
|
+
#
|
13
|
+
class WavefrontCommmandBaseTest < MiniTest::Test
|
14
|
+
attr_reader :wf, :col_width, :skip_cmd
|
15
|
+
|
16
|
+
def setup
|
17
|
+
@wf = WavefrontCommandBase.new
|
18
|
+
@col_width = 18 # has to be manually set for each class
|
19
|
+
end
|
20
|
+
|
21
|
+
def word
|
22
|
+
self.class.name[17..-5]
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_global_options
|
26
|
+
opts = wf.global_options
|
27
|
+
assert_instance_of(Array, opts)
|
28
|
+
|
29
|
+
opts.each do |o|
|
30
|
+
assert_instance_of(String, o)
|
31
|
+
assert_match(/^-\w, --\w+/, o)
|
32
|
+
refute o.end_with?('.')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_common_options
|
37
|
+
opts = wf.common_options
|
38
|
+
assert_instance_of(Array, opts)
|
39
|
+
|
40
|
+
opts.each do |o|
|
41
|
+
assert_instance_of(String, o)
|
42
|
+
assert_match(/^-\w, --\w+/, o)
|
43
|
+
refute o.end_with?('.')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_tag_commands
|
48
|
+
cmds = wf.tag_commands
|
49
|
+
assert_instance_of(Array, cmds)
|
50
|
+
|
51
|
+
cmds.each do |o|
|
52
|
+
assert_instance_of(String, o)
|
53
|
+
assert_match(/^tags* .* <id>/, o)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_word
|
58
|
+
assert_equal(wf.word, word.downcase)
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_sdk_class
|
62
|
+
assert_equal(wf.sdk_class, word)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_sdk_file
|
66
|
+
assert_equal(wf.sdk_file, word.downcase)
|
67
|
+
end
|
68
|
+
|
69
|
+
# rubocop:disable Metrics/AbcSize
|
70
|
+
def test_commands
|
71
|
+
assert wf.commands.start_with?("Usage:\n")
|
72
|
+
assert wf.commands.match(/ --help$/)
|
73
|
+
|
74
|
+
wf.commands(600).split("\n")[1..-1].each do |c|
|
75
|
+
next if skip_cmd && c.match(skip_cmd)
|
76
|
+
assert_match(/^ \w+/, c)
|
77
|
+
assert_includes(c, CMN) unless c =~ /--help$/
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_options
|
82
|
+
assert wf.options(600).start_with?("Global options:\n")
|
83
|
+
assert_match(/\nOptions:\n/, wf.options)
|
84
|
+
|
85
|
+
wf.options(600).split("\n")[1..-1].each do |o|
|
86
|
+
next if o == 'Global options:' || o == 'Options:' || o.empty?
|
87
|
+
assert_instance_of(String, o)
|
88
|
+
assert_match(/^ -\w, --\w+/, o)
|
89
|
+
refute o.end_with?('.')
|
90
|
+
end
|
91
|
+
|
92
|
+
assert_equal(wf.options.split("\n").select(&:empty?).size, 1)
|
93
|
+
end
|
94
|
+
|
95
|
+
# rubocop:disable Metrics/MethodLength
|
96
|
+
def test_opt_row
|
97
|
+
assert_equal(wf.opt_row('-s, --short short option', 10),
|
98
|
+
" -s, --short short option\n")
|
99
|
+
assert_equal(wf.opt_row('-s, --short short option', 8),
|
100
|
+
" -s, --short short option\n")
|
101
|
+
assert_equal(wf.opt_row(
|
102
|
+
'-l, --longoption a long option with a quite ' \
|
103
|
+
'long description which needs folding', 15
|
104
|
+
),
|
105
|
+
' -l, --longoption a long option with a quite long ' \
|
106
|
+
"description which\n needs folding\n")
|
107
|
+
assert_equal(wf.opt_row(
|
108
|
+
'-h, --hugeoption an option with a very long, far ' \
|
109
|
+
'too verbose description which is going need folding ' \
|
110
|
+
'more than one time, let me tell you', 12
|
111
|
+
),
|
112
|
+
' -h, --hugeoption an option with a very long, far too ' \
|
113
|
+
"verbose description\n which is going " \
|
114
|
+
'need folding more than one time, let me tell' \
|
115
|
+
"\n you\n")
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_option_column_width
|
119
|
+
assert_equal(wf.option_column_width, col_width)
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_postscript
|
123
|
+
assert_instance_of(String, wf.postscript)
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_docopt
|
127
|
+
x = wf.docopt
|
128
|
+
assert x.start_with?("Usage:\n")
|
129
|
+
assert_match("\nGlobal options:\n", x)
|
130
|
+
assert_match("--help\n", x)
|
131
|
+
assert_instance_of(String, x)
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'pathname'
|
4
|
+
require_relative(File.join('../../../lib/wavefront-cli/commands',
|
5
|
+
Pathname.new(__FILE__).basename
|
6
|
+
.to_s.sub('_spec.rb', '')))
|
7
|
+
require_relative './base_spec'
|
8
|
+
|
9
|
+
# Test Dashboard commands and options
|
10
|
+
#
|
11
|
+
class WavefrontCommmandDashboardTest < WavefrontCommmandBaseTest
|
12
|
+
def setup
|
13
|
+
@wf = WavefrontCommandDashboard.new
|
14
|
+
@col_width = 21
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'pathname'
|
4
|
+
require_relative(File.join('../../../lib/wavefront-cli/commands',
|
5
|
+
Pathname.new(__FILE__).basename
|
6
|
+
.to_s.sub('_spec.rb', '')))
|
7
|
+
require_relative './base_spec'
|
8
|
+
|
9
|
+
# Test Event commands and options
|
10
|
+
#
|
11
|
+
class WavefrontCommmandEventTest < WavefrontCommmandBaseTest
|
12
|
+
def setup
|
13
|
+
@wf = WavefrontCommandEvent.new
|
14
|
+
@col_width = 23
|
15
|
+
@skip_cmd = /event show/
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require_relative('../../../lib/wavefront-cli/commands/integration')
|
4
|
+
require_relative './base_spec'
|
5
|
+
|
6
|
+
# Test Cloud Integration commands and options
|
7
|
+
#
|
8
|
+
class WavefrontCommmandIntegrationTest < WavefrontCommmandBaseTest
|
9
|
+
def setup
|
10
|
+
@wf = WavefrontCommandIntegration.new
|
11
|
+
@col_width = 19
|
12
|
+
end
|
13
|
+
|
14
|
+
def word
|
15
|
+
'CloudIntegration'
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_word
|
19
|
+
assert_equal(wf.word, 'integration')
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require_relative('../../../lib/wavefront-cli/commands/link')
|
4
|
+
require_relative './base_spec'
|
5
|
+
|
6
|
+
# Test External Link commands and options
|
7
|
+
#
|
8
|
+
class WavefrontCommmandLinkTest < WavefrontCommmandBaseTest
|
9
|
+
def setup
|
10
|
+
@wf = WavefrontCommandLink.new
|
11
|
+
@col_width = 19
|
12
|
+
end
|
13
|
+
|
14
|
+
def word
|
15
|
+
'ExternalLink'
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_word
|
19
|
+
assert_equal(wf.word, 'link')
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'pathname'
|
4
|
+
require_relative(File.join('../../../lib/wavefront-cli/commands',
|
5
|
+
Pathname.new(__FILE__).basename
|
6
|
+
.to_s.sub('_spec.rb', '')))
|
7
|
+
require_relative './base_spec'
|
8
|
+
|
9
|
+
# Test Message commands and options
|
10
|
+
#
|
11
|
+
class WavefrontCommmandMessageTest < WavefrontCommmandBaseTest
|
12
|
+
def setup
|
13
|
+
@wf = WavefrontCommandMessage.new
|
14
|
+
@col_width = 19
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'pathname'
|
4
|
+
require_relative(File.join('../../../lib/wavefront-cli/commands',
|
5
|
+
Pathname.new(__FILE__).basename
|
6
|
+
.to_s.sub('_spec.rb', '')))
|
7
|
+
require_relative './base_spec'
|
8
|
+
|
9
|
+
# Test Metric commands and options
|
10
|
+
#
|
11
|
+
class WavefrontCommmandMetricTest < WavefrontCommmandBaseTest
|
12
|
+
def setup
|
13
|
+
@wf = WavefrontCommandMetric.new
|
14
|
+
@col_width = 19
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'pathname'
|
4
|
+
require_relative(File.join('../../../lib/wavefront-cli/commands',
|
5
|
+
Pathname.new(__FILE__).basename
|
6
|
+
.to_s.sub('_spec.rb', '')))
|
7
|
+
require_relative './base_spec'
|
8
|
+
|
9
|
+
# Test Proxy commands and options
|
10
|
+
#
|
11
|
+
class WavefrontCommmandProxyTest < WavefrontCommmandBaseTest
|
12
|
+
def setup
|
13
|
+
@wf = WavefrontCommandProxy.new
|
14
|
+
@col_width = 19
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'pathname'
|
4
|
+
require_relative(File.join('../../../lib/wavefront-cli/commands',
|
5
|
+
Pathname.new(__FILE__).basename
|
6
|
+
.to_s.sub('_spec.rb', '')))
|
7
|
+
require_relative './base_spec'
|
8
|
+
|
9
|
+
# Test Query commands and options
|
10
|
+
#
|
11
|
+
class WavefrontCommmandQueryTest < WavefrontCommmandBaseTest
|
12
|
+
def setup
|
13
|
+
@wf = WavefrontCommandQuery.new
|
14
|
+
@col_width = 24
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'pathname'
|
4
|
+
require_relative(File.join('../../../lib/wavefront-cli/commands',
|
5
|
+
Pathname.new(__FILE__).basename
|
6
|
+
.to_s.sub('_spec.rb', '')))
|
7
|
+
require_relative './base_spec'
|
8
|
+
|
9
|
+
# Test Webhook commands and options
|
10
|
+
#
|
11
|
+
class WavefrontCommmandWebhookTest < WavefrontCommmandBaseTest
|
12
|
+
def setup
|
13
|
+
@wf = WavefrontCommandWebhook.new
|
14
|
+
@col_width = 19
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require_relative('../../../lib/wavefront-cli/commands/window')
|
4
|
+
require_relative './base_spec'
|
5
|
+
|
6
|
+
# Test Maintenance Window commands and options
|
7
|
+
#
|
8
|
+
class WavefrontCommmandWindowTest < WavefrontCommmandBaseTest
|
9
|
+
def setup
|
10
|
+
@wf = WavefrontCommandWindow.new
|
11
|
+
@col_width = 19
|
12
|
+
end
|
13
|
+
|
14
|
+
def word
|
15
|
+
'MaintenanceWindow'
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_word
|
19
|
+
assert_equal(wf.word, 'window')
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'pathname'
|
4
|
+
require_relative(File.join('../../../lib/wavefront-cli/commands',
|
5
|
+
Pathname.new(__FILE__).basename
|
6
|
+
.to_s.sub('_spec.rb', '')))
|
7
|
+
require_relative './base_spec'
|
8
|
+
|
9
|
+
# Test Write commands and options
|
10
|
+
#
|
11
|
+
class WavefrontCommmandWriteTest < WavefrontCommmandBaseTest
|
12
|
+
def setup
|
13
|
+
@wf = WavefrontCommandWrite.new
|
14
|
+
@col_width = 25
|
15
|
+
@skip_cmd = /write (point|file)/
|
16
|
+
end
|
17
|
+
end
|
@@ -18,17 +18,27 @@ describe "#{word} command" do
|
|
18
18
|
|
19
19
|
it 'deletes with a check on inTrash' do
|
20
20
|
stub_request(:get,
|
21
|
-
"https://other.wavefront.com/api/v2/#{word}/#{id}")
|
22
|
-
|
21
|
+
"https://other.wavefront.com/api/v2/#{word}/#{id}")
|
22
|
+
.with(headers: { 'Accept': '*/*',
|
23
23
|
'Accept-Encoding':
|
24
24
|
'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
25
25
|
'Authorization': 'Bearer 0123456789-ABCDEF',
|
26
|
-
'User-Agent': /wavefront.*/})
|
27
|
-
|
26
|
+
'User-Agent': /wavefront.*/ })
|
27
|
+
.to_return(status: 200, body: '', headers: {})
|
28
28
|
cmd_to_call(word, "delete #{id}",
|
29
29
|
method: :delete, path: "/api/v2/#{word}/#{id}")
|
30
30
|
end
|
31
31
|
|
32
|
+
cmd_to_call(word, "search id=#{id}",
|
33
|
+
{ method: :post, path: "/api/v2/search/#{word}",
|
34
|
+
body: { limit: 10,
|
35
|
+
offset: 0,
|
36
|
+
query: [{key: 'id',
|
37
|
+
value: id,
|
38
|
+
matchingMethod: 'EXACT'}],
|
39
|
+
sort: {field: 'id', ascending: true}},
|
40
|
+
headers: JSON_POST_HEADERS })
|
41
|
+
|
32
42
|
cmd_to_call(word, "undelete #{id}",
|
33
43
|
method: :post, path: "/api/v2/#{word}/#{id}/undelete")
|
34
44
|
invalid_ids(word, ["describe #{bad_id}", "delete #{bad_id}",
|
@@ -0,0 +1,162 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
CMD = 'test'.freeze
|
4
|
+
|
5
|
+
require 'date'
|
6
|
+
require 'map'
|
7
|
+
require 'pathname'
|
8
|
+
require_relative(File.join('../../../lib/wavefront-cli/display',
|
9
|
+
Pathname.new(__FILE__).basename
|
10
|
+
.to_s.sub('_spec.rb', '')))
|
11
|
+
require_relative './spec_helper'
|
12
|
+
|
13
|
+
S_DATA = Map.new()
|
14
|
+
S_OPTIONS = { '<id>': 'abc123' }
|
15
|
+
|
16
|
+
# Test base class for display methods
|
17
|
+
#
|
18
|
+
class WavefrontDisplayBaseTest < MiniTest::Test
|
19
|
+
attr_reader :wf
|
20
|
+
|
21
|
+
def setup
|
22
|
+
@wf = WavefrontDisplay::Base.new(S_DATA, S_OPTIONS)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_put_id_first
|
26
|
+
assert_equal(wf.put_id_first({ k1: 1, k2: 2, id: 3, k4: 4 }),
|
27
|
+
{ id: 3, k1: 1, k2: 2, k4: 4 })
|
28
|
+
assert_equal(wf.put_id_first({ id: 3, k1: 1, k2: 2, k4: 4 }),
|
29
|
+
{ id: 3, k1: 1, k2: 2, k4: 4 })
|
30
|
+
assert_equal(wf.put_id_first({ k2: 1, k1: 2, k4: 4 }),
|
31
|
+
{ k2: 1, k1: 2, k4: 4 })
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_run
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_friendly_name
|
38
|
+
assert_equal(wf.friendly_name, 'base')
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_do_list
|
42
|
+
out = Spy.on(wf, :long_output)
|
43
|
+
wf.do_list
|
44
|
+
assert out.has_been_called?
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_do_list_brief
|
48
|
+
out = Spy.on(wf, :multicolumn)
|
49
|
+
wf.do_list_brief
|
50
|
+
assert out.has_been_called?
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_do_import
|
54
|
+
out = Spy.on(wf, :long_output)
|
55
|
+
assert_output("Imported base.\n") { wf.do_import }
|
56
|
+
assert out.has_been_called?
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_do_delete
|
60
|
+
assert_output("Deleted base 'abc123'.\n") { wf.do_delete }
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_do_undelete
|
64
|
+
assert_output("Undeleted base 'abc123'.\n") { wf.do_undelete }
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_do_tag_add
|
68
|
+
assert_output("Tagged base 'abc123'.\n") { wf.do_tag_add }
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_do_tag_delete
|
72
|
+
assert_output("Deleted tag from base 'abc123'.\n") { wf.do_tag_delete }
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_do_tag_clear
|
76
|
+
assert_output("Cleared tags on base 'abc123'.\n") { wf.do_tag_clear }
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_do_tag_set
|
80
|
+
assert_output("Set tags on base 'abc123'.\n") { wf.do_tag_set }
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_do_tags
|
84
|
+
assert_output("No tags set on base 'abc123'.\n") { wf.do_tags }
|
85
|
+
|
86
|
+
assert_output("tag1\ntag2\n") do
|
87
|
+
WavefrontDisplay::Base.new(%w(tag1 tag2), S_OPTIONS).do_tags
|
88
|
+
end
|
89
|
+
|
90
|
+
assert_output("tag1\n") do
|
91
|
+
WavefrontDisplay::Base.new(%w(tag1), S_OPTIONS).do_tags
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_drop_fields_1
|
96
|
+
data = { k1: 'string', k2: Time.now.to_i, k3: Time.now.to_i }
|
97
|
+
wf = WavefrontDisplay::Base.new(data)
|
98
|
+
wf.drop_fields
|
99
|
+
assert_equal(wf.instance_variable_get(:@data), data)
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_drop_fields_2
|
103
|
+
data = { k1: 'string', k2: Time.now.to_i, k3: Time.now.to_i }
|
104
|
+
wf = WavefrontDisplay::Base.new(data)
|
105
|
+
wf.drop_fields(:k1)
|
106
|
+
assert_equal(wf.instance_variable_get(:@data),
|
107
|
+
{ k2: Time.now.to_i, k3: Time.now.to_i })
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_drop_fields_3
|
111
|
+
data = { k1: 'string', k2: Time.now.to_i, k3: Time.now.to_i }
|
112
|
+
wf = WavefrontDisplay::Base.new(data)
|
113
|
+
wf.drop_fields(:k1, :k3)
|
114
|
+
assert_equal(wf.instance_variable_get(:@data), k2: Time.now.to_i)
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_readable_time_1
|
118
|
+
data = { k1: 'string', k2: Time.now.to_i, k3: Time.now.to_i }
|
119
|
+
wf = WavefrontDisplay::Base.new(data)
|
120
|
+
wf.readable_time
|
121
|
+
assert_equal(wf.instance_variable_get(:@data), data)
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_readable_time_2
|
125
|
+
data = { k1: 'string', k2: 1499426615, k3: 1499426615 }
|
126
|
+
wf = WavefrontDisplay::Base.new(data)
|
127
|
+
wf.readable_time(:k2)
|
128
|
+
x = wf.data
|
129
|
+
assert x.is_a?(Hash)
|
130
|
+
assert_equal(x.size, 3)
|
131
|
+
assert_equal(x.keys, %i(k1 k2 k3))
|
132
|
+
assert_equal(x[:k1], 'string')
|
133
|
+
assert_match(/^20\d\d-[01]\d-[0-3]\d [0-2]\d:[0-5]\d:[0-5]\d$/, x[:k2])
|
134
|
+
assert_equal(x[:k3], 1499426615)
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_readable_time_2
|
138
|
+
data = { k1: 'string', k2: 1499426615, k3: 1499426615 }
|
139
|
+
wf = WavefrontDisplay::Base.new(data)
|
140
|
+
wf.readable_time(:k2, :k3)
|
141
|
+
x = wf.data
|
142
|
+
assert x.is_a?(Hash)
|
143
|
+
assert_equal(x.size, 3)
|
144
|
+
assert_equal(x.keys, %i(k1 k2 k3))
|
145
|
+
assert_equal(x[:k1], 'string')
|
146
|
+
assert_match(/^20\d\d-[01]\d-[0-3]\d [0-2]\d:[0-5]\d:[0-5]\d$/, x[:k2])
|
147
|
+
assert_match(/^20\d\d-[01]\d-[0-3]\d [0-2]\d:[0-5]\d:[0-5]\d$/, x[:k3])
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_human_time
|
151
|
+
assert_raises(ArgumentError) { wf.human_time([1,2,3]) }
|
152
|
+
assert_raises(ArgumentError) { wf.human_time(123) }
|
153
|
+
assert_raises(ArgumentError) { wf.human_time(12345678901234) }
|
154
|
+
assert_equal('2017-07-07 11:23:35', wf.human_time(1499426615, true))
|
155
|
+
assert_match(/^20\d\d-[01]\d-[0-3]\d [0-2]\d:[0-5]\d:[0-5]\d.\d{3}$/,
|
156
|
+
wf.human_time(DateTime.now.strftime('%Q')))
|
157
|
+
assert_match(/^20\d\d-[01]\d-[0-3]\d [0-2]\d:[0-5]\d:[0-5]\d$/,
|
158
|
+
wf.human_time(Time.now.to_i))
|
159
|
+
assert_equal('2017-07-07 11:23:35.123', wf.human_time(1499426615123,
|
160
|
+
true))
|
161
|
+
end
|
162
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require_relative '../../../../lib/wavefront-cli/display/printer/base'
|
4
|
+
require_relative '../spec_helper'
|
5
|
+
|
6
|
+
# Test base class
|
7
|
+
#
|
8
|
+
class WavefrontDisplayPrinterBase < MiniTest::Test
|
9
|
+
attr_reader :wf
|
10
|
+
|
11
|
+
def setup
|
12
|
+
@wf = WavefrontDisplayPrinter::Base.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_key_width
|
16
|
+
assert_equal(wf.key_width, 0)
|
17
|
+
assert_equal(wf.key_width(key1: 1, row2: 2, longrow: 3), 9)
|
18
|
+
assert_equal(wf.key_width({ key1: 1, row2: 2, longrow: 3 }, 3), 10)
|
19
|
+
end
|
20
|
+
end
|