wavefront-cli 4.2.1 → 4.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (190) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +1 -0
  3. data/.rubocop.yml +1 -14
  4. data/.travis.yml +4 -4
  5. data/Gemfile +2 -0
  6. data/HISTORY.md +82 -60
  7. data/Rakefile +2 -0
  8. data/bin/wf +1 -0
  9. data/lib/wavefront-cli/alert.rb +13 -5
  10. data/lib/wavefront-cli/apitoken.rb +2 -0
  11. data/lib/wavefront-cli/base.rb +95 -47
  12. data/lib/wavefront-cli/cloudintegration.rb +6 -0
  13. data/lib/wavefront-cli/command_mixins/acl.rb +6 -1
  14. data/lib/wavefront-cli/command_mixins/tag.rb +2 -0
  15. data/lib/wavefront-cli/commands/.rubocop.yml +3 -4
  16. data/lib/wavefront-cli/commands/alert.rb +2 -1
  17. data/lib/wavefront-cli/commands/apitoken.rb +6 -0
  18. data/lib/wavefront-cli/commands/base.rb +30 -21
  19. data/lib/wavefront-cli/commands/cloudintegration.rb +2 -0
  20. data/lib/wavefront-cli/commands/config.rb +2 -0
  21. data/lib/wavefront-cli/commands/dashboard.rb +2 -0
  22. data/lib/wavefront-cli/commands/derivedmetric.rb +2 -0
  23. data/lib/wavefront-cli/commands/event.rb +3 -1
  24. data/lib/wavefront-cli/commands/integration.rb +2 -1
  25. data/lib/wavefront-cli/commands/link.rb +2 -0
  26. data/lib/wavefront-cli/commands/message.rb +2 -0
  27. data/lib/wavefront-cli/commands/metric.rb +2 -0
  28. data/lib/wavefront-cli/commands/notificant.rb +2 -0
  29. data/lib/wavefront-cli/commands/proxy.rb +2 -0
  30. data/lib/wavefront-cli/commands/query.rb +2 -0
  31. data/lib/wavefront-cli/commands/savedsearch.rb +2 -0
  32. data/lib/wavefront-cli/commands/serviceaccount.rb +58 -0
  33. data/lib/wavefront-cli/commands/settings.rb +2 -0
  34. data/lib/wavefront-cli/commands/source.rb +3 -1
  35. data/lib/wavefront-cli/commands/user.rb +4 -1
  36. data/lib/wavefront-cli/commands/usergroup.rb +3 -0
  37. data/lib/wavefront-cli/commands/webhook.rb +2 -0
  38. data/lib/wavefront-cli/commands/window.rb +2 -0
  39. data/lib/wavefront-cli/commands/write.rb +2 -0
  40. data/lib/wavefront-cli/config.rb +23 -12
  41. data/lib/wavefront-cli/constants.rb +10 -4
  42. data/lib/wavefront-cli/controller.rb +53 -22
  43. data/lib/wavefront-cli/dashboard.rb +3 -0
  44. data/lib/wavefront-cli/derivedmetric.rb +12 -11
  45. data/lib/wavefront-cli/display/alert.rb +7 -4
  46. data/lib/wavefront-cli/display/apitoken.rb +2 -0
  47. data/lib/wavefront-cli/display/base.rb +34 -8
  48. data/lib/wavefront-cli/display/cloudintegration.rb +4 -2
  49. data/lib/wavefront-cli/display/dashboard.rb +2 -0
  50. data/lib/wavefront-cli/display/derivedmetric.rb +2 -0
  51. data/lib/wavefront-cli/display/distribution.rb +2 -0
  52. data/lib/wavefront-cli/display/event.rb +2 -0
  53. data/lib/wavefront-cli/display/externallink.rb +2 -0
  54. data/lib/wavefront-cli/display/integration.rb +2 -0
  55. data/lib/wavefront-cli/display/maintenancewindow.rb +2 -0
  56. data/lib/wavefront-cli/display/message.rb +7 -3
  57. data/lib/wavefront-cli/display/metric.rb +3 -1
  58. data/lib/wavefront-cli/display/notificant.rb +3 -1
  59. data/lib/wavefront-cli/display/printer/long.rb +36 -11
  60. data/lib/wavefront-cli/display/printer/sparkline.rb +3 -0
  61. data/lib/wavefront-cli/display/printer/terse.rb +6 -1
  62. data/lib/wavefront-cli/display/proxy.rb +2 -0
  63. data/lib/wavefront-cli/display/query.rb +35 -24
  64. data/lib/wavefront-cli/display/savedsearch.rb +2 -0
  65. data/lib/wavefront-cli/display/serviceaccount.rb +60 -0
  66. data/lib/wavefront-cli/display/settings.rb +2 -0
  67. data/lib/wavefront-cli/display/source.rb +18 -4
  68. data/lib/wavefront-cli/display/user.rb +56 -10
  69. data/lib/wavefront-cli/display/usergroup.rb +25 -19
  70. data/lib/wavefront-cli/display/webhook.rb +2 -0
  71. data/lib/wavefront-cli/display/write.rb +6 -2
  72. data/lib/wavefront-cli/event.rb +83 -62
  73. data/lib/wavefront-cli/exception.rb +3 -0
  74. data/lib/wavefront-cli/externallink.rb +6 -4
  75. data/lib/wavefront-cli/integration.rb +2 -0
  76. data/lib/wavefront-cli/maintenancewindow.rb +28 -17
  77. data/lib/wavefront-cli/message.rb +4 -0
  78. data/lib/wavefront-cli/metric.rb +4 -1
  79. data/lib/wavefront-cli/notificant.rb +2 -0
  80. data/lib/wavefront-cli/opt_handler.rb +2 -0
  81. data/lib/wavefront-cli/output/base.rb +8 -3
  82. data/lib/wavefront-cli/output/csv.rb +2 -0
  83. data/lib/wavefront-cli/output/csv/base.rb +2 -0
  84. data/lib/wavefront-cli/output/csv/query.rb +14 -7
  85. data/lib/wavefront-cli/output/hcl.rb +2 -0
  86. data/lib/wavefront-cli/output/hcl/alert.rb +2 -0
  87. data/lib/wavefront-cli/output/hcl/base.rb +10 -4
  88. data/lib/wavefront-cli/output/hcl/dashboard.rb +17 -8
  89. data/lib/wavefront-cli/output/hcl/notificant.rb +2 -0
  90. data/lib/wavefront-cli/output/hcl/stdlib/array.rb +2 -0
  91. data/lib/wavefront-cli/output/hcl/stdlib/string.rb +2 -0
  92. data/lib/wavefront-cli/output/json.rb +2 -0
  93. data/lib/wavefront-cli/output/ruby.rb +2 -0
  94. data/lib/wavefront-cli/output/wavefront.rb +2 -0
  95. data/lib/wavefront-cli/output/wavefront/query.rb +7 -4
  96. data/lib/wavefront-cli/output/yaml.rb +2 -0
  97. data/lib/wavefront-cli/proxy.rb +15 -3
  98. data/lib/wavefront-cli/query.rb +14 -12
  99. data/lib/wavefront-cli/savedsearch.rb +2 -0
  100. data/lib/wavefront-cli/serviceaccount.rb +179 -0
  101. data/lib/wavefront-cli/settings.rb +2 -0
  102. data/lib/wavefront-cli/source.rb +2 -0
  103. data/lib/wavefront-cli/stdlib/array.rb +3 -0
  104. data/lib/wavefront-cli/stdlib/string.rb +17 -11
  105. data/lib/wavefront-cli/user.rb +10 -4
  106. data/lib/wavefront-cli/usergroup.rb +4 -2
  107. data/lib/wavefront-cli/version.rb +3 -1
  108. data/lib/wavefront-cli/webhook.rb +2 -0
  109. data/lib/wavefront-cli/write.rb +80 -46
  110. data/spec/.rubocop.yml +3 -16
  111. data/spec/constants.rb +21 -0
  112. data/spec/spec_helper.rb +8 -422
  113. data/spec/support/command_base.rb +82 -0
  114. data/spec/support/minitest_assertions.rb +262 -0
  115. data/spec/support/output_tester.rb +32 -0
  116. data/spec/support/supported_commands.rb +19 -0
  117. data/spec/test_mixins/acl.rb +169 -0
  118. data/spec/test_mixins/delete.rb +25 -0
  119. data/spec/test_mixins/deleteundelete.rb +106 -0
  120. data/spec/test_mixins/describe.rb +24 -0
  121. data/spec/test_mixins/dump.rb +43 -0
  122. data/spec/test_mixins/general.rb +11 -0
  123. data/spec/test_mixins/history.rb +35 -0
  124. data/spec/test_mixins/import.rb +65 -0
  125. data/spec/test_mixins/list.rb +29 -0
  126. data/spec/test_mixins/search.rb +98 -0
  127. data/spec/test_mixins/set.rb +47 -0
  128. data/spec/test_mixins/tag.rb +99 -0
  129. data/spec/wavefront-cli/alert_spec.rb +288 -111
  130. data/spec/wavefront-cli/apitoken_spec.rb +53 -24
  131. data/spec/wavefront-cli/base_spec.rb +9 -27
  132. data/spec/wavefront-cli/cloudintegration_spec.rb +65 -29
  133. data/spec/wavefront-cli/commands/alert_spec.rb +1 -0
  134. data/spec/wavefront-cli/commands/base_spec.rb +15 -13
  135. data/spec/wavefront-cli/commands/cloudintegration_spec.rb +1 -0
  136. data/spec/wavefront-cli/commands/config_spec.rb +3 -0
  137. data/spec/wavefront-cli/commands/dashboard_spec.rb +1 -0
  138. data/spec/wavefront-cli/commands/derivedmetric_spec.rb +1 -0
  139. data/spec/wavefront-cli/commands/event_spec.rb +1 -0
  140. data/spec/wavefront-cli/commands/link_spec.rb +1 -0
  141. data/spec/wavefront-cli/commands/message_spec.rb +1 -0
  142. data/spec/wavefront-cli/commands/metric_spec.rb +1 -0
  143. data/spec/wavefront-cli/commands/proxy_spec.rb +1 -0
  144. data/spec/wavefront-cli/commands/query_spec.rb +1 -0
  145. data/spec/wavefront-cli/commands/webhook_spec.rb +1 -0
  146. data/spec/wavefront-cli/commands/window_spec.rb +1 -0
  147. data/spec/wavefront-cli/commands/write_spec.rb +1 -0
  148. data/spec/wavefront-cli/config_spec.rb +25 -14
  149. data/spec/wavefront-cli/controller_spec.rb +13 -3
  150. data/spec/wavefront-cli/dashboard_spec.rb +125 -76
  151. data/spec/wavefront-cli/derivedmetric_spec.rb +83 -67
  152. data/spec/wavefront-cli/display/base_spec.rb +5 -7
  153. data/spec/wavefront-cli/display/printer/long_spec.rb +20 -16
  154. data/spec/wavefront-cli/display/printer/terse_spec.rb +5 -4
  155. data/spec/wavefront-cli/event_spec.rb +360 -18
  156. data/spec/wavefront-cli/externallink_spec.rb +92 -58
  157. data/spec/wavefront-cli/integration_spec.rb +129 -31
  158. data/spec/wavefront-cli/maintenancewindow_spec.rb +270 -32
  159. data/spec/wavefront-cli/message_spec.rb +73 -30
  160. data/spec/wavefront-cli/metric_spec.rb +60 -22
  161. data/spec/wavefront-cli/notificant_spec.rb +45 -32
  162. data/spec/wavefront-cli/opt_handler_spec.rb +4 -1
  163. data/spec/wavefront-cli/output/csv/query_spec.rb +21 -19
  164. data/spec/wavefront-cli/output/csv_spec.rb +5 -2
  165. data/spec/wavefront-cli/output/hcl_spec.rb +5 -2
  166. data/spec/wavefront-cli/output/helpers.rb +18 -0
  167. data/spec/wavefront-cli/output/json_spec.rb +3 -1
  168. data/spec/wavefront-cli/output/ruby_spec.rb +3 -1
  169. data/spec/wavefront-cli/output/wavefront/query_spec.rb +3 -1
  170. data/spec/wavefront-cli/output/wavefront_spec.rb +6 -4
  171. data/spec/wavefront-cli/output/yaml_spec.rb +3 -1
  172. data/spec/wavefront-cli/proxy_spec.rb +49 -27
  173. data/spec/wavefront-cli/query_spec.rb +174 -92
  174. data/spec/wavefront-cli/resources/responses/query.json +1 -0
  175. data/spec/wavefront-cli/resources/updates/alert.json +15 -0
  176. data/spec/wavefront-cli/resources/updates/dashboard.json +1 -0
  177. data/spec/wavefront-cli/savedsearch_spec.rb +35 -18
  178. data/spec/wavefront-cli/serviceaccount_spec.rb +399 -0
  179. data/spec/wavefront-cli/settings_spec.rb +42 -11
  180. data/spec/wavefront-cli/source_spec.rb +120 -23
  181. data/spec/wavefront-cli/stdlib/array_spec.rb +2 -1
  182. data/spec/wavefront-cli/stdlib/string_spec.rb +9 -6
  183. data/spec/wavefront-cli/user_spec.rb +278 -108
  184. data/spec/wavefront-cli/usergroup_spec.rb +152 -102
  185. data/spec/wavefront-cli/webhook_spec.rb +30 -15
  186. data/spec/wavefront-cli/write_spec.rb +25 -1
  187. data/wavefront-cli.gemspec +5 -3
  188. metadata +65 -21
  189. data/spec/wavefront-cli/commands/spec_helper.rb +0 -3
  190. data/spec/wavefront-cli/display/spec_helper.rb +0 -3
