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.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/release.yml +4 -4
  3. data/.github/workflows/test.yml +2 -2
  4. data/.rubocop.yml +1 -4
  5. data/Gemfile +10 -0
  6. data/HISTORY.md +17 -0
  7. data/README.md +4 -2
  8. data/lib/wavefront-cli/base.rb +4 -4
  9. data/lib/wavefront-cli/commands/base.rb +13 -10
  10. data/lib/wavefront-cli/commands/config.rb +3 -7
  11. data/lib/wavefront-cli/commands/derivedmetric.rb +1 -1
  12. data/lib/wavefront-cli/commands/metric.rb +3 -3
  13. data/lib/wavefront-cli/commands/metricspolicy.rb +33 -0
  14. data/lib/wavefront-cli/commands/query.rb +5 -5
  15. data/lib/wavefront-cli/commands/write.rb +12 -12
  16. data/lib/wavefront-cli/config.rb +31 -35
  17. data/lib/wavefront-cli/constants.rb +3 -2
  18. data/lib/wavefront-cli/controller.rb +19 -15
  19. data/lib/wavefront-cli/display/base.rb +2 -2
  20. data/lib/wavefront-cli/display/cluster.rb +21 -0
  21. data/lib/wavefront-cli/display/metricspolicy.rb +15 -0
  22. data/lib/wavefront-cli/display/printer/long.rb +11 -17
  23. data/lib/wavefront-cli/display/printer/sparkline.rb +3 -3
  24. data/lib/wavefront-cli/display/query.rb +1 -1
  25. data/lib/wavefront-cli/display/write.rb +2 -1
  26. data/lib/wavefront-cli/event.rb +2 -2
  27. data/lib/wavefront-cli/exception_handler.rb +8 -1
  28. data/lib/wavefront-cli/helpers/load_file.rb +2 -2
  29. data/lib/wavefront-cli/maintenancewindow.rb +1 -1
  30. data/lib/wavefront-cli/metricspolicy.rb +42 -0
  31. data/lib/wavefront-cli/opt_handler.rb +2 -3
  32. data/lib/wavefront-cli/output/csv/query.rb +3 -3
  33. data/lib/wavefront-cli/output/hcl/base.rb +4 -4
  34. data/lib/wavefront-cli/output/hcl/dashboard.rb +7 -7
  35. data/lib/wavefront-cli/output/hcl/stdlib/array.rb +1 -1
  36. data/lib/wavefront-cli/output/wavefront/query.rb +7 -7
  37. data/lib/wavefront-cli/stdlib/array.rb +1 -1
  38. data/lib/wavefront-cli/stdlib/string.rb +5 -5
  39. data/lib/wavefront-cli/usage.rb +1 -1
  40. data/lib/wavefront-cli/version.rb +1 -1
  41. data/lib/wavefront-cli/write.rb +15 -19
  42. data/spec/constants.rb +5 -6
  43. data/spec/support/command_base.rb +13 -1
  44. data/spec/support/minitest_assertions.rb +14 -10
  45. data/spec/support/output_tester.rb +2 -2
  46. data/spec/support/supported_commands.rb +3 -1
  47. data/spec/test_mixins/import.rb +2 -2
  48. data/spec/test_mixins/search.rb +9 -7
  49. data/spec/test_mixins/set.rb +1 -1
  50. data/spec/wavefront-cli/account_spec.rb +6 -4
  51. data/spec/wavefront-cli/alert_spec.rb +29 -6
  52. data/spec/wavefront-cli/base_spec.rb +1 -1
  53. data/spec/wavefront-cli/commands/base_spec.rb +3 -3
  54. data/spec/wavefront-cli/commands/config_spec.rb +6 -6
  55. data/spec/wavefront-cli/config_spec.rb +84 -44
  56. data/spec/wavefront-cli/controller_spec.rb +4 -2
  57. data/spec/wavefront-cli/dashboard_spec.rb +1 -1
  58. data/spec/wavefront-cli/derivedmetric_spec.rb +9 -7
  59. data/spec/wavefront-cli/display/base_spec.rb +1 -1
  60. data/spec/wavefront-cli/display/printer/long_spec.rb +6 -4
  61. data/spec/wavefront-cli/display/printer/terse_spec.rb +2 -2
  62. data/spec/wavefront-cli/event_spec.rb +14 -11
  63. data/spec/wavefront-cli/event_store_spec.rb +17 -13
  64. data/spec/wavefront-cli/externallink_spec.rb +5 -3
  65. data/spec/wavefront-cli/maintenancewindow_spec.rb +25 -19
  66. data/spec/wavefront-cli/message_spec.rb +3 -3
  67. data/spec/wavefront-cli/metricspolicy_spec.rb +30 -0
  68. data/spec/wavefront-cli/opt_handler_spec.rb +2 -2
  69. data/spec/wavefront-cli/output/csv/query_spec.rb +1 -1
  70. data/spec/wavefront-cli/output/csv_spec.rb +1 -1
  71. data/spec/wavefront-cli/output/hcl_spec.rb +1 -1
  72. data/spec/wavefront-cli/output/helpers.rb +1 -1
  73. data/spec/wavefront-cli/output/json_spec.rb +1 -1
  74. data/spec/wavefront-cli/output/ruby_spec.rb +1 -1
  75. data/spec/wavefront-cli/output/wavefront/query_spec.rb +1 -1
  76. data/spec/wavefront-cli/output/wavefront_spec.rb +1 -1
  77. data/spec/wavefront-cli/output/yaml_spec.rb +1 -1
  78. data/spec/wavefront-cli/proxy_spec.rb +1 -1
  79. data/spec/wavefront-cli/query_spec.rb +2 -2
  80. data/spec/wavefront-cli/role_spec.rb +4 -3
  81. data/spec/wavefront-cli/serviceaccount_spec.rb +7 -5
  82. data/spec/wavefront-cli/stdlib/array_spec.rb +1 -1
  83. data/spec/wavefront-cli/stdlib/string_spec.rb +4 -2
  84. data/spec/wavefront-cli/usage_spec.rb +2 -2
  85. data/spec/wavefront-cli/{write_spec.rb → write_class_spec.rb} +2 -15
  86. data/wavefront-cli.gemspec +4 -16
  87. metadata +17 -259
  88. data/spec/spec_helper.rb +0 -113
