Sha256: 9fbdbdff12c3a2e3e53a1a95fb5e794e822744c87111ab2227d9b0bbc993f516

Contents?: true

Size: 1.66 KB

Versions: 6

Compression:

Stored size: 1.66 KB

Contents

require 'helper'
require 'logger'
require 'stringio'
require 'simple_uuid'
require 'cassanity/instrumentation/log_subscriber'

describe Cassanity::Instrumentation::LogSubscriber do
  let(:client) {
    Cassanity::Client.new(CassanityHost, CassanityPort, {
      instrumenter: ActiveSupport::Notifications,
    })
  }

  let(:keyspace) { client[:cassanity_test] }

  let(:column_family) {
    keyspace.column_family({
      name: :apps,
      schema: {
        primary_key: :id,
        columns: {
          id: :timeuuid,
          name: :text,
        },
      },
    })
  }

  before do
    @io = StringIO.new
    Cassanity::Instrumentation::LogSubscriber.logger = Logger.new(@io)

    keyspace.recreate
    column_family.recreate
  end

  after do
    Cassanity::Instrumentation::LogSubscriber.logger = nil
  end

  it "works" do
    column_family.insert({
      data: {
        id: SimpleUUID::UUID.new,
        name: 'GitHub.com',
      },
    })

    query = "INSERT INTO cassanity_test.apps (id, name) VALUES (?, ?)"
    log = @io.string
    log.should match(/#{Regexp.escape(query)}/i)
    log.should match(/UUID/i)
    log.should match(/GitHub\.com/i)
  end

  it "does not fail when no bind variables" do
    client.keyspaces
    query = "SELECT * FROM system.schema_keyspaces"
    log = @io.string
    log.should match(/#{Regexp.escape(query)}/i)
  end

  it "works through exceptions" do
    client.driver.should_receive(:execute).and_raise(StandardError.new('boom'))
    begin
      client.keyspaces
    rescue StandardError => e
    end

    query = "SELECT * FROM system.schema_keyspaces"
    log = @io.string.split("\n").last
    log.should match(/#{Regexp.escape(query)}/i)
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
cassanity-0.6.0 spec/integration/cassanity/instrumentation/log_subscriber_spec.rb
cassanity-0.6.0.beta5 spec/integration/cassanity/instrumentation/log_subscriber_spec.rb
cassanity-0.6.0.beta4 spec/integration/cassanity/instrumentation/log_subscriber_spec.rb
cassanity-0.6.0.beta3 spec/integration/cassanity/instrumentation/log_subscriber_spec.rb
cassanity-0.6.0.beta2 spec/integration/cassanity/instrumentation/log_subscriber_spec.rb
cassanity-0.6.0.beta1 spec/integration/cassanity/instrumentation/log_subscriber_spec.rb