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,35 +1,64 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- word = 'apitoken'
4
+ require_relative '../support/command_base'
5
+ require_relative '../../lib/wavefront-cli/apitoken'
4
6
 
5
- require_relative '../spec_helper'
6
- require_relative "../../lib/wavefront-cli/#{word}"
7
+ # Ensure 'apitoken' commands produce the correct API calls.
8
+ #
9
+ class ApiTokenEndToEndTest < EndToEndTest
10
+ include WavefrontCliTest::Delete
7
11
 
8
- id = '17db4cc1-65f6-40a8-a1fa-6fcae460c4bd'
9
- bad_id = 'bad_id'
12
+ def test_list
13
+ quietly { assert_cmd_gets('list', '/api/v2/apitoken') }
14
+ assert_usage('list --offset 4')
15
+ assert_abort_on_missing_creds('list')
10
16
 
11
- k = WavefrontCli::ApiToken
17
+ assert_noop('list',
18
+ 'uri: GET https://default.wavefront.com/api/v2/apitoken')
19
+ end
12
20
 
13
- describe "#{word} command" do
14
- missing_creds(word, ['list',
15
- 'create',
16
- "delete #{id}",
17
- "rename #{id} name"])
21
+ def test_create
22
+ quietly { assert_cmd_posts('create', '/api/v2/apitoken') }
23
+ assert_abort_on_missing_creds('create')
24
+ assert_noop('create',
25
+ 'uri: POST https://default.wavefront.com/api/v2/apitoken',
26
+ 'body: null')
27
+ end
18
28
 
19
- invalid_ids(word, ["delete #{bad_id}", "rename #{bad_id} name"])
29
+ def _test_rename
30
+ assert_cmd_puts("rename #{id} newname", "/api/v2/apitoken/#{id}",
31
+ tokenID: id, tokenName: 'newname')
32
+ assert_invalid_id("rename #{invalid_id} newname")
33
+ assert_abort_on_missing_creds("rename #{id} newname")
20
34
 
21
- cmd_to_call(word, 'list', { path: "/api/v2/#{word}" }, k)
35
+ assert_noop(
36
+ "rename #{id} newname",
37
+ "uri: PUT https://default.wavefront.com/api/v2/apitoken/#{id}",
38
+ 'body: {"tokenID":"17db4cc1-65f6-40a8-a1fa-6fcae460c4bd",' \
39
+ '"tokenName":"newname"}'
40
+ )
41
+ end
22
42
 
23
- cmd_noop(word, 'list',
24
- ["GET https://metrics.wavefront.com/api/v2/#{word}"], k)
25
- cmd_noop(word, 'create',
26
- ["POST https://metrics.wavefront.com/api/v2/#{word}"], k)
27
- cmd_noop(word, "delete #{id}",
28
- ["DELETE https://metrics.wavefront.com/api/v2/#{word}/#{id}"], k)
43
+ private
29
44
 
30
- cmd_to_call(word, "rename #{id} newname",
31
- { method: :put, path: "/api/v2/#{word}/#{id}",
32
- body: { tokenID: id,
33
- tokenName: 'newname' },
34
- headers: JSON_POST_HEADERS }, k)
45
+ def id
46
+ '17db4cc1-65f6-40a8-a1fa-6fcae460c4bd'
47
+ end
48
+
49
+ def invalid_id
50
+ '__BAD__'
51
+ end
52
+
53
+ def cmd_word
54
+ 'apitoken'
55
+ end
56
+
57
+ def sdk_class_name
58
+ 'ApiToken'
59
+ end
60
+
61
+ def friendly_name
62
+ 'api token'
63
+ end
35
64
  end
@@ -1,30 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require_relative '../spec_helper'
4
+ require 'minitest/autorun'
4
5
  require_relative '../../lib/wavefront-cli/alert'