@@ -7,7 +7,7 @@ require_relative '../../../../lib/wavefront-cli/display/printer/long'
7
7
 
8
8
  # Test verbose printing stuff
9
9
  #
10
- class TestWavefrontDisplayPrinterLong < MiniTest::Test
10
+ class TestWavefrontDisplayPrinterLong < Minitest::Test
11
11
  attr_reader :wf
12
12
 
13
13
  def setup
@@ -78,6 +78,7 @@ class TestWavefrontDisplayPrinterLong < MiniTest::Test
78
78
  assert_equal(22, pr.longest_key_col(input))
79
79
  end
80
80
 
81
+ # rubocop:disable Layout/LineContinuationLeadingSpace
81
82
  def test_to_s
82
83
  assert_equal("today\n" \
83
84
  " weather sunny\n" \
@@ -92,24 +93,25 @@ class TestWavefrontDisplayPrinterLong < MiniTest::Test
92
93
  key1: 'val1', key2: 'val2'
93
94
  ).to_s)
94
95
  end
96
+ # rubocop:enable Layout/LineContinuationLeadingSpace
95
97
 
96
98
  def test_end_to_end
97
99
  input, expected = OutputTester.new.in_and_out('user-input.json',
98
100
  'user-human-long')
99
101
  output = WavefrontDisplayPrinter::Long.new(input).to_s
100
- assert_equal(expected, output + "\n")
102
+ assert_equal(expected, "#{output}\n")
101
103
 
102
104
  input, expected = OutputTester.new.in_and_out('user-input.json',
103
105
  'user-human-long-no_sep')
104
106
  output = WavefrontDisplayPrinter::Long.new(input, nil, nil,
105
107
  separator: false).to_s
106
- assert_equal(expected, output + "\n")
108
+ assert_equal(expected, "#{output}\n")
107
109
  end
108
110
 
109
111
  def test_end_to_end_fold
110
112
  input, expected = OutputTester.new.in_and_out('alert-input.json',
111
113
  'alert-human-long')
112
114
  output = WavefrontDisplayPrinter::Long.new(input).to_s
113
- assert_equal(expected, output + "\n")
115
+ assert_equal(expected, "#{output}\n")
114
116
  end
115
117
  end
