require 'fluent_plugins_spec_helper' require 'flydata/fluent-plugins/mysql/truncate_table_query_handler' require 'flydata/fluent-plugins/mysql/shared_query_handler_context' module Mysql describe TruncateTableQueryHandler do include_context "query handler context" describe '#process' do let(:truncate_query) { "TRUNCATE TABLE foo" } let(:expected_record) do { table_name: table, query: truncate_query, type: :truncate_table, respect_order: true, src_pos: "#{current_binlog_file}\t#{next_position - event_length}", table_rev: table_rev, seq: seq } end before do allow(record).to receive(:[]).with("query").and_return(truncate_query) allow(record).to receive(:[]).with("normalized_query").and_return(truncate_query) end context "for a non append only table" do it "should call Fluent's emit with appropriate params" do expect(Fluent::Engine).to receive(:emit).with(tag, timestamp, expected_record) expect(subject.process(record)) end end context "for an append only table" do before do allow(context).to receive(:omit_events).and_return({ table => [:delete, :truncate_table] }) end it "should not call Fluent's emit" do expect(Fluent::Engine).to receive(:emit).never expect(subject.process(record)) end end end end end