5
- require 'spy'
6
- require 'spy/integration'
7
-
8
- OPTS = {
9
- endpoint: 'test.wavefront.com',
10
- token: '0123456789-ABCDEF',
11
- debug: false,
12
- noop: true
13
- }.freeze
14
-
15
- OPTS_CMD = {
16
- endpoint: 'test.wavefront.com',
17
- token: '0123456789-ABCDEF',
18
- debug: false,
19
- noop: true,
20
- test: true,
21
- cmd: true
22
- }.freeze
23
-
24
- DISP_DATA = {
25
- a: 'string',
26
- b: %w[list_1 list_2]
27
- }.freeze
6
+ require_relative '../../lib/wavefront-cli/version'
28
7
 
29
8
  # Since I tidied up the file layout in wavefront-sdk, there's no
30
9
  # longer a 1:1 mapping of CLI and SDK classes. wavefront-sdk/base is
@@ -37,13 +16,16 @@ class WavefrontCliBaseTest < MiniTest::Test
37
16
  attr_reader :wf, :wf_cmd
38
17
 
39
18
  def setup
40
- @wf = WavefrontCli::Alert.new(OPTS)
19
+ @wf = WavefrontCli::Alert.new(endpoint: 'test.wavefront.com',
20
+ token: '0123456789-ABCDEF',
21
+ debug: false,
22
+ noop: true)
41
23
  end
42
24
 
43
25
  def test_mk_creds
44
26
  assert_equal({ endpoint: 'test.wavefront.com',
45
- token: '0123456789-ABCDEF',
46
- agent: "wavefront-cli-#{WF_CLI_VERSION}" },
27
+ token: '0123456789-ABCDEF',
28
+ agent: "wavefront-cli-#{WF_CLI_VERSION}" },
47
29
  wf.mk_creds)
48
30
  end
49
31
 
@@ -1,34 +1,70 @@
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/cloudintegration'
5
6
 