@@ -10,7 +10,7 @@ TERSE_DATA = [{ id: 'id1', name: 'name1', fa: 1, fb: 2, fc: 3 },
10
10
 
11
11
  # Test terse printer
12
12
  #
13
- class WavefrontDisplayPrinterTerse < MiniTest::Test
13
+ class WavefrontDisplayPrinterTerse < Minitest::Test
14
14
  attr_reader :wf, :out
15
15
 
16
16
  def setup
@@ -61,6 +61,6 @@ class WavefrontDisplayPrinterTerse < MiniTest::Test
61
61
  input, expected = OutputTester.new.in_and_out('alerts-input.json',
62
62
  'alerts-human-terse')
63
63
  out = WavefrontDisplayPrinter::Terse.new(input, %i[id status name]).to_s
64
- assert_equal(expected, out + "\n")
64
+ assert_equal(expected, "#{out}\n")
65
65
  end
66
66
  end
@@ -16,11 +16,11 @@ class EventEndToEndTest < EndToEndTest
16
16
  attr_reader :test_state_dir
17
17
 
18
18
  include Wavefront::Mixins
19
- # include WavefrontCliTest::Describe
20
- # include WavefrontCliTest::Delete
21
- # include WavefrontCliTest::Search
22
- # #include WavefrontCliTest::Set
23
- # include WavefrontCliTest::Tag
19
+ include WavefrontCliTest::Describe
20
+ include WavefrontCliTest::Delete
21
+ include WavefrontCliTest::Search
22
+ include WavefrontCliTest::Set
23
+ include WavefrontCliTest::Tag
24
24
 
25
25
  def before_setup
26
26
  @test_state_dir = Pathname.new(Dir.mktmpdir)
@@ -99,7 +99,7 @@ class EventEndToEndTest < EndToEndTest
99
99
  assert state_file.exist?
100
100
  assert_equal(
101
101
  "{\"hosts\":[],\"description\":null,\"severity\":null,\"tags\":[]}\n",
102
- IO.read(state_file)
102
+ File.read(state_file)
103
103
  )
104
104
 
105
105
  assert_abort_on_missing_creds("create #{event_name}")
@@ -131,7 +131,7 @@ class EventEndToEndTest < EndToEndTest
131
131
  assert state_file.exist?
132
132
  assert_equal('{"hosts":["host1","host2"],"description":"reason",' \
133
133
  "\"severity\":null,\"tags\":[\"mytag\"]}\n",
134
- IO.read(state_file))
134
+ File.read(state_file))
135
135
  end
136
136
 
137
137
  def test_create_instantaneous_with_start_time
@@ -170,21 +170,24 @@ class EventEndToEndTest < EndToEndTest
170
170
  end
171
171
 
172
172
  def test_close_with_local_events_pop
173
+ @single_perm = true
174
+
173
175
  setup_test_state_dir
174
- assert((state_dir + '1568133440530:ev3:0').exist?)
176
+ assert state_dir.join('1568133440530:ev3:0').exist?
175
177
 
176
178
  quietly do
177
179
  assert_cmd_posts('close', '/api/v2/event/1568133440530:ev3:0/close')
178
180
  end
179
181
 
180
- refute((state_dir + '1568133440530:ev3:0').exist?)
181
- assert((state_dir + '1568133440520:ev2:0').exist?)
182
+ refute state_dir.join('1568133440530:ev3:0').exist?
183
+ assert state_dir.join('1568133440520:ev2:0').exist?
182
184
 
183
185
  quietly do
184
186
  assert_cmd_posts('close', '/api/v2/event/1568133440520:ev2:0/close')
185
187
  end
186
188
 
187
- refute((state_dir + '1568133440520:ev2:0').exist?)
189
+ refute state_dir.join('1568133440520:ev2:0').exist?
190
+ @single_perm = false
188
191
  end
189
192
 
190
193
  def test_wrap
@@ -11,7 +11,7 @@ TEST_EVENT_STORE_DIR = Pathname.new(Dir.mktmpdir)
11
11
  # Tests for event store class. This is tested well via the interface of the
12
12
  # events CLI class.
13
13
  #
14
- class Test < MiniTest::Test
14
+ class Test < Minitest::Test
15
15
  attr_reader :wf
16
16
 
17
17
  include WavefrontCli::Constants