@@ -1,11 +1,18 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require_relative '../spec_helper'
4
+ require 'minitest/autorun'
5
+ require_relative '../constants'
6
+ require_relative '../support/supported_commands'
4
7
  require_relative '../../lib/wavefront-cli/controller'
5
8
 
6
9
  # Be sure the CLI behaves properly when people ask for help
7
10
  #
8
11
  class WavefrontCliHelpTest < MiniTest::Test
12
+ def test_development_mode
13
+ refute defined?(DEVELOPMENT) if ENV['CI']
14
+ end
15
+
9
16
  def test_no_args
10
17
  capture_io { WavefrontCliController.new([]) }
11
18
  rescue SystemExit => e
@@ -27,11 +34,14 @@ class WavefrontCliHelpTest < MiniTest::Test
27
34
  rescue SystemExit => e
28
35
  assert_equal(1, e.status)
29
36
  assert_match(/^Commands:$/, e.message)
30
- CMDS.each { |cmd| assert_match(/^ #{cmd} /, e.message) }
37
+
38
+ SupportedCommands.new.all.each do |cmd|
39
+ assert_match(/^ #{cmd} /, e.message)
40
+ end
31
41
  end
32
42
 
33
43
  def test_command_help
34
- CMDS.each do |cmd|
44
+ SupportedCommands.new.all.each do |cmd|
35
45
  begin
36
46
  capture_io { WavefrontCliController.new([cmd, '--help']) }
37
47
  rescue SystemExit => e
@@ -1,86 +1,135 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- id = 'test_dashboard'
4
- bad_id = '>_<'
5
- word = 'dashboard'
6
-
7
- require_relative '../spec_helper'
8
- require_relative "../../lib/wavefront-cli/#{word}"
9
-
10
- describe "#{word} command" do
11
- missing_creds(word, ['list', "describe #{id}", "delete #{id}",
12
- "undelete #{id}", "history #{id}"])
13
- list_tests(word)
14
- noop_tests(word, id, true)
15
- cmd_to_call(word, "describe #{id}", path: "/api/v2/#{word}/#{id}")
16
- cmd_to_call(word, "describe -v 7 #{id}",
17
- path: "/api/v2/#{word}/#{id}/history/7")
18
- cmd_to_call(word, "history #{id}", path: "/api/v2/#{word}/#{id}/history")
19
-
20
- it 'deletes with a check on inTrash' do
21
- stub_request(:get,
22
- "https://other.wavefront.com/api/v2/#{word}/#{id}")
23
- .with(headers: { 'Accept': '*/*',
24
- 'Accept-Encoding':
25
- 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
26
- 'Authorization': 'Bearer 0123456789-ABCDEF',
27
- 'User-Agent': /wavefront.*/ })
28
- .to_return(status: 200, body: '', headers: {})
29
- cmd_to_call(word, "delete #{id}",
30
- method: :delete, path: "/api/v2/#{word}/#{id}")
4
+ require_relative '../support/command_base'
5
+ require_relative '../test_mixins/acl'
6
+ require_relative '../test_mixins/tag'
7
+ require_relative '../test_mixins/history'
8
+ require_relative '../../lib/wavefront-cli/dashboard'
9
+
10
+ # Ensure 'dashboard' commands produce the correct API calls.
11
+ #
12
+ class DashboardEndToEndTest < EndToEndTest
13
+ # include WavefrontCliTest::Import
14
+ include WavefrontCliTest::Set
15
+ include WavefrontCliTest::DeleteUndelete
16
+ include WavefrontCliTest::Dump
17
+ include WavefrontCliTest::List
18
+ include WavefrontCliTest::Describe
19
+ include WavefrontCliTest::Search
20
+ include WavefrontCliTest::Tag
21
+ include WavefrontCliTest::History
22
+ include WavefrontCliTest::Acl
23
+
24
+ def test_queries
25
+ quietly do
26
+ assert_cmd_gets('queries', '/api/v2/dashboard?limit=999&offset=0')
27
+ end
31
28
  end
32
29
 
33
- cmd_to_call(word,
34
- 'favs',
35
- method: :post,
36
- path: "/api/v2/search/#{word}",
37
- body: { limit: 999,
38
- offset: 0,
39
- query: [{ key: 'favorite',
40
- value: 'true',
30
+ def test_favs
31
+ assert_repeated_output('No favourites.') do
32
+ assert_cmd_posts('favs', '/api/v2/search/dashboard',
33
+ { limit: 999,
34
+ offset: 0,
35
+ query: [{ key: 'favorite',
36
+ value: 'true',
41
37
  matchingMethod: 'EXACT',
42
- negated: false }],
43
- sort: { field: 'id',
44
- ascending: true } }.to_json)
45
-
46
- spies = [{ class: 'WavefrontCli::Dashboard',
47
- method: :do_favs,
48
- return: nil }]
49
-
50
- cmd_to_call(word,
51
- "fav #{id}",
52
- { method: :post,
53
- path: "/api/v2/#{word}/#{id}/favorite" },
54
- nil,
55
- spies)
56
-
57
- cmd_to_call(word,
58
- "unfav #{id}",
59
- { method: :post,
60
- path: "/api/v2/#{word}/#{id}/unfavorite" },
61
- nil,
62
- spies)
63
-
64
- cmd_to_call(word, "undelete #{id}",
65
- method: :post, path: "/api/v2/#{word}/#{id}/undelete")
66
- invalid_ids(word, ["describe #{bad_id}", "delete #{bad_id}",
67
- "undelete #{bad_id}"])
68
- tag_tests(word, id, bad_id)
69
- search_tests(word, id)
70
- test_list_output(word)
71
- acl_tests(word, id, bad_id)
72
- end
38
+ negated: false }],
39
+ sort: { field: 'id',
40
+ ascending: true } }.to_json)
41
+ end
42
+ end
43
+
44
+ def test_fav
45
+ assert_repeated_output('No favourites.') do
46
+ all_permutations do |perm|
47
+ stub_request(:post, "https://#{perm[:endpoint]}/api/v2/search" \
48
+ '/dashboard')
49
+ .with(body: { limit: 999,
50
+ offset: 0,
51
+ query: [{ key: 'favorite',
52
+ value: 'true',
53
+ matchingMethod: 'EXACT',
54
+ negated: false }],
55
+ sort: { field: 'id', ascending: true } },
56
+ headers: mk_headers(perm[:token]))
57
+ .to_return(status: 200, body: '', headers: {})
58
+
59
+ stub_request(:post,
60
+ "https://#{perm[:endpoint]}/api/v2/dashboard/" \
61
+ 'test_dashboard/favorite')
62
+ .with(body: 'null',
63
+ headers: mk_headers(perm[:token]))
64
+ .to_return(status: 200, body: '', headers: {})
65
+
66
+ wf.new("#{cmd_word} fav #{id} #{perm[:cmdline]}".split)
67
+ end
68
+ end
69
+
70
+ assert_abort_on_missing_creds("fav #{id}")
71
+ assert_invalid_id("fav #{invalid_id}")
72
+ assert_usage('fav')
73
+ end
74
+
75
+ def test_unfav
76
+ assert_repeated_output('No favourites.') do
77
+ all_permutations do |perm|
78
+ search_stub = unfav_search_stub(perm)
79
+ action_stub = unfav_action_stub(perm)
80
+ wf.new("#{cmd_word} unfav #{id} #{perm[:cmdline]}".split)
81
+ assert_requested(search_stub)
82
+ assert_requested(action_stub)
83
+ end
84
+ end
85
+
86
+ assert_abort_on_missing_creds("unfav #{id}")
87
+ assert_invalid_id("unfav #{invalid_id}")
88
+ assert_usage('unfav')
89
+ end
90
+
91
+ private
92
+
93
+ def unfav_search_stub(perm)
94
+ stub_request(:post, "https://#{perm[:endpoint]}/api/v2/search/dashboard")
95
+ .with(body: { limit: 999,
96
+ offset: 0,
97
+ query: [{ key: 'favorite',
98
+ value: 'true',
99
+ matchingMethod: 'EXACT',
100
+ negated: false }],
101
+ sort: { field: 'id', ascending: true } },
102
+ headers: mk_headers(perm[:token]))
103
+ .to_return(status: 200, body: '', headers: {})
104
+ end
105
+
106
+ def unfav_action_stub(perm)
107
+ stub_request(:post,
108
+ "https://#{perm[:endpoint]}/api/v2/dashboard/test_dashboard" \
109
+ '/unfavorite')
110
+ .with(body: 'null',
111
+ headers: mk_headers(perm[:token]))
112
+ .to_return(status: 200, body: '', headers: {})
113
+ end
114
+
115
+ def id
116
+ 'test_dashboard'
117
+ end
73
118
 
74
- class TestAlertMethods < CliMethodTest
75
- def cliclass
76
- WavefrontCli::Dashboard
119
+ def invalid_id
120
+ '>_<'
77
121
  end
78
122
 
79
- def test_import_method
80
- import_tester(:dashboard,
81
- %i[description name parameters tags url creatorId
82
- sections parameterDetails displayDescription
83
- acl numCharts],
84
- %i[id])
123
+ def cmd_word
124
+ 'dashboard'
85
125
  end
126
+
127
+ def import_fields
128
+ %i[description name parameters tags url creatorId sections
129
+ parameterDetails displayDescription acl numCharts]
130
+ end
131
+
132
+ def import_data; end
133
+
134
+ def update_data; end
86
135
  end
@@ -1,84 +1,100 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- word = 'derivedmetric'
4
+ require_relative '../support/command_base'
5
+ require_relative '../test_mixins/tag'
6
+ require_relative '../test_mixins/history'
7
+ require_relative '../../lib/wavefront-cli/derivedmetric'
4
8
 
5
- require_relative '../spec_helper'
6
- require_relative "../../lib/wavefront-cli/#{word}"
9
+ # Ensure 'derivedmetric' commands produce the correct API calls.
10
+ #
11
+ class DerivedMetricEndToEndTest < EndToEndTest
12
+ include WavefrontCliTest::List
13
+ include WavefrontCliTest::Describe
14
+ include WavefrontCliTest::Dump
15
+ # include WavefrontCliTest::Import
16
+ include WavefrontCliTest::Set
17
+ include WavefrontCliTest::DeleteUndelete
18
+ include WavefrontCliTest::Search
19
+ include WavefrontCliTest::Tag
20
+ include WavefrontCliTest::History
7
21
 
8
- id = '1529938767979'
9
- bad_id = '>_<'
22
+ def test_create_simple
23
+ quietly do
24
+ assert_cmd_posts('create mymetric ts(series)',
25
+ '/api/v2/derivedmetric',
26
+ minutes: 5,
27
+ name: 'mymetric',
28
+ includeObsoleteMetrics: false,
29
+ processRateMinutes: 1,
30
+ query: 'ts(series)')
31
+ end
10
32
 
11
- k = WavefrontCli::DerivedMetric
33
+ assert_noop('create mymetric ts(series)',
34
+ 'uri: POST https://default.wavefront.com/api/v2/' \
35
+ 'derivedmetric',
36
+ 'body: ' + {
37
+ query: 'ts(series)',
38
+ name: 'mymetric',
39
+ minutes: 5,
40
+ includeObsoleteMetrics: false,
41
+ processRateMinutes: 1
42
+ }.to_json)
12
43
 
13
- describe "#{word} command" do
14
- missing_creds(word, ['list', "describe #{id}", "delete #{id}",
15
- "undelete #{id}", "history #{id}"])
16
- list_tests(word, nil, k)
17
- noop_tests(word, id, true, word, k)
18
- search_tests(word, id, k)
19
- cmd_to_call(word, "describe #{id}", { path: "/api/v2/#{word}/#{id}" }, k)
20
- cmd_to_call(word, "describe -v 7 #{id}",
21
- { path: "/api/v2/#{word}/#{id}/history/7" }, k)
22
- cmd_to_call(word, "history #{id}",
23
- { path: "/api/v2/#{word}/#{id}/history" }, k)
44
+ assert_usage('create')
45
+ assert_abort_on_missing_creds("create #{id} ts(series)")
46
+ # Names are free-text, so there aren't any invalid ID tests for this
47
+ # command.
48
+ end
24
49
 
25
- it 'deletes with a check on inTrash' do
26
- stub_request(:get,
27
- "https://other.wavefront.com/api/v2/#{word}/#{id}")
28
- .with(headers: { 'Accept': '*/*',
29
- 'Accept-Encoding':
30
- 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
31
- 'Authorization': 'Bearer 0123456789-ABCDEF',
32
- 'User-Agent': /wavefront.*/ })
33
- .to_return(status: 200, body: '', headers: {})
34
- cmd_to_call(word, "delete #{id}",
35
- { method: :delete, path: "/api/v2/#{word}/#{id}" }, k)
50
+ def create_with_options
51
+ quietly do
52
+ assert_cmd_posts('create -i 3 -r 7 -b mymetric ts(series)',
53
+ '/api/v2/derivedmetric',
54
+ minutes: 7,
55
+ name: 'mymetric',
56
+ includeObsoleteMetrics: true,
57
+ processRateMinutes: 3,
58
+ query: 'ts(series)')
59
+ end
36
60
  end
37
61
 
38
- cmd_to_call(word, "undelete #{id}",
39
- { method: :post, path: "/api/v2/#{word}/#{id}/undelete" }, k)
40
- invalid_ids(word, ["describe #{bad_id}", "delete #{bad_id}",
41
- "undelete #{bad_id}"])
42
- tag_tests(word, id, bad_id, nil, k)
62
+ def create_with_options_and_tags
63
+ quietly do
64
+ assert_cmd_posts('create -i 3 -T tag1 -T tag2 mymetric ts(series)',
65
+ '/api/v2/derivedmetric',
66
+ minutes: 5,
67
+ name: 'mymetric',
68
+ includeObsoleteMetrics: false,
69
+ processRateMinutes: 3,
70
+ tags: %w[tag1 tag2],
71
+ query: 'ts(series)')
72
+ end
73
+ end
43
74
 
44
- cmd_to_call(word, 'create test_dm ts(series)',
45
- { method: :post, path: '/api/v2/derivedmetric',
46
- body: { minutes: 5,
47
- name: 'test_dm',
48
- includeObsoleteMetrics: false,
49
- processRateMinutes: 1,
50
- query: 'ts(series)' },
51
- headers: JSON_POST_HEADERS }, k)
75
+ private
52
76
 
53
- cmd_to_call(word, 'create -i 3 -r 7 -b test_dm ts(series)',
54
- { method: :post, path: '/api/v2/derivedmetric',
55
- body: { minutes: 7,
56
- name: 'test_dm',
57
- includeObsoleteMetrics: true,
58
- processRateMinutes: 3,
59
- query: 'ts(series)' },
60
- headers: JSON_POST_HEADERS }, k)
77
+ def id
78
+ '1529926075038'
79
+ end
61
80
 
62
- cmd_to_call(word, 'create -i 3 -T tag1 -T tag2 test_dm ts(series)',
63
- { method: :post, path: '/api/v2/derivedmetric',
64
- body: { minutes: 5,
65
- name: 'test_dm',
66
- includeObsoleteMetrics: false,
67
- processRateMinutes: 3,
68
- tags: %w[tag1 tag2],
69
- query: 'ts(series)' },
70
- headers: JSON_POST_HEADERS }, k)
71
- test_list_output(word, k)
72
- end
81
+ def invalid_id
82
+ '__BAD__'
83
+ end
84
+
85
+ def cmd_word
86
+ 'derivedmetric'
87
+ end
88
+
89
+ def sdk_class_name
90
+ 'DerivedMetric'
91
+ end
73
92
 
74
- class TestDerivedMetricMethods < CliMethodTest
75
- def test_import_method
76
- import_tester(:derivedmetric,
77
- %i[tags minutes name query metricsUsed hostsUsed],
78
- %i[id])
93
+ def import_fields
94
+ %i[tags minutes name query metricsUsed hostsUsed]
79
95
  end
80
96
 
81
- def cliclass
82
- WavefrontCli::DerivedMetric
97
+ def friendly_name
98
+ 'derived metric'
83
99
  end
84
100
  end
@@ -1,12 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'date'
4
5
  require 'map'
5
- require 'pathname'
6
- require_relative(File.join('../../../lib/wavefront-cli/display',
7
- Pathname.new(__FILE__).basename
8
- .to_s.sub('_spec.rb', '')))
9
- require_relative 'spec_helper'
6
+ require 'minitest/autorun'
7
+ require 'spy/integration'
8
+ require_relative '../../../lib/wavefront-cli/display/base'
10
9
 
11
10
  S_DATA = Map.new
12
11
  S_OPTIONS = { '<id>': 'abc123' }.freeze
@@ -175,10 +174,9 @@ class WavefrontDisplayBaseTest < MiniTest::Test
175
174
  assert_raises(ArgumentError) { wf.human_time(123) }
176
175
  assert_raises(ArgumentError) { wf.human_time(12_345_678_901_234) }
177
176
  assert_equal('2017-07-07 11:23:35', wf.human_time(1_499_426_615, true))
178
- # rubocop:disable Style/DateTime
179
177
  assert_match(/^20\d\d-[01]\d-[0-3]\d [0-2]\d:[0-5]\d:[0-5]\d.\d{3}$/,
180
178
  wf.human_time(DateTime.now.strftime('%Q')))
181
- # rubocop:enable Style/DateTime
179
+
182
180
  assert_match(/^20\d\d-[01]\d-[0-3]\d [0-2]\d:[0-5]\d:[0-5]\d$/,
183
181
  wf.human_time(Time.now.to_i))
184
182
  assert_equal('2017-07-07 11:23:35.123', wf.human_time(1_499_426_615_123,
@@ -1,8 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
4
+ require 'minitest/autorun'
5
+ require_relative '../../../support/output_tester'
3
6
  require_relative '../../../../lib/wavefront-cli/display/printer/long'
4
- require_relative '../spec_helper'
5
- require_relative '../../../spec_helper'
6
7
 
7
8
  # Test verbose printing stuff
8
9
  #
@@ -48,16 +49,16 @@ class TestWavefrontDisplayPrinterLong < MiniTest::Test
48
49
 
49
50
  pr = WavefrontDisplayPrinter::Long.new({}, nil, nil,
50
51
  indent: 4, padding: 3)
51
- assert_equal({ indent: 4,
52
- padding: 3,
52
+ assert_equal({ indent: 4,
53
+ padding: 3,
53
54
  separator: true,
54
- none: true }, pr.opts)
55
+ none: true }, pr.opts)
55
56
 
56
57
  pr = WavefrontDisplayPrinter::Long.new({}, nil, nil, none: false)
57
- assert_equal({ indent: 2,
58
- padding: 2,
58
+ assert_equal({ indent: 2,
59
+ padding: 2,
59
60
  separator: true,
60
- none: false }, pr.opts)
61
+ none: false }, pr.opts)
61
62
  end
62
63
 
63
64
  def test_longest_key_col
@@ -76,33 +77,36 @@ class TestWavefrontDisplayPrinterLong < MiniTest::Test
76
77
  end
77
78
 
78
79
  def test_to_s
79
- assert_equal("today\n weather sunny\n day Tuesday",
80
+ assert_equal("today\n" \
81
+ " weather sunny\n" \
82
+ ' day Tuesday',
80
83
  WavefrontDisplayPrinter::Long.new(
81
84
  today: { weather: 'sunny', day: :Tuesday }
82
85
  ).to_s)
83
86
 
84
- assert_equal("key1 val1\nkey2 val2",
87
+ assert_equal("key1 val1\n" \
88
+ 'key2 val2',
85
89
  WavefrontDisplayPrinter::Long.new(
86
90
  key1: 'val1', key2: 'val2'
87
91
  ).to_s)
88
92
  end
89
93
 
90
94
  def test_end_to_end
91
- input, expected = OUTPUT_TESTER.in_and_out('user-input.json',
92
- 'user-human-long')
95
+ input, expected = OutputTester.new.in_and_out('user-input.json',
96
+ 'user-human-long')
93
97
  output = WavefrontDisplayPrinter::Long.new(input).to_s
94
98
  assert_equal(expected, output + "\n")
95
99
 
96
- input, expected = OUTPUT_TESTER.in_and_out('user-input.json',
97
- 'user-human-long-no_sep')
100
+ input, expected = OutputTester.new.in_and_out('user-input.json',
101
+ 'user-human-long-no_sep')
98
102
  output = WavefrontDisplayPrinter::Long.new(input, nil, nil,
99
103
  separator: false).to_s
100
104
  assert_equal(expected, output + "\n")
101
105
  end
102
106
 
103
107
  def test_end_to_end_fold
104
- input, expected = OUTPUT_TESTER.in_and_out('alert-input.json',
105
- 'alert-human-long')
108
+ input, expected = OutputTester.new.in_and_out('alert-input.json',
109
+ 'alert-human-long')
106
110
  output = WavefrontDisplayPrinter::Long.new(input).to_s
107
111
  assert_equal(expected, output + "\n")
108
112
  end