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,45 +1,143 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- id = 'tester'
4
- bad_id = '%%badid%%'
5
- word = 'integration'
4
+ require_relative '../support/command_base'
5
+ require_relative '../../lib/wavefront-cli/integration'
6
6
 
7
- require_relative '../spec_helper'
8
- require_relative "../../lib/wavefront-cli/#{word}"
7
+ # Ensure 'integration' commands produce the correct API calls.
8
+ #
9
+ class IntegrationEndToEndTest < EndToEndTest
10
+ include WavefrontCliTest::List
11
+ include WavefrontCliTest::Describe
12
+ include WavefrontCliTest::Search
9
13
 
10
- describe "#{word} command" do
11
- missing_creds(word, ['list', "describe #{id}", "install #{id}",
12
- "uninstall #{id}", "status #{id}", 'statuses',
13
- 'manifests'])
14
- list_tests(word)
15
- noop_tests(word, id, :skip, 'integration')
16
- cmd_to_call(word, "status #{id}", path: "/api/v2/#{word}/#{id}/status")
14
+ def test_install
15
+ quietly do
16
+ assert_cmd_posts("install #{id}",
17
+ "/api/v2/integration/#{id}/install",
18
+ 'null')
19
+ end
17
20
 
18
- cmd_to_call(word, "install #{id}",
19
- method: :post, path: "/api/v2/#{word}/#{id}/install")
21
+ assert_invalid_id("install #{invalid_id}")
22
+ assert_usage('install')
23
+ assert_abort_on_missing_creds("install #{id}")
20
24
 
21
- cmd_to_call(word, "uninstall #{id}",
22
- method: :post, path: "/api/v2/#{word}/#{id}/uninstall")
25
+ assert_noop("install #{id}",
26
+ 'uri: POST https://default.wavefront.com/api/v2/' \
27
+ "integration/#{id}/install",
28
+ 'body: null')
29
+ end
23
30
 
24
- cmd_to_call(word, "alert install #{id}",
25
- method: :post,
26
- path: "/api/v2/#{word}/#{id}/install-all-alerts")
31
+ def test_uninstall
32
+ quietly do
33
+ assert_cmd_posts("uninstall #{id}",
34
+ "/api/v2/integration/#{id}/uninstall",
35
+ 'null')
36
+ end
27
37
 
28
- cmd_to_call(word, "alert uninstall #{id}",
29
- method: :post,
30
- path: "/api/v2/#{word}/#{id}/uninstall-all-alerts")
38
+ assert_invalid_id("uninstall #{invalid_id}")
39
+ assert_usage('uninstall')
40
+ assert_abort_on_missing_creds("uninstall #{id}")
31
41
 
32
- cmd_to_call(word, "describe #{id}", path: "/api/v2/#{word}/#{id}")
42
+ assert_noop("uninstall #{id}",
43
+ 'uri: POST https://default.wavefront.com/api/v2/' \
44
+ "integration/#{id}/uninstall",
45
+ 'body: null')
46
+ end
33
47
 
34
- cmd_to_call(word, "status #{id}", path: "/api/v2/#{word}/#{id}/status")
48
+ def test_manifests
49
+ assert_exits_with('Human-readable manifest output is not supported.',
50
+ 'manifests -f human')
35
51
 
36
- cmd_to_call(word, 'installed', path: "/api/v2/#{word}/installed")
52
+ quietly do
53
+ assert_cmd_gets('manifests -f json', '/api/v2/integration/manifests')
54
+ end
37
55
 
38
- cmd_to_call(word, 'manifests -f json', path: "/api/v2/#{word}/manifests")
56
+ assert_noop('manifests --format yaml',
57
+ 'uri: GET https://default.wavefront.com/api/v2/' \
58
+ 'integration/manifests')
59
+ assert_abort_on_missing_creds('manifests')
60
+ end
39
61
 
