Sha256: d1752ddb6c15c7d98238813169703a4c73ab649a48333ba280de6c0ab32009d9

Contents?: true

Size: 1.69 KB

Versions: 9

Compression:

Stored size: 1.69 KB

Contents

require 'fluent_plugins_spec_helper'
require 'flydata/fluent-plugins/mysql/drop_database_query_handler'
require 'flydata/fluent-plugins/mysql/shared_query_handler_context'

module Mysql
  describe DropDatabaseQueryHandler do
    let(:subject_object) { described_class.new(context) }
    include_context "query handler context"

    let(:drop_keyword) { "DATABASE" }
    let(:drop_database_query) { "DROP #{drop_keyword} #{database}" }

    describe '#process' do
      subject { subject_object.process(record) }
      before do
        expect(Fluent::Engine).to receive(:emit).never
      end

      shared_examples "test different dbs" do
        context "for the target db" do
          let(:database) { target_database }
          let(:binlog_pos) { "#{context.current_binlog_file}\t#{record['next_position'] - record['event_length']}" }

          it "shows a error message" do
            expect($log).to receive(:error).with("DROP DATABASE detected. A full re-sync is required to provide sync consistency. - db_name:'#{record["db_name"]}' query:'#{record["query"]}' normalized query:'#{record["normalized_query"]}' binlog_pos:'#{binlog_pos}'")

            subject
          end
        end
        context "for another db" do
          let(:database) { "another_db" }
          it "does not show a error message" do
            expect($log).not_to receive(:error)
            subject
          end
        end
      end

      context "with drop database query" do
        let(:drop_keyword) { "DATABASE" }
        include_examples "test different dbs"
      end

      context "with drop schema query" do
        let(:drop_keyword) { "SCHEMA" }
        include_examples "test different dbs"
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
flydata-0.6.11 spec/flydata/fluent-plugins/mysql/drop_database_query_handler_spec.rb
flydata-0.6.10 spec/flydata/fluent-plugins/mysql/drop_database_query_handler_spec.rb
flydata-0.6.9 spec/flydata/fluent-plugins/mysql/drop_database_query_handler_spec.rb
flydata-0.6.8 spec/flydata/fluent-plugins/mysql/drop_database_query_handler_spec.rb
flydata-0.6.7 spec/flydata/fluent-plugins/mysql/drop_database_query_handler_spec.rb
flydata-0.6.6 spec/flydata/fluent-plugins/mysql/drop_database_query_handler_spec.rb
flydata-0.6.5 spec/flydata/fluent-plugins/mysql/drop_database_query_handler_spec.rb
flydata-0.6.4 spec/flydata/fluent-plugins/mysql/drop_database_query_handler_spec.rb
flydata-0.6.3 spec/flydata/fluent-plugins/mysql/drop_database_query_handler_spec.rb