@@ -53,7 +53,7 @@ class Test < MiniTest::Test
53
53
  end
54
54
 
55
55
  def test_create_dir_ok
56
- dir = TEST_EVENT_STORE_DIR + 'testdir'
56
+ dir = TEST_EVENT_STORE_DIR.join('testdir')
57
57
  refute dir.exist?
58
58
  wf.create_dir(dir)
59
59
  assert dir.exist?
@@ -64,13 +64,13 @@ class Test < MiniTest::Test
64
64
  setup_test_state_dir
65
65
 
66
66
  x = wf.list
67
- assert(x.all? { |e| e.is_a?(Pathname) })
67
+ assert(x.all?(Pathname))
68
68
  assert_equal(4, x.size)
69
-
70
69
  empty_test_state_dir
71
70
  end
72
71
 
73
72
  def test_list_empty_stack
73
+ wf = WavefrontCli::EventStore.new({}, TEST_EVENT_STORE_DIR)
74
74
  out, err = capture_io { assert_raises(SystemExit) { wf.list } }
75
75
  assert_empty(out)
76
76
  assert_equal("No locally recorded events.\n", err)
@@ -79,9 +79,9 @@ class Test < MiniTest::Test
79
79
  def test_pop_event
80
80
  setup_test_state_dir
81
81
 
82
- assert (wf.dir + '1568133440530:ev3:0').exist?
82
+ assert wf.dir.join('1568133440530:ev3:0').exist?
83
83
  assert_equal('1568133440530:ev3:0', wf.pop_event!)
84
- refute (wf.dir + '1568133440530:ev3:0').exist?
84
+ refute wf.dir.join('1568133440530:ev3:0').exist?
85
85
 
86
86
  empty_test_state_dir
87
87
  end
@@ -89,9 +89,9 @@ class Test < MiniTest::Test
89
89
  def test_pop_event_named
90
90
  setup_test_state_dir
91
91
 
92
- assert (wf.dir + '1568133440515:ev1:1').exist?
92
+ assert wf.dir.join('1568133440515:ev1:1').exist?
93
93
  assert_equal('1568133440515:ev1:1', wf.pop_event!('ev1'))
94
- refute (wf.dir + '1568133440515:ev1:1').exist?
94
+ refute wf.dir.join('1568133440515:ev1:1').exist?
95
95
 
96
96
  empty_test_state_dir
97
97
  end
@@ -99,14 +99,15 @@ class Test < MiniTest::Test
99
99
  def test_event_specific
100
100
  setup_test_state_dir
101
101
 
102
- assert (wf.dir + '1568133440515:ev1:1').exist?
102
+ assert wf.dir.join('1568133440515:ev1:1').exist?
103
103
  assert_equal('1568133440515:ev1:1', wf.event('1568133440515:ev1:1'))
104
- assert (wf.dir + '1568133440515:ev1:1').exist?
104
+ assert wf.dir.join('1568133440515:ev1:1').exist?
105
105
 
106
106
  empty_test_state_dir
107
107
  end
108
108
 
109
109
  def test_pop_event_empty_stack
110
+ wf = WavefrontCli::EventStore.new({}, TEST_EVENT_STORE_DIR)
110
111
  out, err = capture_io { assert_raises(SystemExit) { wf.pop_event! } }
111
112
  assert_empty(out)
112
113
  assert_equal("No locally recorded events.\n", err)
@@ -148,9 +149,12 @@ class Test < MiniTest::Test
148
149
  def test_create
149
150
  refute (wf.dir + id).exist?
150
151
  out, err = capture_io { wf.create!(id) }
151
- assert_match(/Event state recorded at .*1481553823153:testev:0./, out)
152
+ assert_match(/Event state recorded at .*#{id}./, out)
152
153
  assert_empty(err)
153
- assert (wf.dir + id).exist?
154
+ event_file = wf.dir + id
155
+ assert event_file.exist?
156
+ event_file.unlink
157
+ refute event_file.exist?
154
158
  end
155
159
 
156
160
  def test_create_with_nostate
@@ -161,7 +165,7 @@ class Test < MiniTest::Test
161
165
  private
162
166
 
163
167
  def id
164
- '1481553823153:testev:0'
168
+ '1481553823153:testevstore:0'
165
169
  end
166
170
 
167
171
  def dummy_event_files
@@ -24,11 +24,13 @@ class ExternalLinkEndToEndTest < EndToEndTest
24
24
  description: 'mydescription')