6
- id = '3b56f61d-1a79-46f6-905c-d75a0f613d10'
7
- bad_id = '__BAD__'
8
- k = WavefrontCli::CloudIntegration
9
- word = 'cloudintegration'
10
-
11
- describe 'cloudintegration command' do
12
- missing_creds(word, ['list', "describe #{id}", "delete #{id}",
13
- "undelete #{id}"])
14
- list_tests(word, 'cloudintegration', k)
15
- noop_tests(word, id, false, 'cloudintegration', k)
16
- search_tests(word, id, k)
17
- cmd_to_call(word, "describe #{id}",
18
- { path: "/api/v2/cloudintegration/#{id}" }, k)
19
- cmd_to_call(word, "delete #{id}",
20
- { method: :delete, path: "/api/v2/cloudintegration/#{id}" }, k)
21
- cmd_to_call(word, "undelete #{id}",
22
- { method: :post,
23
- path: "/api/v2/cloudintegration/#{id}/undelete" }, k)
24
- cmd_to_call(word, "enable #{id}",
25
- { method: :post,
26
- path: "/api/v2/cloudintegration/#{id}/enable" }, k)
27
- cmd_to_call(word, "disable #{id}",
28
- { method: :post,
29
- path: "/api/v2/cloudintegration/#{id}/disable" }, k)
30
- invalid_ids(word, ["describe #{bad_id}", "delete #{bad_id}",
31
- "undelete #{bad_id}", "disable #{bad_id}",
32
- "enable #{bad_id}"])
33
- test_list_output(word, k)
7
+ # Ensure 'cloudintegration' commands produce the correct API calls.
8
+ #
9
+ class CloudIntegrationEndToEndTest < EndToEndTest
10
+ include WavefrontCliTest::DeleteUndelete
11
+ include WavefrontCliTest::Describe
12
+ include WavefrontCliTest::Dump
13
+ include WavefrontCliTest::List
14
+ # include WavefrontCliTest::Import
15
+ include WavefrontCliTest::Search
16
+
17
+ def test_enable
18
+ assert_repeated_output("Enabled '#{id}'.") do
19
+ assert_cmd_posts("enable #{id}",
20
+ "/api/v2/cloudintegration/#{id}/enable")
21
+ end
22
+
23
+ assert_invalid_id("enable #{invalid_id}")
24
+ assert_usage('enable')
25
+ assert_abort_on_missing_creds("enable #{id}")
26
+
27
+ assert_noop("enable #{id}",
28
+ 'uri: POST https://default.wavefront.com/api/v2/' \
29
+ "cloudintegration/#{id}/enable",
30
+ 'body: null')
31
+ end
32
+
33
+ def test_disable
34
+ assert_repeated_output("Disabled '#{id}'.") do
35
+ assert_cmd_posts("disable #{id}",
36
+ "/api/v2/cloudintegration/#{id}/disable")
37
+ end
38
+
39
+ assert_invalid_id("disable #{invalid_id}")
40
+ assert_usage('disable')
41
+ assert_abort_on_missing_creds("disable #{id}")
42
+
43
+ assert_noop("disable #{id}",
44
+ 'uri: POST https://default.wavefront.com/api/v2/' \
45
+ "cloudintegration/#{id}/disable",
46
+ 'body: null')
47
+ end
48
+
49
+ private
50
+
51
+ def id
52
+ '3b56f61d-1a79-46f6-905c-d75a0f613d10'
53
+ end
54
+
55
+ def invalid_id
56
+ '__BAD__'
57
+ end
58
+
59
+ def cmd_word
60
+ 'cloudintegration'
61
+ end
62
+
63
+ def sdk_class_name
64
+ 'CloudIntegration'
65
+ end
66
+
67
+ def friendly_name
68
+ 'cloud integration'
69
+ end
34
70
  end
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'pathname'
4
5
  require_relative(File.join('../../../lib/wavefront-cli/commands',
@@ -1,12 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'pathname'
4
- require_relative(File.join('../../../lib/wavefront-cli/commands',
5
- Pathname.new(__FILE__).basename
6
- .to_s.sub('_spec.rb', '')))
7
- require_relative 'spec_helper'
5
+ require 'minitest/autorun'
6
+ require_relative '../../constants'
7
+ require_relative '../../../lib/wavefront-cli/commands/base'
8
8
 
9
- # Test base class for commands
9
+ # Abstract class for testing commands
10
10
  #
11
11
  class WavefrontCommmandBaseTest < MiniTest::Test
12
12
  attr_reader :wf, :col_width, :skip_cmd
@@ -70,6 +70,7 @@ class WavefrontCommmandBaseTest < MiniTest::Test
70
70
 
71
71
  wf.commands(600).split("\n")[1..-1].each do |c|
72
72
  next if skip_cmd && c.match(skip_cmd)
73
+
73
74
  assert_match(/^ \w+/, c)
74
75
  assert_includes(c, CMN) unless c =~ /--help$/
75
76
  end
@@ -77,38 +78,39 @@ class WavefrontCommmandBaseTest < MiniTest::Test
77
78
 
78
79
  def test_options
79
80
  assert wf.options(600).start_with?("Global options:\n")
80
- assert_match(/\nOptions:\n/, wf.options)
81
+ assert_match(/\nOptions:/, wf.options)
81
82
 
82
83
  wf.options(600).split("\n")[1..-1].each do |o|
83
84
  next if o == 'Global options:' || o == 'Options:' || o.empty?
85
+
84
86
  assert_instance_of(String, o)
85
87
  assert_match(/^ -\w, --\w+/, o)
86
88
  refute o.end_with?('.')
87
89
  end
88
90
 
89
- assert_equal(wf.options.split("\n").select(&:empty?).size, 1)
91
+ assert_equal(1, wf.options.split("\n").select(&:empty?).size)
90
92
  end
91
93
 
92
94
  def test_opt_row
93
95
  assert_equal(wf.opt_row('-s, --short short option', 10),
94
- " -s, --short short option\n")
96
+ ' -s, --short short option')
95
97
  assert_equal(wf.opt_row('-s, --short short option', 8),
96
- " -s, --short short option\n")
98
+ ' -s, --short short option')
97
99
  assert_equal(wf.opt_row(
98
100
  '-l, --longoption a long option with a quite ' \
99
101
  'long description which needs folding', 15
100
- ),
102
+ ),
101
103
  ' -l, --longoption a long option with a quite long ' \
