wavefront-cli 2.1.4 → 2.1.5
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.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.rubocop.yml +1147 -0
- data/README.md +1 -1
- data/lib/wavefront-cli/alert.rb +2 -3
- data/lib/wavefront-cli/base.rb +27 -20
- data/lib/wavefront-cli/commands/alert.rb +0 -1
- data/lib/wavefront-cli/commands/event.rb +3 -2
- data/lib/wavefront-cli/commands/query.rb +0 -1
- data/lib/wavefront-cli/commands/window.rb +0 -1
- data/lib/wavefront-cli/commands/write.rb +0 -1
- data/lib/wavefront-cli/constants.rb +0 -1
- data/lib/wavefront-cli/controller.rb +5 -5
- data/lib/wavefront-cli/display/alert.rb +3 -5
- data/lib/wavefront-cli/display/dashboard.rb +3 -3
- data/lib/wavefront-cli/display/webhook.rb +2 -2
- data/lib/wavefront-cli/display/write.rb +1 -1
- data/lib/wavefront-cli/event.rb +67 -53
- data/lib/wavefront-cli/integration.rb +0 -1
- data/lib/wavefront-cli/maintenancewindow.rb +36 -20
- data/lib/wavefront-cli/opt_handler.rb +1 -1
- data/lib/wavefront-cli/query.rb +44 -27
- data/lib/wavefront-cli/string.rb +13 -25
- data/lib/wavefront-cli/version.rb +1 -1
- data/lib/wavefront-cli/write.rb +2 -7
- data/spec/.rubocop.yml +16 -0
- data/spec/spec_helper.rb +55 -55
- data/spec/wavefront-cli/alert_spec.rb +8 -8
- data/spec/wavefront-cli/base_spec.rb +1 -1
- data/spec/wavefront-cli/cloudintegration_spec.rb +6 -6
- data/spec/wavefront-cli/commands/base_spec.rb +0 -2
- data/spec/wavefront-cli/controller_spec.rb +5 -5
- data/spec/wavefront-cli/dashboard_spec.rb +8 -8
- data/spec/wavefront-cli/display/base_spec.rb +22 -23
- data/spec/wavefront-cli/display/printer/long_spec.rb +30 -28
- data/spec/wavefront-cli/event_spec.rb +8 -8
- data/spec/wavefront-cli/externallink_spec.rb +6 -6
- data/spec/wavefront-cli/maintanancewindow_spec.rb +8 -9
- data/spec/wavefront-cli/opt_handler_spec.rb +4 -5
- data/spec/wavefront-cli/proxy_spec.rb +8 -8
- data/spec/wavefront-cli/savedsearch_spec.rb +6 -6
- data/spec/wavefront-cli/source_spec.rb +8 -8
- data/spec/wavefront-cli/string_spec.rb +2 -3
- data/spec/wavefront-cli/webhook_spec.rb +8 -8
- data/wavefront-cli.gemspec +3 -3
- metadata +20 -5
    
        data/lib/wavefront-cli/query.rb
    CHANGED
    
    | @@ -9,37 +9,54 @@ module WavefrontCli | |
| 9 9 | 
             
                include Wavefront::Mixins
         | 
| 10 10 |  | 
| 11 11 | 
             
                def do_default
         | 
| 12 | 
            -
                   | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 16 | 
            -
                    listMode:               true,
         | 
| 17 | 
            -
                    strict:                 true,
         | 
| 18 | 
            -
                    includeObsoleteMetrics: options[:obsolete],
         | 
| 19 | 
            -
                    sorted:                 true
         | 
| 20 | 
            -
                  }
         | 
| 12 | 
            +
                  t_start     = window_start
         | 
| 13 | 
            +
                  t_end       = window_end
         | 
| 14 | 
            +
                  granularity = granularity(t_start, t_end)
         | 
| 15 | 
            +
                  t_end       = nil unless options[:end]
         | 
