Sha256: e36fc02420e860fcbb3e022e33fde8336fbf1373002a996a5319dadef405dcb4

Contents?: true

Size: 1.65 KB

Versions: 2

Compression:

Stored size: 1.65 KB

Contents

require_relative '../helper'
require 'google/apis/logging_v2'

class GoogleCloudLoggingOnPrem < Test::Unit::TestCase
  include Fluent::Test::Helpers

  def setup
    Fluent::Test.setup
    GrpcMock.enable!
    GrpcMock.disable_net_connect!
  end

  # default configuration for tests
  CONFIG = <<-CONFIG.freeze
    project_id my-project-id
  CONFIG

  def create_driver(config = CONFIG)
    Fluent::Test::Driver::Output.new(Fluent::Plugin::GoogleCloudLoggingOnPrem).configure(config)
  end

  test 'project_id should be present' do
    assert_raise Fluent::ConfigError do
      create_driver ''
    end
  end

  test 'project_id is set correctly' do
    d = create_driver
    assert_equal 'my-project-id', d.instance.project_id
  end

  test 'writes to logger' do
    VCR.use_cassette('logging', record: :new_episodes, match_requests_on: %i[method uri]) do
      GrpcMock
        .stub_request('/google.logging.v2.LoggingServiceV2/WriteLogEntries')
        .to_return(Google::Apis::LoggingV2::WriteLogEntriesResponse.new)

      driver = create_driver
      timestamp = event_time
      payload = { 'message' => 'this is a test message', 'value' => 100 }

      Google::Cloud::Logging::Entry.any_instance.stubs(:timestamp=).once.with(timestamp)
      Google::Cloud::Logging::Entry.any_instance.stubs(:payload=).once.with(payload)
      Google::Cloud::Logging::Entry.any_instance.stubs(:log_name=).once.with('custom-tag')
      Google::Cloud::Logging::Resource.any_instance.stubs(:type=).once.with('project')
      Google::Cloud::Logging::Project.any_instance.expects(:write_entries).once

      driver.run do
        driver.feed('custom-tag', timestamp, payload)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fluent-plugin-google-cloud-logging-on-prem-0.1.2 test/plugin/test_out_google_cloud_logging_on_prem.rb
fluent-plugin-google-cloud-logging-on-prem-0.1.0 test/plugin/test_out_google_cloud_logging_on_prem.rb