Skip to content

Commit

Permalink
Add more specs for MiqPglogical
Browse files Browse the repository at this point in the history
These specs cover the cases where the provider node is not yet
created.
  • Loading branch information
carbonin committed Nov 8, 2016
1 parent a40216a commit 30cec80
Showing 1 changed file with 65 additions and 40 deletions.
105 changes: 65 additions & 40 deletions spec/replication/util/miq_pglogical_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,69 +5,94 @@
before do
skip "pglogical must be installed" unless pglogical.installed?
MiqServer.seed
subject.configure_provider
end

describe "#provider?" do
it "is true when a provider is configured" do
expect(subject.provider?).to be true
it "is false when a provider is not configured" do
expect(subject.provider?).to be false
end
end

describe "#node?" do
it "is true when a provider is configured" do
expect(subject.node?).to be true
it "is false when a provider is not configured" do
expect(subject.node?).to be false
end
end

describe "#destroy_provider" do
it "removes the provider configuration" do
subject.destroy_provider
expect(subject.provider?).to be false
expect(subject.node?).to be false
expect(connection.extension_enabled?("pglogical")).to be false
describe "#configure_provider" do
it "enables the extenstion and creates the replication set" do
subject.configure_provider
expect(pglogical.enabled?).to be true
expect(pglogical.replication_sets).to include(described_class::REPLICATION_SET_NAME)
end
end

describe "#create_replication_set" do
it "creates the correct initial set" do
expected_excludes = subject.configured_excludes
actual_excludes = connection.tables - subject.included_tables
expect(actual_excludes).to match_array(expected_excludes)
context "when configured as a provider" do
before do
subject.configure_provider
end
end

describe "#refresh_excludes" do
it "adds a new non excluded table" do
connection.exec_query(<<-SQL)
CREATE TABLE test (id INTEGER PRIMARY KEY)
SQL
subject.refresh_excludes
expect(subject.included_tables).to include("test")
describe "#provider?" do
it "is true" do
expect(subject.provider?).to be true
end
end

it "removes a newly excluded table" do
table = subject.included_tables.first
new_excludes = subject.configured_excludes << table
describe "#node?" do
it "is true" do
expect(subject.node?).to be true
end
end

c = MiqServer.my_server.get_config
c.config.store_path(*described_class::SETTINGS_PATH, :exclude_tables, new_excludes)
c.save
describe "#destroy_provider" do
it "removes the provider configuration" do
subject.destroy_provider
expect(subject.provider?).to be false
expect(subject.node?).to be false
expect(connection.extension_enabled?("pglogical")).to be false
end
end

subject.refresh_excludes
expect(subject.included_tables).not_to include(table)
describe "#create_replication_set" do
it "creates the correct initial set" do
expected_excludes = subject.configured_excludes
actual_excludes = connection.tables - subject.included_tables
expect(actual_excludes).to match_array(expected_excludes)
end
end

it "adds a newly included table" do
table = subject.configured_excludes.last
new_excludes = subject.configured_excludes - [table]
describe "#refresh_excludes" do
it "adds a new non excluded table" do
connection.exec_query(<<-SQL)
CREATE TABLE test (id INTEGER PRIMARY KEY)
SQL
subject.refresh_excludes
expect(subject.included_tables).to include("test")
end

it "removes a newly excluded table" do
table = subject.included_tables.first
new_excludes = subject.configured_excludes << table

c = MiqServer.my_server.get_config
c.config.store_path(*described_class::SETTINGS_PATH, :exclude_tables, new_excludes)
c.save

subject.refresh_excludes
expect(subject.included_tables).not_to include(table)
end

it "adds a newly included table" do
table = subject.configured_excludes.last
new_excludes = subject.configured_excludes - [table]

c = MiqServer.my_server.get_config
c.config.store_path(*described_class::SETTINGS_PATH, :exclude_tables, new_excludes)
c.save
c = MiqServer.my_server.get_config
c.config.store_path(*described_class::SETTINGS_PATH, :exclude_tables, new_excludes)
c.save

subject.refresh_excludes
expect(subject.included_tables).to include(table)
subject.refresh_excludes
expect(subject.included_tables).to include(table)
end
end
end

Expand Down

0 comments on commit 30cec80

Please sign in to comment.