Sha256: d04c2afcf83b88910bf8895bb8a9bd1dc37ba38eb6bac335dd1162e52f5c1252

Contents?: true

Size: 1.71 KB

Versions: 4

Compression:

Stored size: 1.71 KB

Contents

# frozen_string_literal: true

require 'simplecov'
SimpleCov.start

$LOAD_PATH.unshift File.expand_path('../lib', __dir__)
$LOAD_PATH.unshift File.expand_path('lib', __dir__)
require 'fluent/plugin/out_splunk_hec'
require 'fluent/plugin/out_splunk_ingest_api'

require 'fluent/test'
require 'fluent/test/driver/output'
require 'fluent/test/helpers'
require 'minitest/autorun'
require 'webmock/minitest'

# make assertions from webmock available in minitest/spec
module Minitest::Expectations
  infect_an_assertion :assert_requested, :must_be_requested, :reverse
  infect_an_assertion :assert_not_requested, :wont_be_requested, :reverse
end

TEST_HEC_TOKEN = 'some-token'

module PluginTestHelper
  def fluentd_conf_for(*lines)
    basic_config = [
      "hec_token #{TEST_HEC_TOKEN}"
    ]
    (basic_config + lines).join("\n")
  end

  def create_hec_output_driver(*configs)
    Fluent::Test::Driver::Output.new(Fluent::Plugin::SplunkHecOutput).tap do |d|
      d.configure(fluentd_conf_for(*configs))
    end
  end

  def stub_hec_request(endpoint)
    stub_request(:post, "#{endpoint}/services/collector")
      .with(headers: { 'Authorization' => "Splunk #{TEST_HEC_TOKEN}",
                       'User-Agent' => "fluent-plugin-splunk_hec_out/#{Fluent::Plugin::SplunkHecOutput::VERSION}" })
      .to_return(body: '{"text":"Success","code":0}')
  end

  def stub_hec_gzip_request(endpoint)
    stub_request(:post, "#{endpoint}/services/collector")
      .with(headers: {
        'Authorization' => "Splunk #{TEST_HEC_TOKEN}",
        'User-Agent' => "fluent-plugin-splunk_hec_out/#{Fluent::Plugin::SplunkHecOutput::VERSION}",
        'Content-Encoding' => "gzip"
      },
      )
      .to_return(body: '{"text":"GzipSuccess","code":0}')
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
fluent-plugin-splunk-hec-1.3.3 test/test_helper.rb
fluent-plugin-splunk-hec-1.3.2 test/test_helper.rb
fluent-plugin-splunk-hec-1.3.1 test/test_helper.rb
fluent-plugin-splunk-hec-1.3.0 test/test_helper.rb