40
- invalid_ids(word, ["describe #{bad_id}", "install #{bad_id}",
41
- "alert install #{bad_id}",
42
- "alert uninstall #{bad_id}",
43
- "uninstall #{bad_id}", "status #{bad_id}"])
44
- test_list_output(word)
62
+ def test_status
63
+ quietly do
64
+ assert_cmd_gets("status #{id}", "/api/v2/integration/#{id}/status")
65
+ end
66
+
67
+ assert_invalid_id("status #{invalid_id}")
68
+ assert_noop("status #{id}",
69
+ 'uri: GET https://default.wavefront.com/api/v2/' \
70
+ "integration/#{id}/status")
71
+ assert_abort_on_missing_creds("status #{id}")
72
+ end
73
+
74
+ def test_statuses
75
+ quietly do
76
+ assert_cmd_gets('statuses', '/api/v2/integration/status')
77
+ end
78
+
79
+ assert_noop('statuses',
80
+ 'uri: GET https://default.wavefront.com/api/v2/' \
81
+ 'integration/status')
82
+ assert_abort_on_missing_creds('statuses')
83
+ end
84
+
85
+ def test_alert_install
86
+ quietly do
87
+ assert_cmd_posts("alert install #{id}",
88
+ "/api/v2/integration/#{id}/install-all-alerts",
89
+ 'null')
90
+ end
91
+
92
+ assert_invalid_id("alert install #{invalid_id}")
93
+ assert_usage('alert install')
94
+ assert_abort_on_missing_creds("alert install #{id}")
95
+
96
+ assert_noop("alert install #{id}",
97
+ 'uri: POST https://default.wavefront.com/api/v2/' \
98
+ "integration/#{id}/install-all-alerts",
99
+ 'body: null')
100
+ end
101
+
102
+ def test_alert_uninstall
103
+ quietly do
104
+ assert_cmd_posts("alert uninstall #{id}",
105
+ "/api/v2/integration/#{id}/uninstall-all-alerts",
106
+ 'null')
107
+ end
108
+
109
+ assert_invalid_id("alert uninstall #{invalid_id}")
110
+ assert_usage('alert uninstall')
111
+ assert_abort_on_missing_creds("alert uninstall #{id}")
112
+
113
+ assert_noop("alert uninstall #{id}",
114
+ 'uri: POST https://default.wavefront.com/api/v2/' \
115
+ "integration/#{id}/uninstall-all-alerts",
116
+ 'body: null')
117
+ end
118
+
119
+ def test_installed
120
+ quietly do
121
+ assert_cmd_gets('installed', '/api/v2/integration/installed')
122
+ end
123
+
124
+ assert_noop('installed',
125
+ 'uri: GET https://default.wavefront.com/api/v2/' \
126
+ 'integration/installed')
127
+ assert_abort_on_missing_creds('installed')
128
+ end
129
+
130
+ private
131
+
132
+ def id
133
+ 'tester'
134
+ end
135
+
136
+ def invalid_id
137
+ '%%badid%%'
138
+ end
139
+
140
+ def cmd_word
141
+ 'integration'
142
+ end
45
143
  end
@@ -1,41 +1,279 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require_relative '../spec_helper'
4
+ require_relative '../support/command_base'
4
5
  require_relative '../../lib/wavefront-cli/maintenancewindow'
5
6
 