25
25
  end
26
26
 
27
+ json_body = { name: 'myname',
28
+ template: 'mytemplate',
29
+ description: 'mydescription' }.to_json
30
+
27
31
  assert_noop('create myname mydescription mytemplate',
28
32
  'uri: POST https://default.wavefront.com/api/v2/extlink',
29
- 'body: ' + { name: 'myname',
30
- template: 'mytemplate',
31
- description: 'mydescription' }.to_json)
33
+ "body: #{json_body}")
32
34
 
33
35
  assert_abort_on_missing_creds('create myname mydescription mytemplate')
34
36
  assert_usage('create myname mydescription')
@@ -42,15 +42,17 @@ class MaintenanceWindowEndToEndTest < EndToEndTest
42
42
  title: 'test_window')
43
43
  end
44
44
 
45
+ json_body = { title: 'test_window',
46
+ startTimeInSeconds: 1_566_776_337,
47
+ endTimeInSeconds: 1_566_776_399,
48
+ reason: 'testing',
49
+ relevantHostNames: %w[shark box] }.to_json
50
+
45
51
  assert_noop(
46
52
  'create --desc testing -H shark -s 1566776337 -H box ' \
47
53
  '-e 1566776399 test_window',
48
54
  'uri: POST https://default.wavefront.com/api/v2/maintenancewindow',
49
- 'body: ' + { title: 'test_window',
50
- startTimeInSeconds: 1_566_776_337,
51
- endTimeInSeconds: 1_566_776_399,
52
- reason: 'testing',
53
- relevantHostNames: %w[shark box] }.to_json
55
+ "body: #{json_body}"
54
56
  )
55
57
  end
56
58
 
@@ -172,16 +174,18 @@ class MaintenanceWindowEndToEndTest < EndToEndTest
172
174
  end
173
175
  end
174
176
 
177
+ json_body = { limit: 999,
178
+ offset: 0,
179
+ query: [{ key: 'runningState',
180
+ value: 'ongoing',
181
+ matchingMethod: 'EXACT' }],
182
+ sort: { field: 'runningState',
183
+ ascending: true } }.to_json
184
+
175
185
  assert_noop(
176
186
  'ongoing',
177
187
  'uri: POST https://default.wavefront.com/api/v2/search/maintenancewindow',
178
- 'body: ' + { limit: 999,
179
- offset: 0,
180
- query: [{ key: 'runningState',
181
- value: 'ongoing',
182
- matchingMethod: 'EXACT' }],
183
- sort: { field: 'runningState',
184
- ascending: true } }.to_json
188
+ "body: #{json_body}"
185
189
  )
186
190
 
187
191
  assert_empty(err)
@@ -198,16 +202,18 @@ class MaintenanceWindowEndToEndTest < EndToEndTest
198
202
  end
199
203
  end
200
204
 
205
+ json_body = { limit: 999,
206
+ offset: 0,
207
+ query: [{ key: 'runningState',
208
+ value: 'pending',
209
+ matchingMethod: 'EXACT' }],
210
+ sort: { field: 'runningState',
211
+ ascending: true } }.to_json
212
+
201
213
  assert_noop(
202
214
  'pending',
203
215
  'uri: POST https://default.wavefront.com/api/v2/search/maintenancewindow',
204
- 'body: ' + { limit: 999,
205
- offset: 0,
206
- query: [{ key: 'runningState',
207
- value: 'pending',
208
- matchingMethod: 'EXACT' }],
209
- sort: { field: 'runningState',
210
- ascending: true } }.to_json
216
+ "body: #{json_body}"
211
217
  )
212
218
 
213
219
  assert_empty(err)
@@ -15,11 +15,11 @@ class MessageEndToEndTest < EndToEndTest
15
15
  '/api/v2/message?limit=100&offset=0&unreadOnly=true')
16
16
  end
17
17
 
18
+ params = { offset: 0, limit: 100, unreadOnly: true }
19
+
18
20
  assert_noop('list',
19
21
  'uri: GET https://default.wavefront.com/api/v2/message',
20
- 'params: ' + {
21
- offset: 0, limit: 100, unreadOnly: true
22
- }.to_s)
22
+ "params: #{params}")
23
23
 
