-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
spec/lib/dump_cleaner/cleaners/mysql_shell_dump_cleaner_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
require "tempfile" | ||
require "fileutils" | ||
|
||
RSpec.describe DumpCleaner::Cleaners::MysqlShellDumpCleaner do | ||
let(:config) do | ||
instance_double(DumpCleaner::Config, cleanup_tables: [%w[db table1], %w[db table2]]) | ||
end | ||
|
||
describe "#pre_cleanup" do | ||
it "creates the destination dump directory" do | ||
Dir.mktmpdir do |dir| | ||
options = instance_double(DumpCleaner::Options, source_dump_path: "#{dir}/source_dump", | ||
destination_dump_path: "#{dir}/dest_dump") | ||
expect(Dir.exist?("#{dir}/dest_dump")).to be false | ||
|
||
described_class.new(config:, options:).pre_cleanup | ||
expect(Dir.exist?("#{dir}/dest_dump")).to be true | ||
end | ||
end | ||
end | ||
|
||
describe "#clean" do | ||
it "calls the MysqlShellTableCleaner hooks for each table" do | ||
options = instance_double(DumpCleaner::Options, source_dump_path: "source_dump", | ||
destination_dump_path: "dest_dump") | ||
|
||
cleaner1 = instance_double(DumpCleaner::Cleaners::MysqlShellTableCleaner) | ||
expect(DumpCleaner::Cleaners::MysqlShellTableCleaner) | ||
.to receive(:new).with(db: "db", table: "table1", config:, options:) | ||
.and_return(cleaner1) | ||
expect(cleaner1).to receive(:pre_cleanup) | ||
expect(cleaner1).to receive(:clean) | ||
expect(cleaner1).to receive(:post_cleanup) | ||
|
||
cleaner2 = instance_double(DumpCleaner::Cleaners::MysqlShellTableCleaner) | ||
expect(DumpCleaner::Cleaners::MysqlShellTableCleaner) | ||
.to receive(:new).with(db: "db", table: "table2", config:, options:) | ||
.and_return(cleaner2) | ||
expect(cleaner2).to receive(:pre_cleanup) | ||
expect(cleaner2).to receive(:clean) | ||
expect(cleaner2).to receive(:post_cleanup) | ||
|
||
described_class.new(config:, options:).clean | ||
end | ||
end | ||
|
||
describe "#post_cleanup" do | ||
it "copies all non-existent files to destination" do | ||
Dir.mktmpdir do |dir| | ||
options = instance_double(DumpCleaner::Options, source_dump_path: "#{dir}/source_dump", | ||
destination_dump_path: "#{dir}/dest_dump") | ||
Dir.mkdir("#{dir}/source_dump") | ||
FileUtils.touch("#{dir}/source_dump/file1") | ||
FileUtils.touch("#{dir}/source_dump/file2") | ||
FileUtils.touch("#{dir}/source_dump/file3") | ||
|
||
Dir.mkdir("#{dir}/dest_dump") | ||
FileUtils.touch("#{dir}/dest_dump/file2") | ||
|
||
described_class.new(config:, options:).post_cleanup | ||
expect(File.exist?("#{dir}/dest_dump/file1")).to be true | ||
expect(File.exist?("#{dir}/dest_dump/file3")).to be true | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters