Skip to content

Commit

Permalink
#46 tested and fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Jan 19, 2024
1 parent 0872d06 commit f322ba1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
25 changes: 14 additions & 11 deletions lib/pgtk/liquibase_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,24 @@ def initialize(*args, &task_block)
def run
raise "Option 'master' is mandatory" unless @master
raise "Option 'yaml' is mandatory" unless @yaml
yml = YAML.load_file(
if @yaml.is_a?(Array)
@yaml.drop_while { |f| !File.exist?(f) }.first
else
@yaml
end
)
raise "YAML at #{yaml} is missing 'pgsql' section" unless yml['pgsql']
pom = File.expand_path(File.join(__dir__, '../../resources/pom.xml'))
yml = @yaml
unless yml.is_a?(Hash)
yml = YAML.load_file(
if @yaml.is_a?(Array)
@yaml.drop_while { |f| !File.exist?(f) }.first
else
@yaml
end
)
end
raise "YAML configuration is missing the 'pgsql' section" unless yml['pgsql']
@master = File.expand_path(@master)
unless File.exist?(@master)
raise "Liquibase master is absent at '#{@master}', which points to '#{File.realpath(@master)}'. \
raise "Liquibase master is absent at '#{@master}'. \
More about this file you can find in Liquibase documentation: \
https://docs.liquibase.com/concepts/changelogs/xml-format.html"
end
@master = File.expand_path(@master)
pom = File.expand_path(File.join(__dir__, '../../resources/pom.xml'))
Dir.chdir(File.dirname(@master)) do
system(
[
Expand Down
11 changes: 11 additions & 0 deletions test/test_liquibase_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,15 @@ def test_basic
Rake::Task['liquibase2'].invoke
end
end

def test_with_invalid_master_file
Pgtk::LiquibaseTask.new(:lb) do |t|
t.master = 'the-file-doesnt-exist.xml'
t.yaml = { 'pgsql' => {} }
end
ex = assert_raises do
Rake::Task['lb'].invoke
end
assert(ex.message.include?('the-file-doesnt-exist.xml'))
end
end

0 comments on commit f322ba1

Please sign in to comment.