24
24
  assert_abort_on_missing_creds('list')
25
25
  end
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative '../support/command_base'
5
+ require_relative '../../lib/wavefront-cli/metricspolicy'
6
+
7
+ # Ensure 'metricspolicy' commands produce the correct API calls.
8
+ #
9
+ class MetricsPolicyEndToEndTest < EndToEndTest
10
+ def test_describe
11
+ quietly do
12
+ assert_cmd_gets('describe', '/api/v2/metricspolicy')
13
+ assert_cmd_gets('describe -v4', '/api/v2/metricspolicy/history/4')
14
+ end
15
+ end
16
+
17
+ def _test_revert
18
+ quietly do
19
+ assert_cmd_posts('revert 2', '/api/v2/metricspolicy/revert/2')
20
+ end
21
+ end
22
+
23
+ def cmd_word
24
+ 'metricspolicy'
25
+ end
26
+
27
+ def sdk_class_name
28
+ 'MetricsPolicy'
29
+ end
30
+ end
@@ -9,12 +9,12 @@ require_relative '../../lib/wavefront-cli/opt_handler'
9
9
  # Some of these tests will be skipped if you have a ~/.wavefront
10
10
  # config file. CI will never have that.
11
11
  #
12
- INTERFERING_FILE = Pathname.new(ENV['HOME']) + '.wavefront'
12
+ INTERFERING_FILE = Pathname.new(Dir.home).join('.wavefront')
13
13
 
14
14
  # Test option handler class. End to end tests because the work is
15
15
  # always done in the constructor
16
16
  #
17
- class OptHandlerTest < MiniTest::Test
17
+ class OptHandlerTest < Minitest::Test
18
18
  def test_no_opts
19
19
  x = WavefrontCli::OptHandler.new
20
20
  assert x.is_a?(WavefrontCli::OptHandler)
@@ -7,7 +7,7 @@ require_relative '../../../../lib/wavefront-cli/output/csv/query'
7
7
 
8
8
  # Test CSV output
9
9
  #
10
- class WavefrontOutputCsvTest < MiniTest::Test
10
+ class WavefrontOutputCsvTest < Minitest::Test
11
11
  attr_reader :wfq, :wfr, :wfqq, :wfh, :wft, :wftl
12
12
 
13
13
  def setup
@@ -8,7 +8,7 @@ require_relative '../../../lib/wavefront-cli/output/csv'
8
8
 
9
9
  # Test the CSV instantiation of the base class
10
10
  #
11
- class CsvOutputBaseTest < MiniTest::Test
11
+ class CsvOutputBaseTest < Minitest::Test
12
12
  attr_reader :wfo
13
13
 
14
14
  def setup
@@ -8,7 +8,7 @@ require_relative '../../../lib/wavefront-cli/output/hcl'
8
8
 
9
9
  # Test HCL stuff
10
10
  #
11
- class WavefrontOutputBaseTest < MiniTest::Test
11
+ class WavefrontOutputBaseTest < Minitest::Test
12
12
  attr_reader :wfo
13
13
 
14
14
  def setup
@@ -14,5 +14,5 @@ def load_raw_query_response
14
14
  end
15
15
 
16
16
  def load_file(file)
17
- JSON.parse(IO.read(RES_DIR + file), symbolize_names: true)
17
+ JSON.parse(File.read(RES_DIR.join(file)), symbolize_names: true)
18
18
  end
@@ -8,7 +8,7 @@ require_relative '../../../lib/wavefront-cli/output/json'
8
8
 
9
9
  # Test JSON output
10
10
  #
11
- class WavefrontOutputJsonTest < MiniTest::Test
11
+ class WavefrontOutputJsonTest < Minitest::Test
12
12
  attr_reader :wfo
13
13
 
14
14
  def setup
@@ -10,7 +10,7 @@ require_relative '../../../lib/wavefront-cli/output/ruby'
10
10
  # controlled an environment as this, I'm not going to bother. We
11
11
  # only p() an objecty anyway.
12
12
  #
13
- class WavefrontOutputJsonTest < MiniTest::Test
13
+ class WavefrontOutputJsonTest < Minitest::Test
14
14
  attr_reader :wfo
15
15
 
16
16
  def setup