| 21 16 |  | 
| 22 | 
            -
                  options[: | 
| 23 | 
            -
             | 
| 24 | 
            -
                                    else
         | 
| 25 | 
            -
                                      (Time.now - 600).to_i
         | 
| 26 | 
            -
                                    end
         | 
| 17 | 
            +
                  wf.query(options[:'<query>'], granularity, t_start, t_end, q_opts)
         | 
| 18 | 
            +
                end
         | 
| 27 19 |  | 
| 28 | 
            -
             | 
| 29 | 
            -
             | 
| 30 | 
            -
             | 
| 20 | 
            +
                # @return [Hash] options for the SDK query method
         | 
| 21 | 
            +
                #
         | 
| 22 | 
            +
                def q_opts
         | 
| 23 | 
            +
                  ret = { autoEvents:             options[:events],
         | 
| 24 | 
            +
                          i:                      options[:inclusive],
         | 
| 25 | 
            +
                          summarization:          options[:summarize] || 'mean',
         | 
| 26 | 
            +
                          listMode:               true,
         | 
| 27 | 
            +
                          strict:                 true,
         | 
| 28 | 
            +
                          includeObsoleteMetrics: options[:obsolete],
         | 
| 29 | 
            +
                          sorted:                 true }
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                  ret[:n] = options[:name] if options[:name]
         | 
| 32 | 
            +
                  ret[:p] = options[:points] if options[:points]
         | 
| 33 | 
            +
                  ret
         | 
| 34 | 
            +
                end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                # @return [Integer] start of query window. If one has been
         | 
| 37 | 
            +
                #   given, that; if not, ten minutes ago
         | 
| 38 | 
            +
                #
         | 
| 39 | 
            +
                def window_start
         | 
| 40 | 
            +
                  if options[:start]
         | 
| 41 | 
            +
                    parse_time(options[:start], true)
         | 
| 31 42 | 
             
                  else
         | 
| 32 | 
            -
                     | 
| 43 | 
            +
                    (Time.now - 600).to_i
         | 
| 33 44 | 
             
                  end
         | 
| 45 | 
            +
                end
         | 
| 34 46 |  | 
| 35 | 
            -
             | 
| 36 | 
            -
             | 
| 37 | 
            -
             | 
| 38 | 
            -
             | 
| 39 | 
            -
                   | 
| 47 | 
            +
                # @return [Integer] end of query window. If one has been
         | 
| 48 | 
            +
                #   given, that; if not, now
         | 
| 49 | 
            +
                #
         | 
| 50 | 
            +
                def window_end
         | 
| 51 | 
            +
                  if options[:end]
         | 
| 52 | 
            +
                    parse_time(options[:end], true)
         | 
| 53 | 
            +
                  else
         | 
| 54 | 
            +
                    Time.now.to_i
         | 
| 55 | 
            +
                  end
         | 
| 56 | 
            +
                end
         | 
| 40 57 |  | 
| 41 | 
            -
             | 
| 42 | 
            -
             | 
| 58 | 
            +
                def granularity(t_start, t_end)
         | 
| 59 | 
            +
                  options[:granularity] || default_granularity(t_start - t_end)
         | 
| 43 60 | 
             
                end
         | 
| 44 61 |  | 
| 45 62 | 
             
                # Work out a sensible granularity based on the time window
         | 
| @@ -47,9 +64,9 @@ module WavefrontCli | |
| 47 64 | 
             
                def default_granularity(window)
         | 
| 48 65 | 
             
                  if window < 300
         | 
| 49 66 | 
             
                    :s
         | 
| 50 | 
            -
                  elsif window <  | 
| 67 | 
            +
                  elsif window < 10_800
         | 
| 51 68 | 
             
                    :m
         | 
| 52 | 
            -
                  elsif window <  | 
| 69 | 
            +
                  elsif window < 259_200
         | 
| 53 70 | 
             
                    :h
         | 
| 54 71 | 
             
                  else
         | 
| 55 72 | 
             
                    :d
         | 
    
        data/lib/wavefront-cli/string.rb
    CHANGED
    
    | @@ -8,9 +8,8 @@ class String | |
| 8 8 | 
             
              # @param indent [Integer] size of hanging indent, in chars
         | 
| 9 9 | 
             
              #
         | 
| 10 10 | 
             
              def cmd_fold(tw = TW, indent = 10)
         | 
| 11 | 
            -
                 | 
| 12 | 
            -
             | 
| 13 | 
            -
                  .tr('^', ' ')
         | 
| 11 | 
            +
                gsub(/(-\w) /, '\\1^').scan_line(tw - 12).join("\n" + ' ' * indent)
         | 
| 12 | 
            +
                                      .tr('^', ' ')
         | 
| 14 13 | 
             
              end
         | 
| 15 14 |  | 
| 16 15 | 
             
              # Wrapper around #fold()
         | 
| @@ -27,7 +26,6 @@ class String | |
| 27 26 | 
             
              # for option folding, now addded the prefix parameter to make it
         | 
| 28 27 | 
             
              # more general.
         | 
| 29 28 | 
             
              #
         | 
| 30 | 
            -
              # rubocop:disable Metrics/AbcSize
         | 
| 31 29 | 
             
              #
         | 
| 32 30 | 
             
              # @param tw [Integer] terminal width
         | 
| 33 31 | 
             
              # @param indent [Integer] size of hanging indent, in chars
         | 
| @@ -35,17 +33,17 @@ class String | |
| 35 33 | 
             
              # @return [String] the folded line
         | 
| 36 34 | 
             
              #
         | 
| 37 35 | 
             
              def fold(tw = TW, indent = 10, prefix = '')
         | 
| 38 | 
            -
                chunks =  | 
| 36 | 
            +
                chunks = scan_line(tw - 8)
         | 
| 39 37 |  | 
| 40 | 
            -
                 | 
| 38 | 
            +
                first_line = format("%s%s\n", prefix, chunks.shift)
         | 
| 41 39 |  | 
| 42 | 
            -
                return  | 
| 40 | 
            +
                return first_line if chunks.empty?
         | 
| 43 41 |  | 
| 44 42 | 
             
                rest = chunks.join(' ').scan_line(tw - indent - 5).map do |l|
         | 
| 45 43 | 
             
                  prefix + ' ' * indent + l
         | 
| 46 44 | 
             
                end
         | 
| 47 45 |  | 
| 48 | 
            -
                 | 
| 46 | 
            +
                first_line + rest.join("\n") + "\n"
         | 
| 49 47 | 
             
              end
         | 
| 50 48 |  | 
| 51 49 | 
             
              # @param width [Integer] length of longest string (width of
         | 
| @@ -59,26 +57,16 @@ class String | |
| 59 57 |  | 
| 60 58 | 
             
              def to_seconds
         | 
| 61 59 | 
             
                begin
         | 
| 62 | 
            -
                  number, unit =  | 
| 63 | 
            -
                rescue
         | 
| 60 | 
            +
                  number, unit = match(/^(\d+)([smhdw])$/).captures
         | 
| 61 | 
            +
                rescue NoMethodError
         | 
| 64 62 | 
             
                  raise ArgumentError
         | 
| 65 63 | 
             
                end
         | 
| 66 64 |  | 
| 67 | 
            -
                 | 
| 68 | 
            -
             | 
| 69 | 
            -
                           1
         | 
| 70 | 
            -
                         when 'm'
         | 
| 71 | 
            -
                           60
         | 
| 72 | 
            -
                         when 'h'
         | 
| 73 | 
            -
                           3600
         | 
| 74 | 
            -
                         when 'd'
         | 
| 75 | 
            -
                           86400
         | 
| 76 | 
            -
                         when 'w'
         | 
| 77 | 
            -
                           604800
         | 
| 78 | 
            -
                         else
         | 
| 79 | 
            -
                           raise ArgumentError
         | 
| 80 | 
            -
                         end
         | 
| 65 | 
            +
                number.to_i * unit_factor(unit.to_sym)
         | 
| 66 | 
            +
              end
         | 
| 81 67 |  | 
| 82 | 
            -
             | 
| 68 | 
            +
              def unit_factor(unit)
         | 
| 69 | 
            +
                factors = { s: 1, m: 60, h: 3600, d: 86_400, w: 604_800 }
         | 
| 70 | 
            +
                factors[unit] || 1
         | 
| 83 71 | 
             
              end
         | 
| 84 72 | 
             
            end
         | 
| @@ -1 +1 @@ | |
| 1 | 
            -
            WF_CLI_VERSION = '2.1. | 
| 1 | 
            +
            WF_CLI_VERSION = '2.1.5'.freeze
         | 
    
        data/lib/wavefront-cli/write.rb
    CHANGED
    
    | @@ -5,7 +5,6 @@ module WavefrontCli | |
| 5 5 | 
             
              #
         | 
| 6 6 | 
             
              # Send points to a proxy.
         | 
| 7 7 | 
             
              #
         | 
| 8 | 
            -
              # rubocop:disable Metrics/ClassLength
         | 
| 9 8 | 
             
              class Write < Base
         | 
| 10 9 | 
             
                attr_reader :fmt
         | 
| 11 10 | 
             
                include Wavefront::Mixins
         | 
| @@ -13,9 +12,6 @@ module WavefrontCli | |
| 13 12 | 
             
                def mk_creds
         | 
| 14 13 | 
             
                  { proxy: options[:proxy], port: options[:port] || 2878 }
         | 
| 15 14 | 
             
                end
         | 
| 16 | 
            -
             | 
| 17 | 
            -
                # rubocop:disable Metrics/AbcSize
         | 
| 18 | 
            -
                # rubocop:disable Metrics/MethodLength
         | 
| 19 15 | 
             
                def do_point
         | 
| 20 16 | 
             
                  p = { path:  options[:'<metric>'],
         | 
| 21 17 | 
             
                        value: options[:'<value>'].to_f,
         | 
| @@ -221,7 +217,7 @@ module WavefrontCli | |
| 221 217 | 
             
                #
         | 
| 222 218 | 
             
                def valid_timestamp?(ts)
         | 
| 223 219 | 
             
                  (ts.is_a?(Integer) || ts.match(/^\d+$/)) &&
         | 
| 224 | 
            -
                    ts.to_i >  | 
| 220 | 
            +
                    ts.to_i > 946_684_800 && ts.to_i < (Time.now.to_i + 31_557_600)
         | 
| 225 221 | 
             
                end
         | 
| 226 222 |  | 
| 227 223 | 
             
                def validate_opts
         | 
| @@ -239,9 +235,8 @@ module WavefrontCli | |
| 239 235 | 
             
                end
         | 
| 240 236 |  | 
| 241 237 | 
             
                def load_data(file)
         | 
| 242 | 
            -
                  IO.read(file)
         | 
| 243 | 
            -
                rescue
         | 
| 244 238 | 
             
                  raise "Cannot open file '#{file}'." unless file.exist?
         | 
| 239 | 
            +
                  IO.read(file)
         | 
| 245 240 | 
             
                end
         | 
| 246 241 | 
             
              end
         | 
| 247 242 | 
             
            end
         | 
    
        data/spec/.rubocop.yml
    ADDED
    
    
    
        data/spec/spec_helper.rb
    CHANGED
    
    | @@ -9,35 +9,34 @@ require_relative '../lib/wavefront-cli/controller' | |
| 9 9 |  | 
| 10 10 | 
             
            unless defined?(CMD)
         | 
| 11 11 | 
             
              CMD = 'wavefront'.freeze
         | 
| 12 | 
            -
              ENDPOINT = 'metrics.wavefront.com'
         | 
| 13 | 
            -
              TOKEN = '0123456789-ABCDEF'
         | 
| 12 | 
            +
              ENDPOINT = 'metrics.wavefront.com'.freeze
         | 
| 13 | 
            +
              TOKEN = '0123456789-ABCDEF'.freeze
         | 
| 14 14 | 
             
              RES_DIR = Pathname.new(__FILE__).dirname + 'wavefront-cli' + 'resources'
         | 
| 15 15 | 
             
              CF = RES_DIR + 'wavefront.conf'
         | 
| 16 16 | 
             
              CF_VAL =  IniFile.load(CF)
         | 
| 17 17 | 
             
              JSON_POST_HEADERS = {
         | 
| 18 | 
            -
             | 
| 18 | 
            +
                'Content-Type': 'application/json', Accept: 'application/json'
         | 
| 19 19 | 
             
              }.freeze
         | 
| 20 20 |  | 
| 21 | 
            -
              CMDS = %w | 
| 22 | 
            -
                        proxy query savedsearch source user window webhook write | 
| 21 | 
            +
              CMDS = %w[alert integration dashboard event link message metric
         | 
| 22 | 
            +
                        proxy query savedsearch source user window webhook write].freeze
         | 
| 23 23 |  | 
| 24 | 
            -
              BAD_TAG= | 
| 24 | 
            +
              BAD_TAG = '*BAD_TAG*'.freeze
         | 
| 25 25 | 
             
              TW = 80
         | 
| 26 26 | 
             
            end
         | 
| 27 27 |  | 
| 28 28 | 
             
            # Return an array of CLI permutations and the values to which they relate
         | 
| 29 29 | 
             
            #
         | 
| 30 30 | 
             
            def permutations
         | 
| 31 | 
            -
              [ | 
| 32 | 
            -
             | 
| 33 | 
            -
             | 
| 34 | 
            -
             | 
| 35 | 
            -
             | 
| 36 | 
            -
             | 
| 37 | 
            -
             | 
| 38 | 
            -
             | 
| 39 | 
            -
             | 
| 40 | 
            -
              ]
         | 
| 31 | 
            +
              [["-t #{TOKEN} -E #{ENDPOINT}", { t: TOKEN, e: ENDPOINT }],
         | 
| 32 | 
            +
               ["-c #{CF}", { t: CF_VAL['default']['token'],
         | 
| 33 | 
            +
                              e: CF_VAL['default']['endpoint'] }],
         | 
| 34 | 
            +
               ["-c #{CF} -P other", { t: CF_VAL['other']['token'],
         | 
| 35 | 
            +
                                       e: CF_VAL['other']['endpoint'] }],
         | 
| 36 | 
            +
               ["-c #{CF} -P other -t #{TOKEN}", { t: TOKEN,
         | 
| 37 | 
            +
                                                   e: CF_VAL['other']['endpoint'] }],
         | 
| 38 | 
            +
               ["-c #{CF} -E #{ENDPOINT}", { t: CF_VAL['default']['token'],
         | 
| 39 | 
            +
                                             e: ENDPOINT }]]
         | 
| 41 40 | 
             
            end
         | 
| 42 41 |  | 
| 43 42 | 
             
            # Match a command to the final API call it should produce, applying options in
         | 
| @@ -48,12 +47,12 @@ end | |
| 48 47 | 
             
            #  command
         | 
| 49 48 | 
             
            # @param call [Hash]
         | 
| 50 49 | 
             
            #
         | 
| 50 | 
            +
            # rubocop:disable Metrics/AbcSize
         | 
| 51 51 | 
             
            def cmd_to_call(word, args, call, sdk_class = nil)
         | 
| 52 52 | 
             
              headers = { 'Accept':          /.*/,
         | 
| 53 53 | 
             
                          'Accept-Encoding': /.*/,
         | 
| 54 54 | 
             
                          'Authorization':  'Bearer 0123456789-ABCDEF',
         | 
| 55 | 
            -
                          'User-Agent':     "wavefront-cli-#{WF_CLI_VERSION}"
         | 
| 56 | 
            -
                        }
         | 
| 55 | 
            +
                          'User-Agent':     "wavefront-cli-#{WF_CLI_VERSION}" }
         | 
| 57 56 |  | 
| 58 57 | 
             
              sdk_class ||= Object.const_get("WavefrontCli::#{word.capitalize}")
         | 
| 59 58 |  | 
| @@ -67,23 +66,25 @@ def cmd_to_call(word, args, call, sdk_class = nil) | |
| 67 66 | 
             
                    cmd = "#{word} #{args} #{opts} #{fmt}"
         | 
| 68 67 | 
             
                    uri = 'https://' + vals[:e] + call[:path]
         | 
| 69 68 | 
             
                    h = headers.dup
         | 
| 70 | 
            -
                    h[: | 
| 69 | 
            +
                    h[:Authorization] = "Bearer #{vals[:t]}"
         | 
| 71 70 |  | 
| 72 71 | 
             
                    it "runs #{cmd} and makes the correct API call" do
         | 
| 73 | 
            -
             | 
| 74 72 | 
             
                      if call.key?(:body)
         | 
| 75 | 
            -
                        stub_request(method, uri).with(headers: h, body: call[:body]) | 
| 76 | 
            -
             | 
| 73 | 
            +
                        stub_request(method, uri).with(headers: h, body: call[:body])
         | 
| 74 | 
            +
                                                 .to_return(body: {}.to_json, status: 200)
         | 
| 77 75 | 
             
                      else
         | 
| 78 | 
            -
                        stub_request(method, uri).with(headers: h) | 
| 79 | 
            -
             | 
| 76 | 
            +
                        stub_request(method, uri).with(headers: h)
         | 
| 77 | 
            +
                                                 .to_return(body: {}.to_json, status: 200)
         | 
| 80 78 | 
             
                      end
         | 
| 81 79 |  | 
| 82 80 | 
             
                      require "wavefront-sdk/#{sdk_class.name.split('::').last.downcase}"
         | 
| 83 | 
            -
                       | 
| 84 | 
            -
                         | 
| 85 | 
            -
             | 
| 86 | 
            -
             | 
| 81 | 
            +
                      Spy.on_instance_method(
         | 
| 82 | 
            +
                        Object.const_get(
         | 
| 83 | 
            +
                          "Wavefront::#{sdk_class.name.split('::').last}"
         | 
| 84 | 
            +
                        ),
         | 
| 85 | 
            +
                        :respond
         | 
| 86 | 
            +
                      ).and_return({})
         | 
| 87 | 
            +
                      d = Spy.on_instance_method(sdk_class, :display)
         | 
| 87 88 | 
             
                      WavefrontCliController.new(cmd.split)
         | 
| 88 89 | 
             
                      assert d.has_been_called?
         | 
| 89 90 | 
             
                      assert_requested(method, uri, headers: h)
         | 
| @@ -109,8 +110,8 @@ end | |
| 109 110 | 
             
            def invalid_something(cmd, subcmds, thing)
         | 
| 110 111 | 
             
              subcmds.each do |sc|
         | 
| 111 112 | 
             
                it "fails '#{sc}' because of an invalid #{thing}" do
         | 
| 112 | 
            -
                   | 
| 113 | 
            -
             | 
| 113 | 
            +
                  _out, err = fail_command("#{cmd} #{sc}")
         | 
| 114 | 
            +
                  assert_match(/^'.*' is not a valid #{thing}.\n$/, err)
         | 
| 114 115 | 
             
                end
         | 
| 115 116 | 
             
              end
         | 
| 116 117 | 
             
            end
         | 
| @@ -118,8 +119,8 @@ end | |
| 118 119 | 
             
            def invalid_tags(cmd, subcmds)
         | 
| 119 120 | 
             
              subcmds.each do |sc|
         | 
| 120 121 | 
             
                it "fails '#{sc}' because of an invalid tag" do
         | 
| 121 | 
            -
                   | 
| 122 | 
            -
             | 
| 122 | 
            +
                  _out, err = fail_command("#{cmd} #{sc}")
         | 
| 123 | 
            +
                  assert_equal(err, "'#{BAD_TAG}' is not a valid tag.\n")
         | 
| 123 124 | 
             
                end
         | 
| 124 125 | 
             
              end
         | 
| 125 126 | 
             
            end
         | 
| @@ -127,8 +128,8 @@ end | |
| 127 128 | 
             
            def invalid_ids(cmd, subcmds)
         | 
| 128 129 | 
             
              subcmds.each do |sc|
         | 
| 129 130 | 
             
                it "fails '#{sc}' on invalid input" do
         | 
| 130 | 
            -
                   | 
| 131 | 
            -
             | 
| 131 | 
            +
                  _out, err = fail_command("#{cmd} #{sc}")
         | 
| 132 | 
            +
                  assert_match(/^'.+' is not a valid \w/, err)
         | 
| 132 133 | 
             
                end
         | 
| 133 134 | 
             
              end
         | 
| 134 135 | 
             
            end
         | 
| @@ -142,7 +143,7 @@ def missing_creds(cmd, subcmds) | |
| 142 143 | 
             
                  it "'#{subcmd}' errors and tells the user to use a token" do
         | 
| 143 144 | 
             
                    out, err = fail_command("#{cmd} #{subcmd} -c /f")
         | 
| 144 145 | 
             
                    assert_match(/supply an API token/, err)
         | 
| 145 | 
            -
                    assert_match( | 
| 146 | 
            +
                    assert_match(%r{config file '/f' not found.}, out)
         | 
| 146 147 | 
             
                  end
         | 
| 147 148 | 
             
                end
         | 
| 148 149 | 
             
              end
         | 
| @@ -151,7 +152,7 @@ end | |
| 151 152 | 
             
            # Generic list tests, needed by most commands
         | 
| 152 153 | 
             
            #
         | 
| 153 154 | 
             
            def list_tests(cmd, pth = nil, k = nil)
         | 
| 154 | 
            -
              pth  | 
| 155 | 
            +
              pth ||= cmd
         | 
| 155 156 | 
             
              cmd_to_call(cmd, 'list', { path: "/api/v2/#{pth}?limit=100&offset=0" }, k)
         | 
| 156 157 | 
             
              cmd_to_call(cmd, 'list -L 50', { path: "/api/v2/#{pth}?limit=50&offset=0" },
         | 
| 157 158 | 
             
                          k)
         | 
| @@ -163,34 +164,33 @@ end | |
| 163 164 |  | 
| 164 165 | 
             
            def tag_tests(cmd, id, bad_id, pth = nil)
         | 
| 165 166 | 
             
              pth ||= cmd
         | 
| 166 | 
            -
              cmd_to_call(cmd, "tags #{id}",  | 
| 167 | 
            +
              cmd_to_call(cmd, "tags #{id}", path: "/api/v2/#{pth}/#{id}/tag")
         | 
| 167 168 | 
             
              cmd_to_call(cmd, "tag set #{id} mytag",
         | 
| 168 | 
            -
                           | 
| 169 | 
            -
             | 
| 170 | 
            -
             | 
| 171 | 
            -
             | 
| 169 | 
            +
                          method: :post,
         | 
| 170 | 
            +
                          path:    "/api/v2/#{pth}/#{id}/tag",
         | 
| 171 | 
            +
                          body:    %w[mytag].to_json,
         | 
| 172 | 
            +
                          headers: JSON_POST_HEADERS)
         | 
| 172 173 | 
             
              cmd_to_call(cmd, "tag set #{id} mytag1 mytag2",
         | 
| 173 | 
            -
                           | 
| 174 | 
            -
             | 
| 175 | 
            -
             | 
| 176 | 
            -
             | 
| 174 | 
            +
                          method: :post,
         | 
| 175 | 
            +
                          path: "/api/v2/#{pth}/#{id}/tag",
         | 
| 176 | 
            +
                          body: %w[mytag1 mytag2].to_json,
         | 
| 177 | 
            +
                          headers: JSON_POST_HEADERS)
         | 
| 177 178 | 
             
              cmd_to_call(cmd, "tag add #{id} mytag",
         | 
| 178 | 
            -
                           | 
| 179 | 
            +
                          method: :put, path: "/api/v2/#{pth}/#{id}/tag/mytag")
         | 
| 179 180 | 
             
              cmd_to_call(cmd, "tag delete #{id} mytag",
         | 
| 180 | 
            -
                           | 
| 181 | 
            -
              cmd_to_call(cmd, "tag clear #{id}",  | 
| 182 | 
            -
             | 
| 183 | 
            -
             | 
| 184 | 
            -
             | 
| 181 | 
            +
                          method: :delete, path: "/api/v2/#{pth}/#{id}/tag/mytag")
         | 
| 182 | 
            +
              cmd_to_call(cmd, "tag clear #{id}", method:  :post,
         | 
| 183 | 
            +
                                                  path:    "/api/v2/#{pth}/#{id}/tag",
         | 
| 184 | 
            +
                                                  body:    [].to_json,
         | 
| 185 | 
            +
                                                  headers: JSON_POST_HEADERS)
         | 
| 185 186 | 
             
              invalid_ids(cmd, ["tags #{bad_id}", "tag clear #{bad_id}",
         | 
| 186 187 | 
             
                                "tag add #{bad_id} mytag", "tag delete #{bad_id} mytag"])
         | 
| 187 | 
            -
              invalid_tags(cmd, ["tag add #{id} #{BAD_TAG}", " | 
| 188 | 
            -
                                 "tags #{id} tag1 #{BAD_TAG}",
         | 
| 189 | 
            -
                                 "tag delete #{id} #{BAD_TAG}"])
         | 
| 188 | 
            +
              invalid_tags(cmd, ["tag add #{id} #{BAD_TAG}", "tag delete #{id} #{BAD_TAG}"])
         | 
| 190 189 | 
             
            end
         | 
| 191 190 |  | 
| 191 | 
            +
            # stdlib extensions
         | 
| 192 | 
            +
            #
         | 
| 192 193 | 
             
            class Hash
         | 
| 193 | 
            -
             | 
| 194 194 | 
             
              # A quick way to deep-copy a hash.
         | 
| 195 195 | 
             
              #
         | 
| 196 196 | 
             
              def dup
         | 
| @@ -34,14 +34,14 @@ describe "#{word} command" do | |
| 34 34 | 
             
              cmd_to_call(word, "snooze #{id}",
         | 
| 35 35 | 
             
                          method: :post, path: "/api/v2/#{word}/#{id}/snooze")
         | 
| 36 36 | 
             
              cmd_to_call(word, "search id=#{id}",
         | 
| 37 | 
            -
                           | 
| 38 | 
            -
             | 
| 39 | 
            -
             | 
| 40 | 
            -
             | 
| 41 | 
            -
             | 
| 42 | 
            -
             | 
| 43 | 
            -
             | 
| 44 | 
            -
             | 
| 37 | 
            +
                          method: :post, path: "/api/v2/search/#{word}",
         | 
| 38 | 
            +
                          body:   { limit: 10,
         | 
| 39 | 
            +
                                    offset: 0,
         | 
| 40 | 
            +
                                    query: [{ key: 'id',
         | 
| 41 | 
            +
                                              value: id,
         | 
| 42 | 
            +
                                              matchingMethod: 'EXACT' }],
         | 
| 43 | 
            +
                                    sort: { field: 'id', ascending: true } },
         | 
| 44 | 
            +
                          headers: JSON_POST_HEADERS)
         | 
| 45 45 | 
             
              cmd_to_call(word, "snooze -T 800 #{id}",
         | 
| 46 46 | 
             
                          method: :post,
         | 
| 47 47 | 
             
                          path:   "/api/v2/#{word}/#{id}/snooze?seconds=800")
         | 
| @@ -17,13 +17,13 @@ describe 'cloudintegration command' do | |
| 17 17 | 
             
              cmd_to_call(word, "delete #{id}",
         | 
| 18 18 | 
             
                          { method: :delete, path: "/api/v2/cloudintegration/#{id}" }, k)
         | 
| 19 19 | 
             
              cmd_to_call(word, "search -L 100 id~#{id}",
         | 
| 20 | 
            -
                          { method: :post, path:  | 
| 21 | 
            -
                            body:   { limit:  | 
| 20 | 
            +
                          { method: :post, path: '/api/v2/search/cloudintegration',
         | 
| 21 | 
            +
                            body:   { limit: '100',
         | 
| 22 22 | 
             
                                      offset: 0,
         | 
| 23 | 
            -
                                      query: [{key: 'id',
         | 
| 24 | 
            -
             | 
| 25 | 
            -
             | 
| 26 | 
            -
                                      sort: {field: 'id', ascending: true}},
         | 
| 23 | 
            +
                                      query: [{ key: 'id',
         | 
| 24 | 
            +
                                                value: id,
         | 
| 25 | 
            +
                                                matchingMethod: 'CONTAINS' }],
         | 
| 26 | 
            +
                                      sort: { field: 'id', ascending: true } },
         | 
| 27 27 | 
             
                            headers: JSON_POST_HEADERS }, WavefrontCli::CloudIntegration)
         | 
| 28 28 | 
             
              cmd_to_call(word, "undelete #{id}",
         | 
| 29 29 | 
             
                          { method: :post,
         | 
| @@ -64,7 +64,6 @@ class WavefrontCommmandBaseTest < MiniTest::Test | |
| 64 64 | 
             
                assert_equal(wf.sdk_file, word.downcase)
         | 
| 65 65 | 
             
              end
         | 
| 66 66 |  | 
| 67 | 
            -
              # rubocop:disable Metrics/AbcSize
         | 
| 68 67 | 
             
              def test_commands
         | 
| 69 68 | 
             
                assert wf.commands.start_with?("Usage:\n")
         | 
| 70 69 | 
             
                assert wf.commands.match(/ --help$/)
         | 
| @@ -90,7 +89,6 @@ class WavefrontCommmandBaseTest < MiniTest::Test | |
| 90 89 | 
             
                assert_equal(wf.options.split("\n").select(&:empty?).size, 1)
         | 
| 91 90 | 
             
              end
         | 
| 92 91 |  | 
| 93 | 
            -
              # rubocop:disable Metrics/MethodLength
         | 
| 94 92 | 
             
              def test_opt_row
         | 
| 95 93 | 
             
                assert_equal(wf.opt_row('-s, --short    short option', 10),
         | 
| 96 94 | 
             
                             "  -s, --short    short option\n")
         | 
| @@ -16,22 +16,20 @@ class WavefrontCliHelpTest < MiniTest::Test | |
| 16 16 | 
             
              end
         | 
| 17 17 |  | 
| 18 18 | 
             
              def test_version
         | 
| 19 | 
            -
                WavefrontCliController.new(%w | 
| 19 | 
            +
                WavefrontCliController.new(%w[--version])
         | 
| 20 20 | 
             
              rescue SystemExit => e
         | 
| 21 21 | 
             
                assert_equal(1, e.status)
         | 
| 22 22 | 
             
                assert_match(/^\d+\.\d+\.\d+$/, e.message)
         | 
| 23 23 | 
             
              end
         | 
| 24 24 |  | 
| 25 25 | 
             
              def test_help
         | 
| 26 | 
            -
                WavefrontCliController.new(%w | 
| 26 | 
            +
                WavefrontCliController.new(%w[--help])
         | 
| 27 27 | 
             
              rescue SystemExit => e
         | 
| 28 28 | 
             
                assert_equal(1, e.status)
         | 
| 29 29 | 
             
                assert_match(/^Commands:$/, e.message)
         | 
| 30 30 | 
             
                CMDS.each { |cmd| assert_match(/^  #{cmd} /, e.message) }
         | 
| 31 31 | 
             
              end
         | 
| 32 32 |  | 
| 33 | 
            -
              # rubocop:disable Metrics/AbcSize
         | 
| 34 | 
            -
              # rubocop:disable Metrics/MethodLength
         | 
| 35 33 | 
             
              def test_command_help
         | 
| 36 34 | 
             
                CMDS.each do |cmd|
         | 
| 37 35 | 
             
                  begin
         | 
| @@ -56,6 +54,8 @@ class Giblets < WavefrontCliController | |
| 56 54 | 
             
              def initialize; end
         | 
| 57 55 | 
             
            end
         | 
| 58 56 |  | 
| 57 | 
            +
            # Here's the subclass
         | 
| 58 | 
            +
            #
         | 
| 59 59 | 
             
            class GibletsTest < MiniTest::Test
         | 
| 60 60 | 
             
              attr_reader :wfc
         | 
| 61 61 |  | 
| @@ -66,6 +66,6 @@ class GibletsTest < MiniTest::Test | |
| 66 66 | 
             
              def test_sanitize_keys
         | 
| 67 67 | 
             
                h_in = { '--help': true, stuff: false, 'key' => 'value' }
         | 
| 68 68 | 
             
                assert_equal(wfc.sanitize_keys(h_in),
         | 
| 69 | 
            -
                              | 
| 69 | 
            +
                             help: true, stuff: false, key: 'value')
         | 
| 70 70 | 
             
              end
         | 
| 71 71 | 
             
            end
         | 
| @@ -30,14 +30,14 @@ describe "#{word} command" do | |
| 30 30 | 
             
              end
         | 
| 31 31 |  | 
| 32 32 | 
             
              cmd_to_call(word, "search id=#{id}",
         | 
| 33 | 
            -
                           | 
| 34 | 
            -
             | 
| 35 | 
            -
             | 
| 36 | 
            -
             | 
| 37 | 
            -
             | 
| 38 | 
            -
             | 
| 39 | 
            -
             | 
| 40 | 
            -
             | 
| 33 | 
            +
                          method: :post, path: "/api/v2/search/#{word}",
         | 
| 34 | 
            +
                          body:   { limit: 10,
         | 
| 35 | 
            +
                                    offset: 0,
         | 
| 36 | 
            +
                                    query: [{ key: 'id',
         | 
| 37 | 
            +
                                              value: id,
         | 
| 38 | 
            +
                                              matchingMethod: 'EXACT' }],
         | 
| 39 | 
            +
                                    sort: { field: 'id', ascending: true } },
         | 
| 40 | 
            +
                          headers: JSON_POST_HEADERS)
         | 
| 41 41 |  | 
| 42 42 | 
             
              cmd_to_call(word, "undelete #{id}",
         | 
| 43 43 | 
             
                          method: :post, path: "/api/v2/#{word}/#{id}/undelete")
         |