Sha256: dd9ebf448848a8d0548f5cbfc5d9da2ac67eb3b572a68505918301375575d66e

Contents?: true

Size: 1.82 KB

Versions: 24

Compression:

Stored size: 1.82 KB

Contents

require 'fluent_plugins_spec_helper'
require 'flydata/fluent-plugins/mysql/table_meta'

module Mysql
  describe TableMeta do
    let(:mysql_url) { double('mysql_url') }
    let(:database) { 'test-db' }
    let(:tables) { %w(a_table b_table c_table) }

    let(:conn) { double('conn') }
    let(:table_meta) { TableMeta.new(
      mysql_url: mysql_url, database: database, tables: tables) }

    before do
      allow(conn).to receive(:close)
      allow(Mysql2::Client).to receive(:new).and_return(conn)
    end

    describe '.update' do
      let(:query_result) {[]}
      before do
        allow(conn).to receive(:query).and_return(query_result)
      end

      context 'when character_set_name is supported' do
        context 'when encoding is not necessary' do
          let(:query_result) {[
            {'table_name' => 'a_table', 'character_set_name' => 'utf8' }
          ]}
          it 'set nil for encoding' do
            table_meta.update
            expect(table_meta['a_table'][:encoding]).to be_nil
          end
        end

        context 'when encoding is needed' do
          let(:query_result) {[
            {'table_name' => 'a_table', 'character_set_name' => 'latin1' },
            {'table_name' => 'b_table', 'character_set_name' => 'cp932' }
          ]}
          it 'set ruby encoding encoding' do
            table_meta.update
            expect(table_meta['a_table'][:encoding]).to eq('ISO-8859-1')
            expect(table_meta['b_table'][:encoding]).to eq('CP932')
          end
        end
      end

      context 'when character_set_name is not supported' do
        let(:query_result) {[
          {'table_name' => 'a_table', 'character_set_name' => 'xxxx' }
        ]}
        it 'raise an error' do
          expect{table_meta.update}.to raise_error('Unsupported charset:xxxx.')
        end
      end
    end
  end
end


Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
flydata-0.3.13 spec/flydata/fluent-plugins/mysql/table_meta_spec.rb
flydata-0.3.12 spec/flydata/fluent-plugins/mysql/table_meta_spec.rb
flydata-0.3.11 spec/flydata/fluent-plugins/mysql/table_meta_spec.rb
flydata-0.3.10 spec/flydata/fluent-plugins/mysql/table_meta_spec.rb
flydata-0.3.9 spec/flydata/fluent-plugins/mysql/table_meta_spec.rb
flydata-0.3.8 spec/flydata/fluent-plugins/mysql/table_meta_spec.rb
flydata-0.3.7 spec/flydata/fluent-plugins/mysql/table_meta_spec.rb
flydata-0.3.6 spec/flydata/fluent-plugins/mysql/table_meta_spec.rb
flydata-0.3.5 spec/flydata/fluent-plugins/mysql/table_meta_spec.rb
flydata-0.3.4 spec/flydata/fluent-plugins/mysql/table_meta_spec.rb
flydata-0.3.3 spec/flydata/fluent-plugins/mysql/table_meta_spec.rb
flydata-0.3.2 spec/flydata/fluent-plugins/mysql/table_meta_spec.rb
flydata-0.3.1 spec/flydata/fluent-plugins/mysql/table_meta_spec.rb
flydata-0.3.0 spec/flydata/fluent-plugins/mysql/table_meta_spec.rb
flydata-0.2.30 spec/flydata/fluent-plugins/mysql/table_meta_spec.rb
flydata-0.2.29 spec/flydata/fluent-plugins/mysql/table_meta_spec.rb
flydata-0.2.28 spec/flydata/fluent-plugins/mysql/table_meta_spec.rb
flydata-0.2.27 spec/flydata/fluent-plugins/mysql/table_meta_spec.rb
flydata-0.2.26 spec/flydata/fluent-plugins/mysql/table_meta_spec.rb
flydata-0.2.25 spec/flydata/fluent-plugins/mysql/table_meta_spec.rb