@@ -7,7 +7,7 @@ require_relative '../../../../lib/wavefront-cli/output/wavefront/query'
7
7
 
8
8
  # Test Wavefront wire-format output
9
9
  #
10
- class WavefrontOutputWavefrontTest < MiniTest::Test
10
+ class WavefrontOutputWavefrontTest < Minitest::Test
11
11
  attr_reader :wfq, :wfr
12
12
 
13
13
  def setup
@@ -8,7 +8,7 @@ require_relative '../../../lib/wavefront-cli/output/wavefront'
8
8
 
9
9
  # Test the Wavefront instantiation of the base class
10
10
  #
11
- class WavefrontOutputBaseTest < MiniTest::Test
11
+ class WavefrontOutputBaseTest < Minitest::Test
12
12
  attr_reader :wfo
13
13
 
14
14
  def setup
@@ -8,7 +8,7 @@ require_relative '../../../lib/wavefront-cli/output/yaml'
8
8
 
9
9
  # Test YAML output
10
10
  #
11
- class WavefrontOutputYamlTest < MiniTest::Test
11
+ class WavefrontOutputYamlTest < Minitest::Test
12
12
  attr_reader :wfo
13
13
 
14
14
  def setup
@@ -37,7 +37,7 @@ class ProxyEndToEndTest < EndToEndTest
37
37
  end
38
38
 
39
39
  def test_shutdown
40
- assert_output("Requested shutdown of proxy '#{id}'.\n") do
40
+ assert_repeated_output("Requested shutdown of proxy '#{id}'.") do
41
41
  assert_cmd_puts("shutdown #{id}", "/api/v2/proxy/#{id}",
42
42
  { shutdown: true }.to_json)
43
43
  end
@@ -183,7 +183,7 @@ class QueryEndToEndTest < EndToEndTest
183
183
  end
184
184
 
185
185
  def canned_response
186
- IO.read(RES_DIR + 'responses' + 'query.json')
186
+ File.read(RES_DIR.join('responses', 'query.json'))
187
187
  end
188
188
  end
189
189
 
@@ -199,7 +199,7 @@ end
199
199
 
200
200
  # Query tests
201
201
  #
202
- class QueryTest < MiniTest::Test
202
+ class QueryTest < Minitest::Test
203
203
  attr_reader :wf
204
204
 
205
205
  def setup
@@ -94,7 +94,7 @@ class RoleEndToEndTest < EndToEndTest
94
94
  { permissions: permissions }.to_json)
95
95
  end
96
96
 
97
- assert_equal(permissions.join("\n"), out.strip)
97
+ assert_equal(permissions, out.split("\n").uniq)
98
98
  assert_empty err
99
99
 
100
100
  assert_abort_on_missing_creds("permissions #{id}")
@@ -120,8 +120,9 @@ class RoleEndToEndTest < EndToEndTest
120
120
  accounts.to_json)
121
121
  end
122
122
 
123
- assert_equal("Took '#{id}' from '#{accounts.first}', '#{accounts.last}'.",
124
- out.strip.tr("\n", ' '))
123
+ assert out.strip.tr("\n", ' ').start_with?(
124
+ "Took '#{id}' from '#{accounts.first}', '#{accounts.last}'."
125
+ )
125
126
 
126
127
  assert_empty err
127
128
 
@@ -105,14 +105,16 @@ class ServiceAccountEndToEndTest < EndToEndTest
105
105
  userGroups: [])
106
106
  end
107
107
 
108
+ json_body = { identifier: id,
109
+ active: true,
110
+ tokens: [],
111
+ roles: [],
112
+ userGroups: [] }.to_json
113
+
108
114
  assert_noop(
109
115
  "create #{id}",
110
116
  'uri: POST https://default.wavefront.com/api/v2/account/serviceaccount',
111
- 'body: ' + { identifier: id,
112
- active: true,
113
- tokens: [],
114
- roles: [],
115
- userGroups: [] }.to_json
117
+ "body: #{json_body}"
116
118
  )
117
119
 
118
120
  assert_abort_on_missing_creds("create #{id}")
@@ -6,7 +6,7 @@ require_relative '../../../lib/wavefront-cli/stdlib/array'
6
6
 
7
7
  # Test extensions to stlib Array
8
8
  #
9
- class TestArray < MiniTest::Test
9
+ class TestArray < Minitest::Test
10
10
  def test_max_length
