require 'spec_helper' require 'flydata-core/postgresql/compatibility_checker' module FlydataCore module Postgresql describe 'CompatibilityChecker' do let(:database) { 'test_db' } let(:tables) { %w(table_1 table_2 table_3) } let(:option) do { database: database, tables: tables } end describe SnapshotFunctionChecker do let(:subject_object) { described_class.new(option) } describe '#check_reesult' do let(:result) { [] } subject { subject_object.check_result(result) } context 'when the function exists' do let(:result) do [ {'proname' => 'txid_current_snapshot'} ] end it { expect{subject}.not_to raise_error } end context 'when the function does not exist' do let(:result) do [] end it do expect{subject}.to raise_error( FlydataCore::PostgresqlCompatibilityError, /Unsupported PostgreSQL version/ ) end end end end describe TableExistenceChecker do let(:subject_object) { described_class.new(option) } describe '#create_query' do subject { subject_object.create_query } context 'when schema is not set' do it { is_expected.to eq < 'table_1'}, {'table_name' => 'table_2'}, {'table_name' => 'table_3'}, ] end it { expect{subject}.not_to raise_error } end context 'when some tables does not exist' do let(:result) do [{"table_name" => "table_2"}] end it do expect{subject}.to raise_error {|e| expect(e).to be_kind_of(FlydataCore::PostgresqlCompatibilityError) expect(e.to_s.include?("table_1")).to be_truthy expect(e.to_s.include?("table_2")).to be_falsey expect(e.to_s.include?("table_3")).to be_truthy } end end end end describe PrimaryKeyChecker do let(:subject_object) { described_class.new(option) } describe '#create_query' do subject { subject_object.create_query } context 'when schema is not set' do it { is_expected.to eq < "table_1"}, {"table_name" => "table_3"}] end it do skip "Primary key check for postgresql currenlty not raises error due to false alarm" expect{subject}.to raise_error {|e| expect(e).to be_kind_of(FlydataCore::PostgresqlCompatibilityError) expect(e.to_s.include?("table_1")).to be_truthy expect(e.to_s.include?("table_2")).to be_falsey expect(e.to_s.include?("table_3")).to be_truthy } end end end end describe PkOverrideChecker do let(:subject_object) { described_class.new(option) } describe '#create_query' do subject { subject_object.create_query } context 'when pk_override is given' do before do option[:pk_override] = { 'table_1' => ['id'], 'table_2' => ['name'], } end it { is_expected.to eq < "table_1", "column_name" => "id"}, {"table_name" => "table_1", "column_name" => "value"}, {"table_name" => "table_2", "column_name" => "name"}, {"table_name" => "table_2", "column_name" => "age"}, ] } before do option[:pk_override] = pk_override end context 'when given pk_override exist' do let(:pk_override) { { 'table_1' => ['id'], 'table_2' => ['name'], } } it { expect{subject}.not_to raise_error } end context 'when some columns do not exist' do let(:pk_override) { { 'table_1' => ['id'], 'table_2' => ['id'], } } it do expect{subject}.to raise_error {|e| expect(e).to be_kind_of(FlydataCore::PostgresqlCompatibilityError) expect(e.to_s.include?("table_1")).to be_falsey expect(e.to_s.include?("table_2")).to be_truthy } end end end end end end end