wavefront-cli 8.5.1 → 10.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/.github/workflows/release.yml +4 -4
- data/.github/workflows/test.yml +2 -2
- data/.rubocop.yml +1 -4
- data/Gemfile +10 -0
- data/HISTORY.md +17 -0
- data/README.md +4 -2
- data/lib/wavefront-cli/base.rb +4 -4
- data/lib/wavefront-cli/commands/base.rb +13 -10
- data/lib/wavefront-cli/commands/config.rb +3 -7
- data/lib/wavefront-cli/commands/derivedmetric.rb +1 -1
- data/lib/wavefront-cli/commands/metric.rb +3 -3
- data/lib/wavefront-cli/commands/metricspolicy.rb +33 -0
- data/lib/wavefront-cli/commands/query.rb +5 -5
- data/lib/wavefront-cli/commands/write.rb +12 -12
- data/lib/wavefront-cli/config.rb +31 -35
- data/lib/wavefront-cli/constants.rb +3 -2
- data/lib/wavefront-cli/controller.rb +19 -15
- data/lib/wavefront-cli/display/base.rb +2 -2
- data/lib/wavefront-cli/display/cluster.rb +21 -0
- data/lib/wavefront-cli/display/metricspolicy.rb +15 -0
- data/lib/wavefront-cli/display/printer/long.rb +11 -17
- data/lib/wavefront-cli/display/printer/sparkline.rb +3 -3
- data/lib/wavefront-cli/display/query.rb +1 -1
- data/lib/wavefront-cli/display/write.rb +2 -1
- data/lib/wavefront-cli/event.rb +2 -2
- data/lib/wavefront-cli/exception_handler.rb +8 -1
- data/lib/wavefront-cli/helpers/load_file.rb +2 -2
- data/lib/wavefront-cli/maintenancewindow.rb +1 -1
- data/lib/wavefront-cli/metricspolicy.rb +42 -0
- data/lib/wavefront-cli/opt_handler.rb +2 -3
- data/lib/wavefront-cli/output/csv/query.rb +3 -3
- data/lib/wavefront-cli/output/hcl/base.rb +4 -4
- data/lib/wavefront-cli/output/hcl/dashboard.rb +7 -7
- data/lib/wavefront-cli/output/hcl/stdlib/array.rb +1 -1
- data/lib/wavefront-cli/output/wavefront/query.rb +7 -7
- data/lib/wavefront-cli/stdlib/array.rb +1 -1
- data/lib/wavefront-cli/stdlib/string.rb +5 -5
- data/lib/wavefront-cli/usage.rb +1 -1
- data/lib/wavefront-cli/version.rb +1 -1
- data/lib/wavefront-cli/write.rb +15 -19
- data/spec/constants.rb +5 -6
- data/spec/support/command_base.rb +13 -1
- data/spec/support/minitest_assertions.rb +14 -10
- data/spec/support/output_tester.rb +2 -2
- data/spec/support/supported_commands.rb +3 -1
- data/spec/test_mixins/import.rb +2 -2
- data/spec/test_mixins/search.rb +9 -7
- data/spec/test_mixins/set.rb +1 -1
- data/spec/wavefront-cli/account_spec.rb +6 -4
- data/spec/wavefront-cli/alert_spec.rb +29 -6
- data/spec/wavefront-cli/base_spec.rb +1 -1
- data/spec/wavefront-cli/commands/base_spec.rb +3 -3
- data/spec/wavefront-cli/commands/config_spec.rb +6 -6
- data/spec/wavefront-cli/config_spec.rb +84 -44
- data/spec/wavefront-cli/controller_spec.rb +4 -2
- data/spec/wavefront-cli/dashboard_spec.rb +1 -1
- data/spec/wavefront-cli/derivedmetric_spec.rb +9 -7
- data/spec/wavefront-cli/display/base_spec.rb +1 -1
- data/spec/wavefront-cli/display/printer/long_spec.rb +6 -4
- data/spec/wavefront-cli/display/printer/terse_spec.rb +2 -2
- data/spec/wavefront-cli/event_spec.rb +14 -11
- data/spec/wavefront-cli/event_store_spec.rb +17 -13
- data/spec/wavefront-cli/externallink_spec.rb +5 -3
- data/spec/wavefront-cli/maintenancewindow_spec.rb +25 -19
- data/spec/wavefront-cli/message_spec.rb +3 -3
- data/spec/wavefront-cli/metricspolicy_spec.rb +30 -0
- data/spec/wavefront-cli/opt_handler_spec.rb +2 -2
- data/spec/wavefront-cli/output/csv/query_spec.rb +1 -1
- data/spec/wavefront-cli/output/csv_spec.rb +1 -1
- data/spec/wavefront-cli/output/hcl_spec.rb +1 -1
- data/spec/wavefront-cli/output/helpers.rb +1 -1
- data/spec/wavefront-cli/output/json_spec.rb +1 -1
- data/spec/wavefront-cli/output/ruby_spec.rb +1 -1
- data/spec/wavefront-cli/output/wavefront/query_spec.rb +1 -1
- data/spec/wavefront-cli/output/wavefront_spec.rb +1 -1
- data/spec/wavefront-cli/output/yaml_spec.rb +1 -1
- data/spec/wavefront-cli/proxy_spec.rb +1 -1
- data/spec/wavefront-cli/query_spec.rb +2 -2
- data/spec/wavefront-cli/role_spec.rb +4 -3
- data/spec/wavefront-cli/serviceaccount_spec.rb +7 -5
- data/spec/wavefront-cli/stdlib/array_spec.rb +1 -1
- data/spec/wavefront-cli/stdlib/string_spec.rb +4 -2
- data/spec/wavefront-cli/usage_spec.rb +2 -2
- data/spec/wavefront-cli/{write_spec.rb → write_class_spec.rb} +2 -15
- data/wavefront-cli.gemspec +4 -16
- metadata +17 -259
- data/spec/spec_helper.rb +0 -113
@@ -8,12 +8,14 @@ require_relative '../../lib/wavefront-cli/controller'
|
|
8
8
|
# An abstract class which facilitates "end-to-end" testing of
|
9
9
|
# commands.
|
10
10
|
#
|
11
|
-
class EndToEndTest <
|
11
|
+
class EndToEndTest < Minitest::Test
|
12
|
+
attr_accessor :single_perm
|
12
13
|
attr_reader :wf
|
13
14
|
|
14
15
|
def setup
|
15
16
|
before_setup if respond_to?(:before_setup)
|
16
17
|
@wf = WavefrontCliController
|
18
|
+
@single_perm = false
|
17
19
|
end
|
18
20
|
|
19
21
|
def api_path
|
@@ -79,4 +81,14 @@ class EndToEndTest < MiniTest::Test
|
|
79
81
|
{ status: { result: 'OK', message: '', code: 200 },
|
80
82
|
items: [] }.to_json
|
81
83
|
end
|
84
|
+
|
85
|
+
def blank_envvars
|
86
|
+
%w[WAVEFRONT_ENDPOINT WAVEFRONT_PROXY WAVEFRONT_TOKEN].each do |v|
|
87
|
+
ENV[v] = nil
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def config?
|
92
|
+
Pathname.new(Dir.home).join('.wavefront').exist?
|
93
|
+
end
|
82
94
|
end
|
@@ -147,10 +147,13 @@ module Minitest
|
|
147
147
|
end
|
148
148
|
|
149
149
|
def assert_cmd_posts(command, api_path, payload = 'null',
|
150
|
-
response =
|
150
|
+
response = nil, extra_headers = {})
|
151
|
+
response ||= dummy_response
|
151
152
|
all_permutations do |p|
|
152
153
|
assert_posts("https://#{p[:endpoint]}#{api_path}",
|
153
|
-
mk_headers(p[:token]
|
154
|
+
mk_headers(p[:token], extra_headers),
|
155
|
+
payload,
|
156
|
+
response) do
|
154
157
|
wf.new("#{cmd_word} #{command} #{p[:cmdline]}".split)
|
155
158
|
end
|
156
159
|
end
|
@@ -166,7 +169,7 @@ module Minitest
|
|
166
169
|
end
|
167
170
|
|
168
171
|
def assert_cmd_deletes(command, api_path, response = dummy_response)
|
169
|
-
|
172
|
+
all_permutations do |p|
|
170
173
|
assert_deletes("https://#{p[:endpoint]}#{api_path}",
|
171
174
|
mk_headers(p[:token]), response) do
|
172
175
|
wf.new("#{cmd_word} #{command} #{p[:cmdline]}".split)
|
@@ -188,13 +191,14 @@ module Minitest
|
|
188
191
|
assert_empty(err)
|
189
192
|
end
|
190
193
|
|
191
|
-
# Run tests with all available permutations
|
192
|
-
#
|
193
|
-
#
|
194
|
+
# Run tests with all available permutations, unless the single_perm class
|
195
|
+
# variable is set. This lets us run tests faster by running fewer (but
|
196
|
+
# still a good random selection) and lets us run tests which must only be
|
197
|
+
# run once, like tests which pop stuff off the event stack.
|
194
198
|
#
|
195
199
|
def all_permutations
|
196
200
|
perms = permutations
|
197
|
-
perms =
|
201
|
+
perms = perms.shuffle.take(1) if @single_perm || ENV['FAST_TESTS']
|
198
202
|
|
199
203
|
perms.each do |p|
|
200
204
|
yield(p)
|
@@ -213,11 +217,11 @@ module Minitest
|
|
213
217
|
|
214
218
|
private
|
215
219
|
|
216
|
-
def mk_headers(token = nil)
|
220
|
+
def mk_headers(token = nil, extra_headers = {})
|
217
221
|
{ Accept: /.*/,
|
218
222
|
'Accept-Encoding': /.*/,
|
219
|
-
Authorization:
|
220
|
-
'User-Agent': "wavefront-cli-#{WF_CLI_VERSION}" }
|
223
|
+
Authorization: "Bearer #{token || '0123456789-ABCDEF'}",
|
224
|
+
'User-Agent': "wavefront-cli-#{WF_CLI_VERSION}" }.merge(extra_headers)
|
221
225
|
end
|
222
226
|
|
223
227
|
# Every command we simulate running is done under the following
|
@@ -14,7 +14,7 @@ class OutputTester
|
|
14
14
|
# @return [Object] canned raw responses used to test outputs
|
15
15
|
#
|
16
16
|
def load_input(file, only_items = true)
|
17
|
-
ret = JSON.parse(
|
17
|
+
ret = JSON.parse(File.read(RES_DIR.join('display', file)),
|
18
18
|
symbolize_names: true)
|
19
19
|
only_items ? ret[:items] : ret
|
20
20
|
end
|
@@ -23,7 +23,7 @@ class OutputTester
|
|
23
23
|
# @return [String]
|
24
24
|
#
|
25
25
|
def load_expected(file)
|
26
|
-
|
26
|
+
File.read(RES_DIR.join('display', file))
|
27
27
|
end
|
28
28
|
|
29
29
|
def in_and_out(input, expected, only_items = true)
|
@@ -2,11 +2,13 @@
|
|
2
2
|
|
3
3
|
require_relative '../constants'
|
4
4
|
|
5
|
+
# Produces a list of wf's commands
|
6
|
+
#
|
5
7
|
class SupportedCommands
|
6
8
|
attr_reader :cmd_dir
|
7
9
|
|
8
10
|
def initialize
|
9
|
-
@cmd_dir = ROOT
|
11
|
+
@cmd_dir = ROOT.join('lib', 'wavefront-cli', 'commands')
|
10
12
|
end
|
11
13
|
|
12
14
|
def all
|
data/spec/test_mixins/import.rb
CHANGED
@@ -61,11 +61,11 @@ module WavefrontCliTest
|
|
61
61
|
private
|
62
62
|
|
63
63
|
def import_file
|
64
|
-
RES_DIR
|
64
|
+
RES_DIR.join('imports', "#{api_path}.json")
|
65
65
|
end
|
66
66
|
|
67
67
|
def update_file
|
68
|
-
RES_DIR
|
68
|
+
RES_DIR.join('updates', "#{api_path}.json")
|
69
69
|
end
|
70
70
|
end
|
71
71
|
end
|
data/spec/test_mixins/search.rb
CHANGED
@@ -18,17 +18,19 @@ module WavefrontCliTest
|
|
18
18
|
sort: { field: 'id', ascending: true })
|
19
19
|
end
|
20
20
|
|
21
|
+
json_body = { limit: 10,
|
22
|
+
offset: 0,
|
23
|
+
query: [{ key: 'id',
|
24
|
+
value: id,
|
25
|
+
matchingMethod: 'EXACT',
|
26
|
+
negated: false }],
|
27
|
+
sort: { field: 'id', ascending: true } }.to_json
|
28
|
+
|
21
29
|
assert_noop(
|
22
30
|
"search id=#{id}",
|
23
31
|
'uri: POST https://default.wavefront.com/api/v2/search/' \
|
24
32
|
"#{search_api_path}",
|
25
|
-
|
26
|
-
offset: 0,
|
27
|
-
query: [{ key: 'id',
|
28
|
-
value: id,
|
29
|
-
matchingMethod: 'EXACT',
|
30
|
-
negated: false }],
|
31
|
-
sort: { field: 'id', ascending: true } }.to_json
|
33
|
+
"body: #{json_body}"
|
32
34
|
)
|
33
35
|
assert_abort_on_missing_creds("search id=#{id}")
|
34
36
|
assert_usage('search')
|
data/spec/test_mixins/set.rb
CHANGED
@@ -228,10 +228,12 @@ class AccountEndToEndTest < EndToEndTest
|
|
228
228
|
cmd = "validate #{user_list.join(' ')}"
|
229
229
|
|
230
230
|
quietly do
|
231
|
-
assert_cmd_posts(
|
232
|
-
|
233
|
-
|
234
|
-
|
231
|
+
assert_cmd_posts(
|
232
|
+
cmd,
|
233
|
+
'/api/v2/account/validateAccounts',
|
234
|
+
user_list.to_json,
|
235
|
+
File.read(RES_DIR.join('responses', 'user-validate.json'))
|
236
|
+
)
|
235
237
|
end
|
236
238
|
|
237
239
|
assert_noop(cmd,
|
@@ -21,6 +21,25 @@ class AlertEndToEndTest < EndToEndTest
|
|
21
21
|
include WavefrontCliTest::History
|
22
22
|
include WavefrontCliTest::Acl
|
23
23
|
|
24
|
+
# This test isn't run if whoever runs it has a config file, because it tests
|
25
|
+
# wf's behaviour only if that file does not exist. CI will never have that
|
26
|
+
# file.
|
27
|
+
#
|
28
|
+
def test_no_config_no_envvars
|
29
|
+
skip if config?
|
30
|
+
|
31
|
+
blank_envvars
|
32
|
+
wf = WavefrontCliController
|
33
|
+
|
34
|
+
out, err = capture_io do
|
35
|
+
assert_raises(SystemExit) { wf.new(%w[alert list]) }
|
36
|
+
end
|
37
|
+
|
38
|
+
assert_empty(err)
|
39
|
+
assert out.start_with?('Credential error. Missing api token.')
|
40
|
+
assert_match(/You may also run 'wf config setup'/, out)
|
41
|
+
end
|
42
|
+
|
24
43
|
def test_latest
|
25
44
|
quietly do
|
26
45
|
assert_cmd_gets("latest #{id}", "/api/v2/alert/#{id}/history")
|
@@ -48,10 +67,12 @@ class AlertEndToEndTest < EndToEndTest
|
|
48
67
|
id: id, v: nil, name: nil)
|
49
68
|
end
|
50
69
|
|
70
|
+
json_body = { id: id, name: nil, v: nil }.to_json
|
71
|
+
|
51
72
|
assert_noop("clone #{id}",
|
52
73
|
'uri: POST https://default.wavefront.com/api/v2/' \
|
53
74
|
"alert/#{id}/clone",
|
54
|
-
|
75
|
+
"body: #{json_body}")
|
55
76
|
|
56
77
|
assert_invalid_id("clone #{invalid_id}")
|
57
78
|
assert_usage('clone')
|
@@ -65,10 +86,12 @@ class AlertEndToEndTest < EndToEndTest
|
|
65
86
|
id: id, v: 5, name: nil)
|
66
87
|
end
|
67
88
|
|
89
|
+
json_body = { id: id, name: nil, v: 5 }.to_json
|
90
|
+
|
68
91
|
assert_noop("clone #{id} --version 5",
|
69
92
|
'uri: POST https://default.wavefront.com/api/v2/' \
|
70
93
|
"alert/#{id}/clone",
|
71
|
-
|
94
|
+
"body: #{json_body}")
|
72
95
|
|
73
96
|
assert_invalid_id("clone -v 10 #{invalid_id}")
|
74
97
|
assert_usage('clone -v')
|
@@ -173,7 +196,7 @@ class AlertEndToEndTest < EndToEndTest
|
|
173
196
|
assert_noop('snoozed',
|
174
197
|
'uri: POST https://default.wavefront.com/api/v2/' \
|
175
198
|
'search/alert',
|
176
|
-
|
199
|
+
"body: #{state_search('snoozed').to_json}")
|
177
200
|
|
178
201
|
assert_abort_on_missing_creds('snoozed')
|
179
202
|
end
|
@@ -193,7 +216,7 @@ class AlertEndToEndTest < EndToEndTest
|
|
193
216
|
assert_noop('firing',
|
194
217
|
'uri: POST https://default.wavefront.com/api/v2/' \
|
195
218
|
'search/alert',
|
196
|
-
|
219
|
+
"body: #{state_search('firing').to_json}")
|
197
220
|
|
198
221
|
assert_abort_on_missing_creds('firing')
|
199
222
|
end
|
@@ -213,7 +236,7 @@ class AlertEndToEndTest < EndToEndTest
|
|
213
236
|
assert_noop('currently firing',
|
214
237
|
'uri: POST https://default.wavefront.com/api/v2/' \
|
215
238
|
'search/alert',
|
216
|
-
|
239
|
+
"body: #{state_search('firing').to_json}")
|
217
240
|
|
218
241
|
assert_abort_on_missing_creds('currently firing')
|
219
242
|
end
|
@@ -233,7 +256,7 @@ class AlertEndToEndTest < EndToEndTest
|
|
233
256
|
assert_noop('currently in_maintenance',
|
234
257
|
'uri: POST https://default.wavefront.com/api/v2/' \
|
235
258
|
'search/alert',
|
236
|
-
|
259
|
+
"body: #{state_search('in_maintenance').to_json}")
|
237
260
|
|
238
261
|
assert_abort_on_missing_creds('currently in_maintenance')
|
239
262
|
end
|
@@ -12,7 +12,7 @@ require_relative '../../lib/wavefront-cli/version'
|
|
12
12
|
# class via an instantiation of a concrete class. I don't think any
|
13
13
|
# of this matters.
|
14
14
|
#
|
15
|
-
class WavefrontCliBaseTest <
|
15
|
+
class WavefrontCliBaseTest < Minitest::Test
|
16
16
|
attr_reader :wf, :wf_cmd
|
17
17
|
|
18
18
|
def setup
|
@@ -8,7 +8,7 @@ require_relative '../../../lib/wavefront-cli/commands/base'
|
|
8
8
|
|
9
9
|
# Abstract class for testing commands
|
10
10
|
#
|
11
|
-
class WavefrontCommmandBaseTest <
|
11
|
+
class WavefrontCommmandBaseTest < Minitest::Test
|
12
12
|
attr_reader :wf, :col_width, :skip_cmd
|
13
13
|
|
14
14
|
def setup
|
@@ -68,7 +68,7 @@ class WavefrontCommmandBaseTest < MiniTest::Test
|
|
68
68
|
assert wf.commands.start_with?("Usage:\n")
|
69
69
|
assert wf.commands.match(/ --help$/)
|
70
70
|
|
71
|
-
wf.commands(600).split("\n")[1
|
71
|
+
wf.commands(600).split("\n")[1..].each do |c|
|
72
72
|
next if skip_cmd && c.match(skip_cmd)
|
73
73
|
|
74
74
|
assert_match(/^ \w+/, c)
|
@@ -80,7 +80,7 @@ class WavefrontCommmandBaseTest < MiniTest::Test
|
|
80
80
|
assert wf.options(600).start_with?("Global options:\n")
|
81
81
|
assert_match(/\nOptions:/, wf.options)
|
82
82
|
|
83
|
-
wf.options(600).split("\n")[1
|
83
|
+
wf.options(600).split("\n")[1..].each do |o|
|
84
84
|
next if o == 'Global options:' || o == 'Options:' || o.empty?
|
85
85
|
|
86
86
|
assert_instance_of(String, o)
|
@@ -13,14 +13,14 @@ require_relative 'base_spec'
|
|
13
13
|
class WavefrontCommmandConfigTest < WavefrontCommmandBaseTest
|
14
14
|
def setup
|
15
15
|
@wf = WavefrontCommandConfig.new
|
16
|
-
@col_width =
|
16
|
+
@col_width = 19
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_options
|
20
|
-
|
20
|
+
assert wf.options(600).start_with?("Global options:\n")
|
21
21
|
assert_match(/Options:\n/, wf.options)
|
22
22
|
|
23
|
-
wf.options(600).split("\n")[1
|
23
|
+
wf.options(600).split("\n")[1..].each do |o|
|
24
24
|
next if o == 'Global options:' || o == 'Options:' || o.empty?
|
25
25
|
|
26
26
|
assert_instance_of(String, o)
|
@@ -28,14 +28,14 @@ class WavefrontCommmandConfigTest < WavefrontCommmandBaseTest
|
|
28
28
|
refute o.end_with?('.')
|
29
29
|
end
|
30
30
|
|
31
|
-
assert_equal(wf.options.split("\n").count(&:empty?),
|
31
|
+
assert_equal(wf.options.split("\n").count(&:empty?), 1)
|
32
32
|
end
|
33
33
|
|
34
34
|
def test_commands
|
35
35
|
assert wf.commands.start_with?("Usage:\n")
|
36
36
|
assert wf.commands.match(/ --help$/)
|
37
37
|
|
38
|
-
wf.commands(600).split("\n")[1
|
38
|
+
wf.commands(600).split("\n")[1..].each do |c|
|
39
39
|
next if skip_cmd && c.match(skip_cmd)
|
40
40
|
|
41
41
|
assert_match(/^ \w+/, c)
|
@@ -45,7 +45,7 @@ class WavefrontCommmandConfigTest < WavefrontCommmandBaseTest
|
|
45
45
|
def test_docopt
|
46
46
|
x = wf.docopt
|
47
47
|
assert x.start_with?("Usage:\n")
|
48
|
-
|
48
|
+
assert_match("\nGlobal options:\n", x)
|
49
49
|
assert_match("--help\n", x)
|
50
50
|
assert_instance_of(String, x)
|
51
51
|
end
|
@@ -5,29 +5,32 @@ require 'pathname'
|
|
5
5
|
require 'minitest/autorun'
|
6
6
|
require_relative '../constants'
|
7
7
|
require_relative '../../lib/wavefront-cli/config'
|
8
|
+
require_relative '../support/command_base'
|
8
9
|
|
9
|
-
DEF_CF = Pathname.new(
|
10
|
+
DEF_CF = Pathname.new(Dir.home).join('.wavefront')
|
10
11
|
CONF_TMP = Pathname.new('/tmp/outfile')
|
12
|
+
CMD_PATH = Pathname.new(__FILE__)
|
11
13
|
|
12
14
|
# Test CLI configuration command
|
13
15
|
#
|
14
|
-
class WavefrontCliConfigTest <
|
16
|
+
class WavefrontCliConfigTest < Minitest::Test
|
15
17
|
attr_reader :wf, :wfo, :wfn
|
16
18
|
|
17
19
|
def setup
|
20
|
+
blank_envvars
|
18
21
|
@wf = WavefrontCli::Config.new({})
|
19
22
|
@wfo = WavefrontCli::Config.new(config: CF)
|
20
23
|
@wfn = WavefrontCli::Config.new(config: '/no/file')
|
21
24
|
end
|
22
25
|
|
23
26
|
def test_do_location
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
+
assert_equal(DEF_CF, wf.do_location)
|
28
|
+
assert_equal(Pathname('/no/file'), wfn.do_location)
|
29
|
+
assert_equal(CF, wfo.do_location)
|
27
30
|
end
|
28
31
|
|
29
32
|
def test_do_profiles
|
30
|
-
|
33
|
+
assert_equal(%w[default other], wfo.do_profiles)
|
31
34
|
|
32
35
|
assert_raises(WavefrontCli::Exception::ConfigFileNotFound) do
|
33
36
|
wfn.do_profiles
|
@@ -35,10 +38,10 @@ class WavefrontCliConfigTest < MiniTest::Test
|
|
35
38
|
end
|
36
39
|
|
37
40
|
def test_do_show
|
38
|
-
|
39
|
-
assert_empty(err)
|
40
|
-
assert out.start_with?("[default]\n")
|
41
|
-
assert_equal(10, out.split("\n").size)
|
41
|
+
assert_equal(File.read(CF), wfo.do_show)
|
42
|
+
# assert_empty(err)
|
43
|
+
# assert out.start_with?("[default]\n")
|
44
|
+
# assert_equal(10, out.split("\n").size)
|
42
45
|
end
|
43
46
|
|
44
47
|
def test_input_prompt
|
@@ -56,7 +59,7 @@ class WavefrontCliConfigTest < MiniTest::Test
|
|
56
59
|
out, err = capture_io { assert_instance_of(IniFile, wf.base_config) }
|
57
60
|
assert_empty(err)
|
58
61
|
|
59
|
-
if
|
62
|
+
if Pathname.new(Dir.home).join('.wavefront').exist?
|
60
63
|
assert_empty(out)
|
61
64
|
else
|
62
65
|
assert_match(/Creating new configuration file at/, out)
|
@@ -72,23 +75,25 @@ class WavefrontCliConfigTest < MiniTest::Test
|
|
72
75
|
end
|
73
76
|
end
|
74
77
|
|
75
|
-
def
|
76
|
-
assert_equal('str', wf.
|
77
|
-
|
78
|
+
def test_validate_thing_input
|
79
|
+
assert_equal('str', wf.validate_thing_input('str', nil,
|
80
|
+
proc { |v| v.is_a?(String) }))
|
78
81
|
|
79
|
-
assert_equal('defval', wf.
|
80
|
-
|
82
|
+
assert_equal('defval', wf.validate_thing_input('', 'defval',
|
83
|
+
proc { |v|
|
84
|
+
v.is_a?(String)
|
85
|
+
}))
|
81
86
|
|
82
87
|
assert_raises(WavefrontCli::Exception::MandatoryValue) do
|
83
|
-
wf.
|
88
|
+
wf.validate_thing_input('', nil, proc { |v| v.is_a?(String) })
|
84
89
|
end
|
85
90
|
|
86
91
|
assert_raises(WavefrontCli::Exception::InvalidValue) do
|
87
|
-
wf.
|
92
|
+
wf.validate_thing_input(:symbol, nil, proc { |v| v.is_a?(String) })
|
88
93
|
end
|
89
94
|
|
90
95
|
assert_raises(WavefrontCli::Exception::InvalidValue) do
|
91
|
-
wf.
|
96
|
+
wf.validate_thing_input('', 123, proc { |v| v.is_a?(String) })
|
92
97
|
end
|
93
98
|
end
|
94
99
|
|
@@ -196,7 +201,7 @@ class WavefrontCliConfigTest < MiniTest::Test
|
|
196
201
|
assert_equal(
|
197
202
|
"[other]\ntoken = abcdefab-0123-abcd-0123-abcdefabcdef\n" \
|
198
203
|
"endpoint = other.wavefront.com\nproxy = otherwf.localnet\n\n",
|
199
|
-
|
204
|
+
File.read(CONF_TMP)
|
200
205
|
)
|
201
206
|
|
202
207
|
assert_raises(WavefrontCli::Exception::ProfileNotFound) do
|
@@ -204,41 +209,29 @@ class WavefrontCliConfigTest < MiniTest::Test
|
|
204
209
|
end
|
205
210
|
end
|
206
211
|
|
207
|
-
def
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
out.each_line { |l| assert_match(/WAVEFRONT_[A-Z]+\s+unset$/, l) }
|
212
|
-
blank_envvars
|
212
|
+
def test_do_envvars_all_unset
|
213
|
+
assert_equal(['WAVEFRONT_ENDPOINT unset',
|
214
|
+
'WAVEFRONT_TOKEN unset',
|
215
|
+
'WAVEFRONT_PROXY unset'], wfo.do_envvars)
|
213
216
|
end
|
214
217
|
|
215
|
-
def
|
216
|
-
blank_envvars
|
218
|
+
def test_do_envvars_proxy_set
|
217
219
|
ENV['WAVEFRONT_PROXY'] = 'myproxy'
|
218
220
|
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
assert_match(/WAVEFRONT_TOKEN+\s+unset$/, out)
|
223
|
-
assert_match(/WAVEFRONT_PROXY+\s+myproxy$/, out)
|
224
|
-
blank_envvars
|
221
|
+
assert_equal(['WAVEFRONT_ENDPOINT unset',
|
222
|
+
'WAVEFRONT_TOKEN unset',
|
223
|
+
'WAVEFRONT_PROXY myproxy'], wfo.do_envvars)
|
225
224
|
end
|
226
225
|
|
227
|
-
def
|
228
|
-
blank_envvars
|
226
|
+
def test_do_envvars_proxy_and_token_set
|
229
227
|
ENV['WAVEFRONT_PROXY'] = 'myproxy'
|
230
228
|
ENV['WAVEFRONT_TOKEN'] = 'token'
|
231
229
|
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
assert_match(/WAVEFRONT_TOKEN+\s+token$/, out)
|
236
|
-
assert_match(/WAVEFRONT_PROXY+\s+myproxy$/, out)
|
237
|
-
blank_envvars
|
230
|
+
assert_equal(['WAVEFRONT_ENDPOINT unset',
|
231
|
+
'WAVEFRONT_TOKEN token',
|
232
|
+
'WAVEFRONT_PROXY myproxy'], wfo.do_envvars)
|
238
233
|
end
|
239
234
|
|
240
|
-
def test_read_thing; end
|
241
|
-
|
242
235
|
def test_present?
|
243
236
|
assert wfo.present?
|
244
237
|
assert_raises(WavefrontCli::Exception::ConfigFileNotFound) do
|
@@ -261,3 +254,50 @@ class WavefrontCliConfigTest < MiniTest::Test
|
|
261
254
|
end
|
262
255
|
end
|
263
256
|
end
|
257
|
+
|
258
|
+
class ConfigEndToEndTest < EndToEndTest
|
259
|
+
def test_location
|
260
|
+
assert_output("#{Pathname.new(Dir.home).join('.wavefront')}\n", '') do
|
261
|
+
wf.new('config location'.split)
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
def test_profiles
|
266
|
+
assert_output("default\nother\n", '') do
|
267
|
+
wf.new("config profiles -c #{CF}".split)
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
def test_envvars
|
272
|
+
out, err = capture_io { wf.new('config envvars'.split) }
|
273
|
+
assert_equal(3, out.lines.count)
|
274
|
+
assert_empty err
|
275
|
+
assert_match(/^WAVEFRONT_ENDPOINT /, out)
|
276
|
+
assert_match(/^WAVEFRONT_TOKEN /, out)
|
277
|
+
assert_match(/^WAVEFRONT_PROXY /, out)
|
278
|
+
end
|
279
|
+
|
280
|
+
def test_cluster
|
281
|
+
assert_abort_on_missing_creds('cluster')
|
282
|
+
quietly { assert_cmd_gets('cluster', '/api/v2/cluster/info') }
|
283
|
+
end
|
284
|
+
|
285
|
+
def test_about
|
286
|
+
out, err = capture_io { wf.new('config about'.split) }
|
287
|
+
lines = out.lines
|
288
|
+
|
289
|
+
assert_match(/^wf version *#{WF_CLI_VERSION}$/o, lines[0])
|
290
|
+
assert lines[1].start_with?('wf path')
|
291
|
+
assert lines[2].start_with?('SDK version')
|
292
|
+
assert lines[3].start_with?('SDK location')
|
293
|
+
assert lines[4].start_with?('Ruby version')
|
294
|
+
assert lines[5].start_with?('Ruby platform')
|
295
|
+
assert_empty err
|
296
|
+
end
|
297
|
+
|
298
|
+
private
|
299
|
+
|
300
|
+
def cmd_word
|
301
|
+
'config'
|
302
|
+
end
|
303
|
+
end
|
@@ -8,7 +8,7 @@ require_relative '../../lib/wavefront-cli/controller'
|
|
8
8
|
|
9
9
|
# Be sure the CLI behaves properly when people ask for help
|
10
10
|
#
|
11
|
-
class WavefrontCliHelpTest <
|
11
|
+
class WavefrontCliHelpTest < Minitest::Test
|
12
12
|
def test_development_mode
|
13
13
|
refute defined?(DEVELOPMENT) if ENV['CI']
|
14
14
|
end
|
@@ -94,14 +94,16 @@ end
|
|
94
94
|
# tested above.
|
95
95
|
#
|
96
96
|
# rubocop:disable Lint/MissingSuper
|
97
|
+
# rubocop:disable Style/RedundantInitialize
|
97
98
|
class Giblets < WavefrontCliController
|
98
99
|
def initialize; end
|
99
100
|
end
|
101
|
+
# rubocop:enable Style/RedundantInitialize
|
100
102
|
# rubocop:enable Lint/MissingSuper
|
101
103
|
|
102
104
|
# Here's the subclass
|
103
105
|
#
|
104
|
-
class GibletsTest <
|
106
|
+
class GibletsTest < Minitest::Test
|
105
107
|
attr_reader :wfc
|
106
108
|
|
107
109
|
def setup
|
@@ -45,7 +45,7 @@ class DashboardEndToEndTest < EndToEndTest
|
|
45
45
|
assert_repeated_output('No favourites.') do
|
46
46
|
all_permutations do |perm|
|
47
47
|
stub_request(:post, "https://#{perm[:endpoint]}/api/v2/search" \
|
48
|
-
|
48
|
+
'/dashboard')
|
49
49
|
.with(body: { limit: 999,
|
50
50
|
offset: 0,
|
51
51
|
query: [{ key: 'favorite',
|
@@ -30,16 +30,18 @@ class DerivedMetricEndToEndTest < EndToEndTest
|
|
30
30
|
query: 'ts(series)')
|
31
31
|
end
|
32
32
|
|
33
|
+
json_body = {
|
34
|
+
query: 'ts(series)',
|
35
|
+
name: 'mymetric',
|
36
|
+
minutes: 5,
|
37
|
+
includeObsoleteMetrics: false,
|
38
|
+
processRateMinutes: 1
|
39
|
+
}.to_json
|
40
|
+
|
33
41
|
assert_noop('create mymetric ts(series)',
|
34
42
|
'uri: POST https://default.wavefront.com/api/v2/' \
|
35
43
|
'derivedmetric',
|
36
|
-
|
37
|
-
query: 'ts(series)',
|
38
|
-
name: 'mymetric',
|
39
|
-
minutes: 5,
|
40
|
-
includeObsoleteMetrics: false,
|
41
|
-
processRateMinutes: 1
|
42
|
-
}.to_json)
|
44
|
+
"body: #{json_body}")
|
43
45
|
|
44
46
|
assert_usage('create')
|
45
47
|
assert_abort_on_missing_creds("create #{id} ts(series)")
|