11
11
  assert_equal(7, %w[short longer longest].max_length)
12
12
  assert_equal(7, %i[short longer longest].max_length)
@@ -8,7 +8,7 @@ require_relative '../../../lib/wavefront-cli/commands/base'
8
8
 
9
9
  # Test extensions to string class
10
10
  #
11
- class StringTest < MiniTest::Test
11
+ class StringTest < Minitest::Test
12
12
  def test_cmd_fold
13
13
  cmn = '[-DnV] [-c file] [-P profile] [-E endpoint] [-t token]'
14
14
  str = "command subcommand #{cmn} [-a alpha] [-b beta] [-c gamma] <id>"
@@ -28,13 +28,14 @@ class StringTest < MiniTest::Test
28
28
 
29
29
  str = '-o, --option PARAMETER a rather pointless option with a ' \
30
30
  'needlessly wordy description string'
31
- pad = "\n" + ' ' * 12
31
+ pad = "\n#{' ' * 12}"
32
32
  assert_equal(" -o, --option PARAMETER a#{pad}rather pointless" \
33
33
  "#{pad}option with a#{pad}needlessly wordy#{pad}" \
34
34
  "description#{pad}string",
35
35
  str.opt_fold(30, 10))
36
36
  end
37
37
 
38
+ # rubocop:disable Layout/LineContinuationLeadingSpace
38
39
  def test_fold_options
39
40
  str = '-l, --longoption a long option with a quite long ' \
40
41
  'description which needs folding'
@@ -48,6 +49,7 @@ class StringTest < MiniTest::Test
48
49
  ' folding')
49
50
  assert_equal(str.opt_fold(100), " #{str}")
50
51
  end
52
+ # rubocop:enable Layout/LineContinuationLeadingSpace
51
53
 
52
54
  def test_to_seconds
53
55
  assert_equal(14, '14s'.to_seconds)
@@ -49,13 +49,13 @@ class UsageEndToEndTest < EndToEndTest
49
49
  end
50
50
 
51
51
  def response
52
- IO.read(RES_DIR + 'responses' + 'usage-export-csv.json')
52
+ File.read(RES_DIR.join('responses', 'usage-export-csv.json'))
53
53
  end
54
54
  end
55
55
 
56
56
  # test class methods
57
57
  #
58
- class UsageTest < MiniTest::Test
58
+ class UsageTest < Minitest::Test
59
59
  attr_reader :wf
60
60
 
61
61
  def setup
@@ -6,26 +6,13 @@ require_relative '../../lib/wavefront-cli/write'
6
6
 
7
7
  # Test base writer
8
8
  #
9
- class WavefrontCliWriteTest < MiniTest::Test
9
+ class WavefrontCliWriteTest < Minitest::Test
10
10
  attr_reader :wf
11
11
 
12
12
  def setup
13
13
  @wf = WavefrontCli::Write.new({})
14
14
  end
15
15
 
16
- def test_validate_opts
17
- assert WavefrontCli::Write.new(using: 'unix',
18
- socket: '/tmp/sock').validate_opts
19
- assert WavefrontCli::Write.new(proxy: 'wavefront').validate_opts
20
- assert_raises 'WavefrontCli::Exception::CredentialError' do
21
- WavefrontCli::Write.new.validate_opts
22
- end
23
-
24
- assert_raises 'WavefrontCli::Exception::CredentialError' do
25
- WavefrontCli::Write.new(using: 'unix').validate_opts
26
- end
27
- end
28
-
29
16
  def test_validate_opts_file
30
17
  assert WavefrontCli::Write.new(
31
18
  proxy: 'wavefront', metric: 'metric.path'
@@ -172,7 +159,7 @@ class WavefrontCliWriteTest < MiniTest::Test
172
159
  def test_valid_timestamp?
173
160
  assert wf.valid_timestamp?(Time.now.to_i)
174
161
  refute wf.valid_timestamp?(Time.new(1999, 11, 30).to_i)
175
- refute wf.valid_timestamp?(Time.now.to_i + 367 * 24 * 60 * 60)
162
+ refute wf.valid_timestamp?(Time.now.to_i + (367 * 24 * 60 * 60))
176
163
  end
177
164
 
178
165
  def test__sdk_class_and_default_port