require 'fluent_plugins_spec_helper' require 'flydata/fluent-plugins/mysql/binlog_query_dispatcher' module Mysql QUERY_WITH_COMMENTS = < normalized_query}).and_return(r) r end let(:alter_query_handler) do r = double('alter_query_handler') allow(r).to receive(:pattern).and_return(Mysql::AlterTableQueryHandler::PATTERN) r end let(:truncate_query_handler) do r = double('truncate_query_handler') allow(r).to receive(:pattern).and_return(Mysql::TruncateTableQueryHandler::PATTERN) r end let(:context) { double('context') } let(:subject_object) { described_class.new(context) } subject { subject_object } shared_examples "a dispatcher that calls query handler with correct query" do it do expect(correct_query_handler).to receive(:process).with(record) expect(subject.dispatch(record)) end end before do expect(AlterTableQueryHandler).to receive(:new).with(context).and_return(alter_query_handler) expect(TruncateTableQueryHandler).to receive(:new).with(context).and_return(truncate_query_handler) end describe '#dispatch' do context "alter table queries" do let(:correct_query_handler) { alter_query_handler } context "query with comments" do let(:query) { QUERY_WITH_COMMENTS } let(:normalized_query) { NORMALIZED_QUERY_WITH_COMMENTS } it_behaves_like "a dispatcher that calls query handler with correct query" end context "customer query" do let(:query) { CUSTOMER_QUERY } let(:normalized_query) { NORMALIZED_CUSTOMER_QUERY } it_behaves_like "a dispatcher that calls query handler with correct query" end context "query with leading newline" do let(:query) { QUERY_WITH_LEADING_NEWLINE } let(:normalized_query) { NORMALIZED_QUERY_WITH_COMMENTS } it_behaves_like "a dispatcher that calls query handler with correct query" end context "query with special characters in DEFAULT" do let(:query) { QUERY_WITH_SPECIAL_CHARS_IN_DEFAULT } let(:normalized_query) { NORMALIZED_QUERY_WITH_SPECIAL_CHARS } it_behaves_like "a dispatcher that calls query handler with correct query" end context "query with preceding commands" do let(:query) { <