wavefront-cli 4.2.1 → 4.3.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 (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,6 +1,9 @@
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 'helpers'
6
+ require_relative '../../support/supported_commands'
4
7
  require_relative '../../../lib/wavefront-cli/output/wavefront'
5
8
 
6
9
  # Test the Wavefront instantiation of the base class
@@ -9,8 +12,7 @@ class WavefrontOutputBaseTest < MiniTest::Test
9
12
  attr_reader :wfo
10
13
 
11
14
  def setup
12
- @wfo = WavefrontOutput::Wavefront.new(load_query_response,
13
- class: 'query')
15
+ @wfo = WavefrontOutput::Wavefront.new(load_query_response, class: 'query')
14
16
  end
15
17
 
16
18
  def test_my_format
@@ -36,7 +38,7 @@ class WavefrontOutputBaseTest < MiniTest::Test
36
38
  assert klass.respond_to?(:run)
37
39
  end
38
40
 
39
- (CMDS - supported_commands).each do |cmd|
41
+ (SupportedCommands.new.all - supported_commands).each do |cmd|
40
42
  wfo = WavefrontOutput::Wavefront.new(load_query_response, class: cmd)
41
43
  assert_raises(LoadError) { wfo.command_class }
42
44
  end
@@ -1,7 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'yaml'
4
- require_relative '../../spec_helper'
5
+ require_relative 'helpers'
6
+ require 'minitest/autorun'
5
7
  require_relative '../../../lib/wavefront-cli/output/yaml'
6
8
 
7
9
  # Test YAML output
@@ -1,30 +1,52 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- id = 'fd248f53-378e-4fbe-bbd3-efabace8d724'
4
- bad_id = '__bad_id__'
5
- word = 'proxy'
6
-
7
- require_relative '../spec_helper'
8
- require_relative "../../lib/wavefront-cli/#{word}"
9
-
10
- describe "#{word} command" do
11
- missing_creds(word, ['list', 'versions', "describe #{id}", "delete #{id}",
12
- "undelete #{id}", "rename #{id} newname"])
13
- list_tests(word)
14
- noop_tests(word, id)
15
- cmd_to_call(word, "describe #{id}", path: "/api/v2/#{word}/#{id}")
16
- cmd_to_call(word, 'versions', path: "/api/v2/#{word}?limit=999&offset=0")
17
- cmd_to_call(word, "rename #{id} newname",
18
- method: :put,
19
- path: "/api/v2/#{word}/#{id}",
20
- body: { name: 'newname' }.to_json)
21
- cmd_to_call(word, "delete #{id}",
22
- method: :delete, path: "/api/v2/#{word}/#{id}")
23
- cmd_to_call(word, "undelete #{id}",
24
- method: :post, path: "/api/v2/#{word}/#{id}/undelete")
25
- invalid_ids(word, ["describe #{bad_id}", "delete #{bad_id}",
26
- "undelete #{bad_id}", "rename #{bad_id} newname"])
27
- invalid_something(word, ["rename #{id} '(>_<)'"], 'proxy name')
28
- search_tests(word, id)
29
- test_list_output(word)
4
+ require_relative '../support/command_base'
5
+ require_relative '../../lib/wavefront-cli/proxy'
6
+
7
+ # Ensure 'proxy' commands produce the correct API calls.
8
+ #
9
+ class ProxyEndToEndTest < EndToEndTest
10
+ include WavefrontCliTest::DeleteUndelete
11
+ include WavefrontCliTest::Describe
12
+ include WavefrontCliTest::List
13
+ include WavefrontCliTest::Search
14
+
15
+ def test_versions
16
+ quietly do
17
+ assert_cmd_gets('versions', '/api/v2/proxy?limit=999&offset=0')
18
+ end
19
+
20
+ assert_abort_on_missing_creds('versions')
21
+ assert_noop('versions',
22
+ 'uri: GET https://default.wavefront.com/api/v2/proxy',
23
+ 'params: {:offset=>0, :limit=>999}')
24
+ end
25
+
26
+ def test_rename
27
+ quietly do
28
+ assert_cmd_puts("rename #{id} newname", "/api/v2/proxy/#{id}",
29
+ tokenID: id, tokenName: 'newname')
30
+ end
31
+
32
+ assert_noop("rename #{id} newname",
33
+ "uri: PUT https://default.wavefront.com/api/v2/proxy/#{id}",
34
+ 'body: {"name":"newname"}')
35
+ assert_invalid_id("rename #{invalid_id} newname")
36
+ assert_abort_on_missing_creds("rename #{id} newname")
37
+ end
38
+
39
+ private
40
+
41
+ def id
42
+ 'fd248f53-378e-4fbe-bbd3-efabace8d724'
43
+ end
44
+
45
+ def invalid_id
46
+ '__BAD__'
47
+ end
48
+
49
+ def cmd_word
50
+ 'proxy'
51
+ end
30
52
  end
@@ -1,105 +1,187 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- word = 'query'
4
-
5
- require_relative '../spec_helper'
6
- require_relative "../../lib/wavefront-cli/#{word}"
4
+ require_relative '../support/command_base'
5
+ require_relative '../../lib/wavefront-cli/query'
7
6
  require 'wavefront-sdk/support/mixins'
8
- # rubocop:disable Style/MixinUsage
9
- include Wavefront::Mixins
10
- # rubocop:enable Style/MixinUsage
11
7
 
12
- q = 'ts("dev.cli.test")'
13
- #
14
- # The SDK has got smarter about calculating granularity options, so
15
- # we can't use any kind of absolute time any more. We round time
16
- # down to the nearest minute, because that's how users will most
17
- # likely specify it.
8
+ # Ensure 'query' commands produce the correct API calls.
18
9
  #
19
- t1_t = Time.now - (30 * 60)
20
- t1_t = Time.at(t1_t.to_i - t1_t.sec)
21
- t2_t = Time.at(t1_t + (10 * 60))
22
-
23
- t1 = parse_time(t1_t, true)
24
- t2 = parse_time(t2_t, true)
25
- o = "-g m -s #{t1_t.strftime('%H:%M')}"
26
- s_and_e_opts = "-s #{t1_t.strftime('%H:%M')} -e #{t2_t.strftime('%H:%M')}"
27
-
28
- describe "#{word} command" do
29
- cmd_to_call(word, "-s -2h #{q}",
30
- path: '/api/v2/chart/api\\?g=m&i=false' \
31
- '&listMode=true&q=ts\(%22dev.cli.test%22\)' \
32
- '&s=[0-9]{13}&sorted=true&strict=true&summarization=mean',
33
- regex: true)
34
-
35
- missing_creds(word, ["#{o} '#{q}'", "raw #{q}"])
36
-
37
- cmd_noop(word, "-s #{t1} #{q}",
38
- ['GET https://metrics.wavefront.com/api/v2/chart/api',
39
- i: false, summarization: 'mean', listMode: true, strict: true,
40
- sorted: true, q: q, g: :m, s: t1])
41
-
42
- cmd_noop(word, 'raw dev.cli.test',
43
- ['GET https://metrics.wavefront.com/api/v2/chart/raw',
44
- metric: 'dev.cli.test'])
45
-
46
- cmd_to_call(word, "#{o} #{q}",
47
- path: '/api/v2/chart/api?g=m&i=false&listMode=true' \
48
- "&q=ts(%22dev.cli.test%22)&s=#{t1}&sorted=true" \
49
- '&strict=true&summarization=mean')
50
-
51
- cmd_to_call(word, "#{s_and_e_opts} #{q}",
52
- path: "/api/v2/chart/api?e=#{t2}&g=m&i=false" \
53
- '&listMode=true&q=ts(%22dev.cli.test%22)' \
54
- "&s=#{t1}&sorted=true&strict=true&summarization=mean")
55
-
56
- cmd_to_call(word, "-g s #{s_and_e_opts} -S max #{q}",
57
- path: "/api/v2/chart/api?e=#{t2}&g=s&i=false" \
58
- '&listMode=true&q=ts(%22dev.cli.test%22)' \
59
- "&s=#{t1}&sorted=true&strict=true&summarization=max")
60
-
61
- cmd_to_call(word, "-g s #{s_and_e_opts} -p 100 #{q}",
62
- path: "/api/v2/chart/api?e=#{t2}&g=s&i=false" \
63
- '&listMode=true&q=ts(%22dev.cli.test%22)' \
64
- "&s=#{t1}&sorted=true&summarization=mean&strict=true" \
65
- '&p=100')
66
-
67
- cmd_to_call(word, "-iO -g h #{s_and_e_opts} -p 100 #{q}",
68
- path: "/api/v2/chart/api?e=#{t2}&g=h&i=true" \
69
- '&listMode=true&q=ts(%22dev.cli.test%22)' \
70
- "&s=#{t1}&sorted=true&summarization=mean" \
71
- '&strict=true&p=100&includeObsoleteMetrics=true')
72
-
73
- cmd_to_call(word, "-N query -g h #{s_and_e_opts} -p 100 #{q}",
74
- path: "/api/v2/chart/api?e=#{t2}&g=h&i=false" \
75
- '&listMode=true&q=ts(%22dev.cli.test%22)' \
76
- "&s=#{t1}&sorted=true&summarization=mean" \
77
- '&strict=true&p=100&n=query')
78
-
79
- cmd_to_call(word, 'raw dev.cli.test',
80
- path: '/api/v2/chart/raw?metric=dev.cli.test')
81
-
82
- cmd_to_call(word, 'raw -H h1 dev.cli.test',
83
- path: '/api/v2/chart/raw?metric=dev.cli.test&source=h1')
84
-
85
- cmd_to_call(word, "raw -s #{t1_t.strftime('%H:%M')} -H h1 dev.cli.test",
86
- path: '/api/v2/chart/raw?metric=dev.cli.test&source=h1' \
87
- "&startTime=#{t1}")
88
-
89
- cmd_to_call(word, "raw #{s_and_e_opts} -H h1 dev.cli.test",
90
- path: '/api/v2/chart/raw?metric=dev.cli.test&source=h1' \
91
- "&startTime=#{t1}&endTime=#{t2}")
92
- end
10
+ class QueryEndToEndTest < EndToEndTest
11
+ include Wavefront::Mixins
12
+
13
+ def test_query_specifying_start_of_window_no_sparkline
14
+ out, err = capture_io do
15
+ assert_cmd_gets_with_params("-s #{epoch_time[0]} -k #{query}",
16
+ '/api/v2/chart/api',
17
+ { q: query,
18
+ g: 'm',
19
+ s: epoch_time[0].to_s }, canned_response)
20
+ end
21
+
22
+ assert_empty(err)
23
+ assert_match(/name\s+ts\("cpu.0.pc.user"\)/, out)
24
+ assert_match(/query\s+ts\("cpu.0.pc.user"\)/, out)
25
+ refute_match(/sparkline/, out)
26
+
27
+ assert_noop(
28
+ "-s #{epoch_time[0]} -k #{query}",
29
+ 'uri: GET https://default.wavefront.com/api/v2/chart/api',
30
+ 'params: {:i=>false, :summarization=>"mean", :listMode=>true, ' \
31
+ ':strict=>true, :sorted=>true, :q=>"ts(\"dev.cli.test\")", ' \
32
+ ":g=>:m, :s=>#{epoch_time[0]}}"
33
+ )
34
+ end
35
+
36
+ def test_query_with_start_and_end
37
+ out, err = capture_io do
38
+ assert_cmd_gets_with_params("#{start_and_end_opts} #{query}",
39
+ '/api/v2/chart/api',
40
+ { q: query,
41
+ g: 'm',
42
+ s: epoch_time[0].to_s,
43
+ e: epoch_time[1].to_s }, canned_response)
44
+ end
45
+
46
+ assert_empty(err)
47
+ assert_match(/query\s+ts\("cpu.0.pc.user"\)/, out)
48
+ end
49
+
50
+ def test_query_with_start_and_end_and_max_summary
51
+ out, err = capture_io do
52
+ assert_cmd_gets_with_params("#{start_and_end_opts} -S max #{query}",
53
+ '/api/v2/chart/api',
54
+ { q: query,
55
+ g: 'm',
56
+ summarization: 'max',
57
+ s: epoch_time[0].to_s,
58
+ e: epoch_time[1].to_s }, canned_response)
59
+ end
60
+
61
+ assert_empty(err)
62
+ assert_match(/query\s+ts\("cpu.0.pc.user"\)/, out)
63
+ end
64
+
65
+ def test_query_with_start_and_end_and_max_number_of_points
66
+ out, err = capture_io do
67
+ assert_cmd_gets_with_params("#{start_and_end_opts} -p 100 #{query}",
68
+ '/api/v2/chart/api',
69
+ { q: query,
70
+ g: 'm',
71
+ p: '100',
72
+ s: epoch_time[0].to_s,
73
+ e: epoch_time[1].to_s }, canned_response)
74
+ end
75
+
76
+ assert_empty(err)
77
+ assert_match(/query\s+ts\("cpu.0.pc.user"\)/, out)
78
+ end
79
+
80
+ def test_query_with_start_and_end_and_granularity_and_obsolete
81
+ out, err = capture_io do
82
+ assert_cmd_gets_with_params("#{start_and_end_opts} -g h -O #{query}",
83
+ '/api/v2/chart/api',
84
+ { q: query,
85
+ g: 'h',
86
+ includeObsoleteMetrics: 'true',
87
+ s: epoch_time[0].to_s,
88
+ e: epoch_time[1].to_s }, canned_response)
89
+ end
90
+
91
+ assert_empty(err)
92
+ assert_match(/query\s+ts\("cpu.0.pc.user"\)/, out)
93
+ end
94
+
95
+ def test_query_with_start_and_end_and_name
96
+ out, err = capture_io do
97
+ assert_cmd_gets_with_params(
98
+ "#{start_and_end_opts} -g s -N query #{query}",
99
+ '/api/v2/chart/api',
100
+ { q: query,
101
+ g: 's',
102
+ n: 'query',
103
+ s: epoch_time[0].to_s,
104
+ e: epoch_time[1].to_s }, canned_response
105
+ )
106
+ end
93
107
 
94
- describe 'output formatting' do
95
- it 'tests query output' do
96
- out, err = command_output(word, :do_default, nil, 'query-cpu.json')
97
- refute_empty(out)
98
108
  assert_empty(err)
99
- assert out.start_with?('name ')
109
+ assert_match(/query\s+ts\("cpu.0.pc.user"\)/, out)
110
+ end
111
+
112
+ def test_raw
113
+ assert_cmd_gets('raw dev.cli.test',
114
+ '/api/v2/chart/raw?metric=dev.cli.test')
115
+
116
+ assert_noop('raw dev.cli.test',
117
+ 'uri: GET https://default.wavefront.com/api/v2/chart/raw',
118
+ 'params: {:metric=>"dev.cli.test"}')
119
+ assert_abort_on_missing_creds('raw dev.cli.test')
120
+ end
121
+
122
+ def test_error_if_the_query_is_a_literal_raw
123
+ out, err = capture_io do
124
+ assert_raises(SystemExit) do
125
+ assert_cmd_gets_with_params('raw',
126
+ '/api/v2/chart/api',
127
+ { g: 'm', q: 'raw' },
128
+ { errorMessage: 'mock error' }.to_json)
129
+ end
130
+ end
131
+
132
+ assert_empty(out)
133
+ assert_equal("Invalid query. API message: 'mock error'.", err.strip)
134
+ end
135
+
136
+ def test_raw_with_host
137
+ assert_cmd_gets('raw -H h1 dev.cli.test',
138
+ '/api/v2/chart/raw?metric=dev.cli.test&source=h1')
139
+ end
140
+
141
+ def test_raw_with_start_and_host
142
+ assert_cmd_gets("raw -s #{wall_time[0].strftime('%H:%M')} " \
143
+ '-H h1 dev.cli.test',
144
+ '/api/v2/chart/raw?metric=dev.cli.test&source=h1' \
145
+ "&startTime=#{epoch_time[0]}")
146
+ end
147
+
148
+ def test_raw_with_start_and_end_and_host
149
+ assert_cmd_gets("raw #{start_and_end_opts} -H h1 dev.cli.test",
150
+ '/api/v2/chart/raw?metric=dev.cli.test&source=h1' \
151
+ "&startTime=#{epoch_time[0]}&endTime=#{epoch_time[1]}")
152
+ end
153
+
154
+ private
155
+
156
+ def query
157
+ 'ts("dev.cli.test")'
158
+ end
159
+
160
+ def invalid_id
161
+ '__BAD__'
162
+ end
163
+
164
+ def cmd_word
165
+ 'query'
166
+ end
167
+
168
+ def canned_response
169
+ IO.read(RES_DIR + 'responses' + 'query.json')
100
170
  end
101
171
  end
102
172
 
173
+ #
174
+ # describe 'output formatting' do
175
+ # it 'tests query output' do
176
+ # out, err = command_output(word, :do_default, nil, 'query-cpu.json')
177
+ # refute_empty(out)
178
+ # assert_empty(err)
179
+ # assert out.start_with?('name ')
180
+ # end
181
+ # end
182
+
183
+ # Query tests
184
+ #
103
185
  class QueryTest < MiniTest::Test
104
186
  attr_reader :wf
105
187
 
@@ -0,0 +1 @@
1
+ {"query":"ts(\"cpu.0.pc.user\")","name":"ts(\"cpu.0.pc.user\")","granularity":60,"timeseries":[{"label":"cpu.0.pc.user","host":"cube","tags":{"env":"lab"},"data":[[1567773120,25.359955893658334],[1567773180,22.03986909081],[1567773240,17.05377062129167],[1567773300,24.38730402552667],[1567773360,18.931883242503336],[1567773420,2.7780920554299997],[1567773480,2.9629818391683336],[1567773540,2.7025604580616664],[1567773600,3.4189161957333334],[1567773660,2.59600675876]]}],"stats":{"keys":124,"points":695,"summaries":572,"buffer_keys":124,"compacted_keys":1,"compacted_points":572,"latency":300,"queries":5,"s3_keys":0,"cpu_ns":3080507,"skipped_compacted_keys":0,"cached_compacted_keys":0,"query_tasks":0,"dropped_summaries":0}}
@@ -0,0 +1,15 @@
1
+ {
2
+ "id": "1556812163465",
3
+ "name": "PKS - too many containers not running",
4
+ "target": "target:9wltLtYXsP8Je2kI",
5
+ "tags": {
6
+ "customerTags": [
7
+ "pks"
8
+ ]
9
+ },
10
+ "condition": "sum(ts(pks.kube.pod.container.status.running.gauge)) / (sum(ts(pks.kube.pod.container.status.running.gauge)) + sum(ts(pks.kube.pod.container.status.waiting.gauge)) + sum(ts(pks.kube.pod.container.status.terminated.gauge))) < 0.8",
11
+ "displayExpression": "sum(ts(pks.kube.pod.container.status.running.gauge)) / (sum(ts(pks.kube.pod.container.status.running.gauge)) + sum(ts(pks.kube.pod.container.status.waiting.gauge)) + sum(ts(pks.kube.pod.container.status.terminated.gauge)))",
12
+ "minutes": 5,
13
+ "resolveAfterMinutes": 5,
14
+ "severity": "SEVERE"
15
+ }
@@ -0,0 +1 @@
1
+ {"canUserModify":true,"description":"very simple dashboard for CLI tests","hidden":false,"name":"test dashboard","id":"test_dashboard","parameters":{},"tags":{"customerTags":["test.dashboard"]},"customer":"sysdef","url":"test_dashboard","systemOwned":false,"creatorId":"rob@sysdef.xyz","updaterId":"rob@sysdef.xyz","eventFilterType":"BYCHART","sections":[{"name":"Proxy Section","rows":[{"charts":[{"base":0,"units":"Units","name":"New Chart","sources":[{"name":"New Query","query":"ts(\"~proxy.points.2878.*\")","secondaryAxis":false,"scatterPlotSource":"Y","querybuilderEnabled":false,"sourceDescription":""}],"includeObsoleteMetrics":false,"noDefaultEvents":false,"chartAttributes":null,"chartSettings":{"type":"line","autoColumnTags":false},"interpolatePoints":false}],"heightFactor":100}]}],"parameterDetails":{},"displayDescription":false,"displaySectionTableOfContents":true,"displayQueryParameters":false,"chartTitleScalar":0,"eventQuery":"","defaultTimeWindow":"2h","viewsLastDay":0,"viewsLastWeek":0,"viewsLastMonth":0,"acl":{"canView":[],"canModify":["a7d2e651-cec1-4154-a5e8-1946f57ef5b3"]},"createdEpochMillis":1556807658025,"updatedEpochMillis":1556807741557,"deleted":false,"numFavorites":0,"favorite":false,"numCharts":1,"orphan":false}
@@ -1,21 +1,38 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require_relative '../spec_helper'
4
-
5
- id = '4rUipOK3'
6
- bad_id = '__BAD__'
7
- word = 'savedsearch'
8
- require_relative "../../lib/wavefront-cli/#{word}"
9
- k = WavefrontCli::SavedSearch
10
-
11
- describe "#{word} command" do
12
- missing_creds(word, ['list', "describe #{id}", "delete #{id}"])
13
- list_tests(word, 'savedsearch', k)
14
- noop_tests(word, id, false, 'savedsearch', k)
15
- search_tests(word, id, k, 'savedsearch')
16
- cmd_to_call(word, "describe #{id}", { path: "/api/v2/#{word}/#{id}" }, k)
17
- cmd_to_call(word, "delete #{id}",
18
- { method: :delete, path: "/api/v2/#{word}/#{id}" }, k)
19
- invalid_ids(word, ["describe #{bad_id}", "delete #{bad_id}"])
20
- test_list_output(word, k)
4
+ require_relative '../support/command_base'
5
+ require_relative '../../lib/wavefront-cli/savedsearch'
6
+
7
+ # Ensure 'savedsearch' commands produce the correct API calls.
8
+ #
9
+ class SavedSearchEndToEndTest < EndToEndTest
10
+ include WavefrontCliTest::List
11
+ include WavefrontCliTest::Describe
12
+ include WavefrontCliTest::Delete
13
+ include WavefrontCliTest::Dump
14
+ # include WavefrontCliTest::Import
15
+ include WavefrontCliTest::Search
16
+
17
+ private
18
+
19
+ def id
20
+ '4rUipOK3'
21
+ end
22
+
23
+ def invalid_id
24
+ '__BAD__'
25
+ end
26
+
27
+ def cmd_word
28
+ 'savedsearch'
29
+ end
30
+
31
+ def sdk_class_name
32
+ 'SavedSearch'
33
+ end
34
+
35
+ def friendly_name
36
+ 'saved search'
37
+ end
21
38
  end