6
- id = '1493324005091'
7
- bad_id = '__BAD__'
8
- k = WavefrontCli::MaintenanceWindow
9
- word = 'window'
10
-
11
- describe "#{word} command" do
12
- missing_creds(word, ['list', "describe #{id}", "delete #{id}"])
13
- list_tests(word, 'maintenancewindow', k)
14
- noop_tests(word, id, false, 'maintenancewindow', k)
15
- search_tests(word, id, k, 'maintenancewindow')
16
- cmd_to_call(word, "describe #{id}",
17
- { path: "/api/v2/maintenancewindow/#{id}" }, k)
18
- cmd_to_call(word, "delete #{id}",
19
- { method: :delete, path: "/api/v2/maintenancewindow/#{id}" }, k)
20
- invalid_ids(word, ["describe #{bad_id}", "delete #{bad_id}"])
21
- cmd_to_call(word, 'create -d testing -H shark tester',
22
- { method: :post, path: '/api/v2/maintenancewindow',
23
- body: {
24
- },
25
- headers: JSON_POST_HEADERS },
26
- WavefrontCli::MaintenanceWindow)
27
- test_list_output(word, k)
28
- end
7
+ # Ensure 'window' commands produce the correct API calls.
8
+ #
9
+ class MaintenanceWindowEndToEndTest < EndToEndTest
10
+ include WavefrontCliTest::List
11
+ include WavefrontCliTest::Describe
12
+ include WavefrontCliTest::Dump
13
+ include WavefrontCliTest::Delete
14
+ # include WavefrontCliTest::Import
15
+ include WavefrontCliTest::Set
16
+ include WavefrontCliTest::Search
17
+
18
+ def test_create
19
+ quietly do
20
+ assert_cmd_posts('create -d testing --host shark test_window',
21
+ '/api/v2/maintenancewindow',
22
+ endTimeInSeconds: a_timestamp,
23
+ reason: 'testing',
24
+ relevantHostNames: %w[shark],
25
+ startTimeInSeconds: a_timestamp,
26
+ title: 'test_window')
27
+ end
28
+
29
+ assert_abort_on_missing_creds('create -d testing -H box test_window')
30
+ assert_usage('create test_window')
31
+ end
32
+
33
+ def test_create_with_boundaries
34
+ quietly do
35
+ assert_cmd_posts('create --desc testing -H shark -s 1566776337 ' \
36
+ '-H box -e 1566776399 test_window',
37
+ '/api/v2/maintenancewindow',
38
+ endTimeInSeconds: 1_566_776_399,
39
+ reason: 'testing',
40
+ relevantHostNames: %w[shark box],
41
+ startTimeInSeconds: 1_566_776_337,
42
+ title: 'test_window')
43
+ end
44
+
45
+ assert_noop(
46
+ 'create --desc testing -H shark -s 1566776337 -H box ' \
47
+ '-e 1566776399 test_window',
48
+ '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
54
+ )
55
+ end
56
+
57
+ def test_create_with_boundaries_and_tags
58
+ quietly do
59
+ assert_cmd_posts('create -d testing -A alert_tag_1 -A alert_tag_2 ' \
60
+ '--start 1566776337 --end 1566776399 test_window',
61
+ '/api/v2/maintenancewindow',
62
+ endTimeInSeconds: 1_566_776_399,
63
+ reason: 'testing',
64
+ relevantCustomerTags: %w[alert_tag_1 alert_tag_2],
65
+ startTimeInSeconds: 1_566_776_337,
66
+ title: 'test_window')
67
+ end
68
+ end
69
+
70
+ def test_close
71
+ quietly do
72
+ all_permutations do |p|
73
+ get_stub = stub_request(
74
+ :get,
75
+ "https://#{p[:endpoint]}/api/v2/maintenancewindow/#{id}"
76
+ ).to_return(body: canned_response.to_json, status: 200)
77
+
78
+ put_stub = stub_request(
79
+ :put,
80
+ "https://#{p[:endpoint]}/api/v2/maintenancewindow/#{id}"
81
+ ).with(body: { id: '1538845632142',
82
+ reason: 'CLI testing',
83
+ relevantCustomerTags: [],
84
+ relevantHostTags: ['physical'],
85
+ startTimeInSeconds: 1_538_812_800,
86
+ endTimeInSeconds: a_timestamp,
87
+ title: 'test_2' })
88
+ .to_return(body: dummy_response, status: 200)
89
+
90
+ wf.new("window close #{id} #{p[:cmdline]}".split)
91
+
92
+ assert_requested(get_stub)
93
+ assert_requested(put_stub)
94
+ end
95
+ end
96
+
97
+ assert_cannot_noop("close #{id}")
98
+ assert_abort_on_missing_creds("close #{id}")
99
+ assert_usage('close')
100
+ end
101
+
102
+ def test_extend_to
103
+ quietly do
104
+ all_permutations do |p|
105
+ get_stub = stub_request(
106
+ :get,
107
+ "https://#{p[:endpoint]}/api/v2/maintenancewindow/#{id}"
108
+ ).to_return(body: canned_response.to_json, status: 200)
109
+
110
+ put_stub = stub_request(
111
+ :put,
112
+ "https://#{p[:endpoint]}/api/v2/maintenancewindow/#{id}"
113
+ ).with(body: { id: '1538845632142',
114
+ reason: 'CLI testing',
115
+ relevantCustomerTags: [],
116
+ relevantHostTags: ['physical'],
117
+ startTimeInSeconds: 1_538_812_800,
118
+ endTimeInSeconds: 1_566_781_528,
119
+ title: 'test_2' })
120
+ .to_return(body: dummy_response, status: 200)
121
+
122
+ wf.new("window extend to 1566781528 #{id} #{p[:cmdline]}".split)
123
+
124
+ assert_requested(get_stub)
125
+ assert_requested(put_stub)
126
+ end
127
+ end
128
+
129
+ assert_cannot_noop("extend to 2:00 #{id}")
130
+ assert_usage("extend #{id} to 2:00")
131
+ assert_usage('extend')
132
+ end
133
+
134
+ def test_extend_by
135
+ quietly do
136
+ all_permutations do |p|
137
+ get_stub = stub_request(
138
+ :get,
139
+ "https://#{p[:endpoint]}/api/v2/maintenancewindow/#{id}"
140
+ ).to_return(body: canned_response.to_json, status: 200)
141
+
142
+ put_stub = stub_request(
143
+ :put,
144
+ "https://#{p[:endpoint]}/api/v2/maintenancewindow/#{id}"
145
+ ).with(body: { id: '1538845632142',
146
+ reason: 'CLI testing',
147
+ relevantCustomerTags: [],
148
+ relevantHostTags: ['physical'],
149
+ startTimeInSeconds: 1_538_812_800,
150
+ endTimeInSeconds: a_timestamp,
151
+ title: 'test_2' })
152
+ .to_return(body: dummy_response, status: 200)
153
+
154
+ wf.new("window extend by 1h #{id} #{p[:cmdline]}".split)
155
+
156
+ assert_requested(get_stub, times: 2)
157
+ assert_requested(put_stub)
158
+ end
159
+ end
160
+
161
+ assert_cannot_noop("extend by 1h #{id}")
162
+ assert_usage("extend 1h #{id}")
163
+ assert_usage("extend by an hour #{id}")
164
+ end
165
+
166
+ def test_ongoing
167
+ out, err = capture_io do
168
+ assert_raises(SystemExit) do
169
+ assert_cmd_posts('ongoing',
170
+ '/api/v2/search/maintenancewindow',
171
+ state_search('ongoing').to_json)
172
+ end
173
+ end
174
+
175
+ assert_noop(
176
+ 'ongoing',
177
+ '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
185
+ )
186
+
187
+ assert_empty(err)
188
+ assert_equal('No maintenance windows currently ongoing.', out.strip)
189
+ assert_abort_on_missing_creds('ongoing')
190
+ end
191
+
192
+ def test_pending
193
+ out, err = capture_io do
194
+ assert_raises(SystemExit) do
195
+ assert_cmd_posts('pending',
196
+ '/api/v2/search/maintenancewindow',
197
+ state_search('pending').to_json)
198
+ end
199
+ end
200
+
201
+ assert_noop(
202
+ 'pending',
203
+ '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
211
+ )
212
+
213
+ assert_empty(err)
214
+ assert_equal('No maintenance windows in the next 24 hours.', out.strip)
215
+ assert_abort_on_missing_creds('pending')
216
+ end
217
+
218
+ private
219
+
220
+ def id
221
+ '1493324005091'
222
+ end
223
+
224
+ def invalid_id
225
+ '__BAD__'
226
+ end
227
+
228
+ def cmd_word
229
+ 'window'
230
+ end
231
+
232
+ def api_path
233
+ 'maintenancewindow'
234
+ end
235
+
236
+ def sdk_class_name
237
+ 'MaintenanceWindow'
238
+ end
239
+
240
+ def friendly_name
241
+ 'maintenance window'
242
+ end
243
+
244
+ def set_key
245
+ 'title'
246
+ end
247
+
248
+ def import_fields
249
+ %i[startTimeInSeconds endTimeInSeconds relevantCustomerTags
250
+ title relevantHostTags]
251
+ end
29
252
 
