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
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WavefrontCliTest
4
+ #
5
+ # Mixin to test standard 'delete' commands.
6
+ #
7
+ module Delete
8
+ def test_delete
9
+ assert_repeated_output("Deleted #{friendly_name} '#{id}'.") do
10
+ assert_cmd_deletes("delete #{id}", "/api/v2/#{api_path}/#{id}")
11
+ end
12
+
13
+ assert_invalid_id("delete #{invalid_id}")
14
+ assert_usage('delete')
15
+
16
+ assert_noop(
17
+ "delete #{id}",
18
+ 'uri: DELETE https://default.wavefront.com/api/v2/' \
19
+ "#{api_path}/#{id}"
20
+ )
21
+
22
+ assert_abort_on_missing_creds("delete #{id}")
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,106 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WavefrontCliTest
4
+ #
5
+ # Mixin to test standard 'delete' and 'undelete' commands
6
+ #
7
+ module DeleteUndelete
8
+ def test_soft_delete
9
+ all_permutations { |p| soft_delete(p) }
10
+ assert_cannot_noop("delete #{id}")
11
+ assert_invalid_id("delete #{invalid_id}")
12
+ assert_usage('delete')
13
+ end
14
+
15
+ def test_hard_delete
16
+ all_permutations { |p| hard_delete(p) }
17
+ end
18
+
19
+ def test_undelete
20
+ out, err = capture_io do
21
+ assert_cmd_posts("undelete #{id}",
22
+ "/api/v2/#{api_path}/#{id}/undelete", 'null')
23
+ end
24
+
25
+ assert_empty(err)
26
+ assert_equal("Undeleted #{friendly_name} '#{id}'.",
27
+ out.lines.first.rstrip)
28
+
29
+ assert_invalid_id("undelete #{invalid_id}")
30
+ assert_usage('undelete')
31
+ assert_abort_on_missing_creds("undelete #{id}")
32
+
33
+ assert_noop(
34
+ "undelete #{id}",
35
+ 'uri: POST https://default.wavefront.com/api/v2/' \
36
+ "#{api_path}/#{id}/undelete",
37
+ 'body: null'
38
+ )
39
+
40
+ assert_invalid_id("undelete #{invalid_id}")
41
+ assert_usage('undelete')
42
+ end
43
+
44
+ private
45
+
46
+ def soft_delete(perm)
47
+ stub_request(:get,
48
+ "https://#{perm[:endpoint]}/api/v2/#{api_path}/#{id}")
49
+ .with(headers: mk_headers(perm[:token]))
50
+ .to_return(object_exists_response)
51
+
52
+ stub_request(:delete,
53
+ "https://#{perm[:endpoint]}/api/v2/#{api_path}/#{id}")
54
+ .with(headers: mk_headers(perm[:token]))
55
+ .to_return(status: 200)
56
+
57
+ out, err = capture_io do
58
+ wf.new("#{cmd_word} delete #{id} #{perm[:cmdline]}".split)
59
+ end
60
+
61
+ assert_empty(err)
62
+ assert_equal("Soft deleting #{friendly_name} '#{id}'\n" \
63
+ "Deleted #{friendly_name} '#{id}'.",
64
+ out.rstrip)
65
+
66
+ assert_requested(
67
+ :get,
68
+ "https://#{perm[:endpoint]}/api/v2/#{api_path}/#{id}"
69
+ )
70
+ end
71
+
72
+ def hard_delete(perm)
73
+ stub_request(:get,
74
+ "https://#{perm[:endpoint]}/api/v2/#{api_path}/#{id}")
75
+ .with(headers: mk_headers(perm[:token]))
76
+ .to_return(object_deleted_response)
77
+
78
+ stub_request(:delete,
79
+ "https://#{perm[:endpoint]}/api/v2/#{api_path}/#{id}")
80
+ .with(headers: mk_headers(perm[:token]))
81
+ .to_return(status: 200)
82
+
83
+ out, err = capture_io do
84
+ wf.new("#{cmd_word} delete #{id} #{perm[:cmdline]}".split)
85
+ end
86
+
87
+ assert_empty(err)
88
+ assert_equal("Permanently deleting #{friendly_name} '#{id}'\n" \
89
+ "Deleted #{friendly_name} '#{id}'.",
90
+ out.rstrip)
91
+
92
+ assert_requested(
93
+ :get,
94
+ "https://#{perm[:endpoint]}/api/v2/#{api_path}/#{id}"
95
+ )
96
+ end
97
+
98
+ def object_exists_response
99
+ { status: 200, headers: {} }
100
+ end
101
+
102
+ def object_deleted_response
103
+ { status: 404, headers: {} }
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WavefrontCliTest
4
+ #
5
+ # Mixin to test standard 'describe' commands
6
+ #
7
+ module Describe
8
+ def test_describe
9
+ quietly do
10
+ assert_cmd_gets("describe #{id}", "/api/v2/#{api_path}/#{id}")
11
+ end
12
+
13
+ assert_invalid_id("describe #{invalid_id}")
14
+ assert_usage('describe')
15
+
16
+ assert_noop(
17
+ "describe #{id}",
18
+ "uri: GET https://default.wavefront.com/api/v2/#{api_path}/#{id}"
19
+ )
20
+
21
+ assert_abort_on_missing_creds("describe #{id}")
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WavefrontCliTest
4
+ #
5
+ # Mixin to test standard 'dump' commands
6
+ #
7
+ module Dump
8
+ def test_dump_human
9
+ assert_exits_with(
10
+ "Dump format must be 'json' or 'yaml'. (Tried 'human')",
11
+ 'dump --format=human'
12
+ )
13
+ end
14
+
15
+ def test_dump_json
16
+ out, err = capture_io do
17
+ assert_raises(SystemExit) do
18
+ assert_cmd_gets('dump --format=json',
19
+ "/api/v2/#{api_path}?limit=999&offset=0")
20
+ end
21
+ Spy.teardown
22
+ end
23
+
24
+ assert_cannot_noop('dump --format=json')
25
+ assert_empty(err)
26
+ assert_equal([].to_s, out.rstrip)
27
+ end
28
+
29
+ def test_dump_yaml
30
+ out, err = capture_io do
31
+ assert_raises(SystemExit) do
32
+ assert_cmd_gets('dump --format=yaml',
33
+ "/api/v2/#{api_path}?limit=999&offset=0")
34
+ end
35
+ Spy.teardown
36
+ end
37
+
38
+ assert_cannot_noop('dump --format=yaml')
39
+ assert_empty(err)
40
+ assert_equal('--- []', out.rstrip)
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'delete'
4
+ require_relative 'deleteundelete'
5
+ require_relative 'describe'
6
+ require_relative 'dump'
7
+ require_relative 'history'
8
+ require_relative 'import'
9
+ require_relative 'list'
10
+ require_relative 'search'
11
+ require_relative 'set'
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WavefrontCliTest
4
+ #
5
+ # Include this module to get history and describe -v tests
6
+ #
7
+ module History
8
+ def test_describe_v
9
+ quietly do
10
+ assert_cmd_gets("describe -v 7 #{id}",
11
+ "/api/v2/#{api_path}/#{id}/history/7")
12
+ end
13
+
14
+ assert_noop("describe --version 10 #{id}",
15
+ 'uri: GET https://default.wavefront.com/api/v2/' \
16
+ "#{api_path}/#{id}/history/10")
17
+ assert_usage('describe -v 6')
18
+ assert_usage("describe -v #{id}")
19
+ assert_abort_on_missing_creds("describe -v 2 #{id}")
20
+ end
21
+
22
+ def test_history
23
+ assert_repeated_output('No data.') do
24
+ assert_cmd_gets("history #{id}",
25
+ "/api/v2/#{api_path}/#{id}/history")
26
+ end
27
+
28
+ assert_noop("history #{id}",
29
+ 'uri: GET https://default.wavefront.com/api/v2/' \
30
+ "#{api_path}/#{id}/history")
31
+ assert_usage('history')
32
+ assert_abort_on_missing_creds("history #{id}")
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WavefrontCliTest
4
+ #
5
+ # Mixin to test standard 'import' commands
6
+ #
7
+ module Import
8
+ def test_import
9
+ Spy.teardown
10
+
11
+ out, err = capture_io do
12
+ assert_raises(SystemExit) do
13
+ assert_cmd_posts("import #{import_file}",
14
+ "/api/v2/#{api_path}",
15
+ import_data)
16
+ Spy.teardown
17
+ end
18
+ end
19
+
20
+ assert_empty(err)
21
+ assert_equal('IMPORTED', out.strip)
22
+
23
+ assert_exits_with('File not found.', 'import /no/such/file')
24
+ assert_usage('import')
25
+ assert_abort_on_missing_creds("import #{import_file}")
26
+ end
27
+
28
+ def test_import_update
29
+ Spy.teardown
30
+
31
+ out, err = capture_io do
32
+ assert_raises(SystemExit) do
33
+ assert_cmd_puts("import -u #{update_file}",
34
+ "/api/v2/#{api_path}/1556812163465",
35
+ update_data)
36
+ Spy.teardown
37
+ end
38
+ end
39
+
40
+ assert_empty(err)
41
+ assert_equal('1556812163465 IMPORTED', out.strip)
42
+
43
+ assert_exits_with('File not found.', 'import /no/such/file')
44
+ assert_usage('import -u')
45
+ assert_abort_on_missing_creds("import -u #{import_file}")
46
+ end
47
+
48
+ def test_import_fields
49
+ x = cmd_instance.import_to_create(cmd_instance.load_file(import_file))
50
+ assert_instance_of(Hash, x)
51
+ import_fields.each { |f| assert_includes(x.keys, f) }
52
+ blocked_import_fields.each { |f| refute_includes(x.keys, f) }
53
+ end
54
+
55
+ private
56
+
57
+ def import_file
58
+ RES_DIR + 'imports' + "#{api_path}.json"
59
+ end
60
+
61
+ def update_file
62
+ RES_DIR + 'updates' + "#{api_path}.json"
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WavefrontCliTest
4
+ #
5
+ # Mixin to test standard 'list' commands
6
+ #
7
+ module List
8
+ def test_list
9
+ quietly do
10
+ assert_cmd_gets('list',
11
+ "/api/v2/#{api_path}?limit=100&offset=0")
12
+ assert_cmd_gets('list -o 5 --limit 10',
13
+ "/api/v2/#{api_path}?limit=10&offset=5")
14
+ assert_cmd_gets('list -L 50',
15
+ "/api/v2/#{api_path}?limit=50&offset=0")
16
+ assert_cmd_gets('list --offset 60',
17
+ "/api/v2/#{api_path}?limit=100&offset=60")
18
+ end
19
+
20
+ assert_noop(
21
+ 'list -o 5',
22
+ "uri: GET https://default.wavefront.com/api/v2/#{api_path}",
23
+ 'params: {:offset=>"5", :limit=>100}'
24
+ )
25
+
26
+ assert_abort_on_missing_creds('list')
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,98 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WavefrontCliTest
4
+ #
5
+ # Mixin to test standard 'search' commands
6
+ #
7
+ module Search
8
+ def test_search_equals
9
+ assert_repeated_output('No matches.') do
10
+ assert_cmd_posts("search id=#{id}",
11
+ "/api/v2/search/#{search_api_path}",
12
+ limit: 10,
13
+ offset: 0,
14
+ query: [{ key: 'id',
15
+ value: id,
16
+ matchingMethod: 'EXACT',
17
+ negated: false }],
18
+ sort: { field: 'id', ascending: true })
19
+ end
20
+
21
+ assert_noop(
22
+ "search id=#{id}",
23
+ 'uri: POST https://default.wavefront.com/api/v2/search/' \
24
+ "#{search_api_path}",
25
+ 'body: ' + { limit: 10,
26
+ offset: 0,
27
+ query: [{ key: 'id',
28
+ value: id,
29
+ matchingMethod: 'EXACT',
30
+ negated: false }],
31
+ sort: { field: 'id', ascending: true } }.to_json
32
+ )
33
+ assert_abort_on_missing_creds("search id=#{id}")
34
+ assert_usage('search')
35
+ end
36
+
37
+ def test_search_equals_with_limits
38
+ return if cannot_handle_offsets
39
+
40
+ assert_repeated_output('No matches.') do
41
+ assert_cmd_posts("search id=#{id} -L 5 --offset 15",
42
+ "/api/v2/search/#{search_api_path}",
43
+ limit: '5',
44
+ offset: '15',
45
+ query: [{ key: 'id',
46
+ value: id,
47
+ matchingMethod: 'EXACT',
48
+ negated: false }],
49
+ sort: { field: 'id', ascending: true })
50
+ end
51
+
52
+ assert_abort_on_missing_creds("search id=#{id} -L 5 --offset 15")
53
+ end
54
+
55
+ def test_search_does_not_begin_with
56
+ assert_repeated_output('No matches.') do
57
+ assert_cmd_posts("search id=#{id} thing!^word --all",
58
+ "/api/v2/search/#{search_api_path}",
59
+ limit: 999,
60
+ offset: 0,
61
+ query: [{ key: 'id',
62
+ value: id,
63
+ matchingMethod: 'EXACT',
64
+ negated: false },
65
+ { key: 'thing',
66
+ value: 'word',
67
+ matchingMethod: 'STARTSWITH',
68
+ negated: true }],
69
+ sort: { field: 'id', ascending: true })
70
+ end
71
+
72
+ assert_abort_on_missing_creds("search id=#{id} thing!^word --all")
73
+ end
74
+
75
+ def test_search_contains_with_limits
76
+ assert_repeated_output('No matches.') do
77
+ assert_cmd_posts('search id!~avoid -L 2',
78
+ "/api/v2/search/#{search_api_path}",
79
+ limit: '2',
80
+ offset: 0,
81
+ query: [{ key: 'id',
82
+ value: 'avoid',
83
+ matchingMethod: 'CONTAINS',
84
+ negated: true }],
85
+ sort: { field: 'id', ascending: true })
86
+ end
87
+
88
+ assert_abort_on_missing_creds('search id!~avoid -L 2')
89
+ end
90
+
91
+ def test_search_incorrect_usage
92
+ assert_exits_with(
93
+ 'Searches require a key, a value, and a match operator.',
94
+ 'search value -D'
95
+ )
96
+ end
97
+ end
98
+ end