102
- "description which\n needs folding\n")
104
+ "description which\n needs folding")
103
105
  assert_equal(wf.opt_row(
104
106
  '-h, --hugeoption an option with a very long, far ' \
105
107
  'too verbose description which is going need folding ' \
106
108
  'more than one time, let me tell you', 12
107
- ),
109
+ ),
108
110
  ' -h, --hugeoption an option with a very long, far too ' \
109
111
  "verbose description\n which is going " \
110
112
  'need folding more than one time, let me tell' \
111
- "\n you\n")
113
+ "\n you")
112
114
  end
113
115
 
114
116
  def test_option_column_width
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require_relative('../../../lib/wavefront-cli/commands/cloudintegration')
4
5
  require_relative 'base_spec'
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'pathname'
4
5
  require_relative(File.join('../../../lib/wavefront-cli/commands',
@@ -21,6 +22,7 @@ class WavefrontCommmandConfigTest < WavefrontCommmandBaseTest
21
22
 
22
23
  wf.options(600).split("\n")[1..-1].each do |o|
23
24
  next if o == 'Global options:' || o == 'Options:' || o.empty?
25
+
24
26
  assert_instance_of(String, o)
25
27
  assert_match(/^ -\w, --\w+/, o)
26
28
  refute o.end_with?('.')
@@ -35,6 +37,7 @@ class WavefrontCommmandConfigTest < WavefrontCommmandBaseTest
35
37
 
36
38
  wf.commands(600).split("\n")[1..-1].each do |c|
37
39
  next if skip_cmd && c.match(skip_cmd)
40
+
38
41
  assert_match(/^ \w+/, c)
39
42
  end
40
43
  end
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'pathname'
4
5
  require_relative(File.join('../../../lib/wavefront-cli/commands',
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'pathname'
4
5
  require_relative(File.join('../../../lib/wavefront-cli/commands',
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'pathname'
4
5
  require_relative(File.join('../../../lib/wavefront-cli/commands',
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require_relative('../../../lib/wavefront-cli/commands/link')
4
5
  require_relative 'base_spec'
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'pathname'
4
5
  require_relative(File.join('../../../lib/wavefront-cli/commands',
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'pathname'
4
5
  require_relative(File.join('../../../lib/wavefront-cli/commands',
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'pathname'
4
5
  require_relative(File.join('../../../lib/wavefront-cli/commands',
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'pathname'
4
5
  require_relative(File.join('../../../lib/wavefront-cli/commands',
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'pathname'
4
5
  require_relative(File.join('../../../lib/wavefront-cli/commands',
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require_relative('../../../lib/wavefront-cli/commands/window')
4
5
  require_relative 'base_spec'
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'pathname'
4
5
  require_relative(File.join('../../../lib/wavefront-cli/commands',
@@ -1,12 +1,15 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require_relative '../spec_helper'
4
+ require 'pathname'
5
+ require 'minitest/autorun'
6
+ require_relative '../constants'
4
7
  require_relative '../../lib/wavefront-cli/config'
5
8
 
6
9
  DEF_CF = Pathname.new(ENV['HOME']) + '.wavefront'
7
10
  CONF_TMP = Pathname.new('/tmp/outfile')
8
11
 
9
- # Test base writer
12
+ # Test CLI configuration command
10
13
  #
11
14
  class WavefrontCliConfigTest < MiniTest::Test
12
15
  attr_reader :wf, :wfo, :wfn
@@ -18,9 +21,9 @@ class WavefrontCliConfigTest < MiniTest::Test
18
21
  end
19
22
 
20
23
  def test_do_location
21
- assert_output(format("%s\n", CF)) { wfo.do_location }
24
+ assert_output(format("%<file>s\n", file: CF)) { wfo.do_location }
22
25
  assert_output("/no/file\n") { wfn.do_location }
23
- assert_output(format("%s\n", DEF_CF)) { wf.do_location }
26
+ assert_output(format("%<file>s\n", file: DEF_CF)) { wf.do_location }
24
27
  end
25
28
 
26
29
  def test_do_profiles
@@ -45,15 +48,23 @@ class WavefrontCliConfigTest < MiniTest::Test
45
48
 
46
49
  def test_read_input
47
50
  ["value \n", " value\n", " value \t\n", "value\n"].each do |v|
48
- STDIN.stub(:gets, v) do
49
- assert_equal('value', wf.read_input)
50
- end
51
+ STDIN.stub(:gets, v) { assert_equal('value', wf.read_input) }
51
52
  end
52
53
  end
53
54
 
54
55
  def test_base_config
55
- assert_instance_of(IniFile, wfo.base_config)
56
- assert_instance_of(IniFile, wf.base_config)
56
+ out, err = capture_io { assert_instance_of(IniFile, wf.base_config) }
57
+ assert_empty(err)
58
+
59
+ if (Pathname.new(ENV['HOME']) + '.wavefront').exist?
60
+ assert_empty(out)
61
+ else
62
+ assert_match(/Creating new configuration file at/, out)
63
+ end
64
+
65
+ out, err = capture_io { assert_instance_of(IniFile, wfo.base_config) }
66
+ assert_empty(err)
67
+ assert_empty(out)
57
68
 
58
69
  assert_output('') { wfo.base_config }
59
70
  assert_output("Creating new configuration file at /no/file.\n") do
@@ -98,12 +109,12 @@ class WavefrontCliConfigTest < MiniTest::Test
98
109
  assert_equal('json', x[:prof]['format'])
99
110
  end
100
111
 
112
+ assert_empty(err)
101
113
  assert_match(/Creating profile 'prof'./, out)
102
114
  assert_match(/Wavefront API token/, out)
103
115
  assert_match(/Wavefront API endpoint/, out)
104
116
  assert_match(/Wavefront proxy endpoint/, out)
105
117
  assert_match(/default output format/, out)
106
- assert_empty(err)
107
118
  end
108
119
 
109
120
  def test_create_profile_2
@@ -122,12 +133,12 @@ class WavefrontCliConfigTest < MiniTest::Test
122
133
  assert_equal('human', x[:prof]['format'])
123
134
  end
124
135
 
136
+ assert_empty(err)
125
137
  assert_match(/Creating profile 'prof'./, out)
126
138
  assert_match(/Wavefront API token/, out)
127
139
  assert_match(/Wavefront API endpoint/, out)
128
140
  assert_match(/Wavefront proxy endpoint/, out)
129
141
  assert_match(/default output format/, out)
130
- assert_empty(err)
131
142
  end
132
143
 
133
144
  def test_create_profile_3
@@ -141,9 +152,9 @@ class WavefrontCliConfigTest < MiniTest::Test
141
152
  end
142
153
  end
143
154
 
155
+ assert_empty(err)
144
156
  assert_match(/Creating profile 'prof'./, out)
145
157
  assert_match(/Wavefront API token/, out)
146
- assert_empty(err)
147
158
  end
148
159
 
149
160
  def test_create_profile_4
@@ -157,9 +168,9 @@ class WavefrontCliConfigTest < MiniTest::Test
157
168
  end
158
169
  end
159
170
 
171
+ assert_empty(err)
160
172
  assert_match(/Creating profile 'prof'./, out)
161
173
  assert_match(/Wavefront API token/, out)
162
- assert_empty(err)
163
174
  end
164
175
 
165
176
  def test_create_profile_5
@@ -173,9 +184,9 @@ class WavefrontCliConfigTest < MiniTest::Test
173
184
  end
174
185
  end
175
186
 
187
+ assert_empty(err)
176
188
  assert_match(/Creating profile 'prof'./, out)
177
189
  assert_match(/Wavefront API token/, out)
178
- assert_empty(err)
179
190
  end
180
191
 
181
192
  def test_do_setup; end