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 warning message" do expect($log).to receive(:warn).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 warning message" do expect($log).not_to receive(:warn) 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