30
- class TestMaintenanceWindowMethods < CliMethodTest
31
- def cliclass
32
- WavefrontCli::MaintenanceWindow
253
+ def canned_response
254
+ { id: '1538845632142',
255
+ reason: 'CLI testing',
256
+ customerId: 'sysdef',
257
+ relevantCustomerTags: [],
258
+ title: 'test_2',
259
+ startTimeInSeconds: 1_538_812_800,
260
+ endTimeInSeconds: 1_566_780_739,
261
+ relevantHostTags: ['physical'],
262
+ creatorId: 'rob@sysdef.xyz',
263
+ updaterId: 'rob@sysdef.xyz',
264
+ createdEpochMillis: 1_538_845_632_142,
265
+ updatedEpochMillis: 1_566_780_740_722,
266
+ eventName: 'Maintenance Window: test_2',
267
+ runningState: 'ENDED',
268
+ sortAttr: 1_000_000 }
33
269
  end
34
270
 
35
- def test_import_method
36
- import_tester(:window,
37
- %i[startTimeInSeconds endTimeInSeconds
38
- relevantCustomerTags title relevantHostTags],
39
- %i[id])
271
+ def state_search(state)
272
+ { limit: 999,
273
+ offset: 0,
274
+ query: [{ key: 'runningState',
275
+ value: state,
276
+ matchingMethod: 'EXACT' }],
277
+ sort: { field: 'runningState', ascending: true } }
40
278
  end
41
279
  end