From f4634027a3f9c59bd91fc7a5530ad8136e6ee9ae Mon Sep 17 00:00:00 2001 From: Steven Massaro Date: Fri, 5 Jan 2024 08:43:03 -0500 Subject: [PATCH] switch integration tests to use h2 where possible (DAT-16015) (#5417) --- .../core/RollbackIntegrationTest.groovy | 18 +++---- ...gradeChecksumVersionIntegrationTest.groovy | 3 ++ .../command/diff/DiffIntegrationTest.groovy | 16 +++---- .../util/ShowSummaryUtilCommandTest.groovy | 48 +++++++++---------- 4 files changed, 42 insertions(+), 43 deletions(-) diff --git a/liquibase-integration-tests/src/test/groovy/liquibase/command/core/RollbackIntegrationTest.groovy b/liquibase-integration-tests/src/test/groovy/liquibase/command/core/RollbackIntegrationTest.groovy index 67a139b7eac..f395a212e0d 100644 --- a/liquibase-integration-tests/src/test/groovy/liquibase/command/core/RollbackIntegrationTest.groovy +++ b/liquibase-integration-tests/src/test/groovy/liquibase/command/core/RollbackIntegrationTest.groovy @@ -6,33 +6,29 @@ import liquibase.TagVersionEnum import liquibase.command.util.CommandUtil import liquibase.exception.CommandExecutionException import liquibase.exception.RollbackFailedException -import liquibase.exception.UnexpectedLiquibaseException import liquibase.extension.testing.testsystem.DatabaseTestSystem import liquibase.extension.testing.testsystem.TestSystemFactory import liquibase.extension.testing.testsystem.spock.LiquibaseIntegrationTest -import liquibase.logging.core.BufferedLogService import liquibase.resource.SearchPathResourceAccessor import liquibase.ui.ConsoleUIService import spock.lang.Shared import spock.lang.Specification -import java.util.logging.Level - @LiquibaseIntegrationTest class RollbackIntegrationTest extends Specification { @Shared - private DatabaseTestSystem postgres = (DatabaseTestSystem) Scope.getCurrentScope().getSingleton(TestSystemFactory.class).getTestSystem("postgresql") + private DatabaseTestSystem h2 = (DatabaseTestSystem) Scope.getCurrentScope().getSingleton(TestSystemFactory.class).getTestSystem("h2") def "Should rollback correctly with duplicate tags"() { given: def changelogFile = 'target/test-classes/changelogs/pgsql/rollback/rollback-to-tag-changelog.xml' - CommandUtil.runUpdate(postgres, changelogFile) + CommandUtil.runUpdate(h2, changelogFile) ConsoleUIService console = Scope.getCurrentScope().getUI() as ConsoleUIService def outputStream = new ByteArrayOutputStream() console.setOutputStream(new PrintStream(outputStream)) when: - CommandUtil.runRollback(new SearchPathResourceAccessor("."), postgres, changelogFile, "version_2.0", TagVersionEnum.NEWEST) + CommandUtil.runRollback(new SearchPathResourceAccessor("."), h2, changelogFile, "version_2.0", TagVersionEnum.NEWEST) String outputString = outputStream.toString() then: @@ -41,10 +37,10 @@ class RollbackIntegrationTest extends Specification { assert outputString.contains("Rolling Back Changeset: target/test-classes/changelogs/pgsql/rollback/rollback-to-tag-changelog.xml::13.2::testuser") when: - CommandUtil.runUpdate(postgres, changelogFile) + CommandUtil.runUpdate(h2, changelogFile) outputStream = new ByteArrayOutputStream() console.setOutputStream(new PrintStream(outputStream)) - CommandUtil.runRollback(new SearchPathResourceAccessor("."), postgres, changelogFile, "version_2.0", TagVersionEnum.OLDEST) + CommandUtil.runRollback(new SearchPathResourceAccessor("."), h2, changelogFile, "version_2.0", TagVersionEnum.OLDEST) outputString = outputStream.toString() then: @@ -55,7 +51,7 @@ class RollbackIntegrationTest extends Specification { when: outputStream = new ByteArrayOutputStream() console.setOutputStream(new PrintStream(outputStream)) - CommandUtil.runRollback(new SearchPathResourceAccessor("."), postgres, changelogFile, "version_2.0") + CommandUtil.runRollback(new SearchPathResourceAccessor("."), h2, changelogFile, "version_2.0") outputString = outputStream.toString() then: @@ -64,6 +60,6 @@ class RollbackIntegrationTest extends Specification { assert e.getMessage() == "liquibase.exception.RollbackFailedException: Could not find tag 'version_2.0' in the database" cleanup: - CommandUtil.runDropAll(postgres) + CommandUtil.runDropAll(h2) } } diff --git a/liquibase-integration-tests/src/test/groovy/liquibase/command/core/UpgradeChecksumVersionIntegrationTest.groovy b/liquibase-integration-tests/src/test/groovy/liquibase/command/core/UpgradeChecksumVersionIntegrationTest.groovy index 7242b4bec24..40684b544b5 100644 --- a/liquibase-integration-tests/src/test/groovy/liquibase/command/core/UpgradeChecksumVersionIntegrationTest.groovy +++ b/liquibase-integration-tests/src/test/groovy/liquibase/command/core/UpgradeChecksumVersionIntegrationTest.groovy @@ -423,5 +423,8 @@ VALUES('2', 'fl', '$changesetFilepath', '2023-09-29 14:33:39.112', 2, 'EXECUTED' def ranChangeSets = changeLogService.getRanChangeSets() ranChangeSets.size() == 1 ranChangeSets.get(0).getLastCheckSum().toString() == "7:72c7eea8dda3c3582e3cfb39eec12033" + + cleanup: + CommandUtil.runDropAll(h2) } } diff --git a/liquibase-integration-tests/src/test/groovy/liquibase/command/diff/DiffIntegrationTest.groovy b/liquibase-integration-tests/src/test/groovy/liquibase/command/diff/DiffIntegrationTest.groovy index 1c43af11213..a90464a9ab6 100644 --- a/liquibase-integration-tests/src/test/groovy/liquibase/command/diff/DiffIntegrationTest.groovy +++ b/liquibase-integration-tests/src/test/groovy/liquibase/command/diff/DiffIntegrationTest.groovy @@ -25,18 +25,18 @@ import spock.lang.Specification class DiffIntegrationTest extends Specification { @Shared - private DatabaseTestSystem postgres = - (DatabaseTestSystem) Scope.getCurrentScope().getSingleton(TestSystemFactory.class).getTestSystem("postgresql") + private DatabaseTestSystem h2 = + (DatabaseTestSystem) Scope.getCurrentScope().getSingleton(TestSystemFactory.class).getTestSystem("h2") def "Diff with excludes that reference objects on target should work" () { when: - CommandUtil.runDropAll(postgres) - CommandUtil.runSnapshot(postgres, "target/test-classes/snapshot.json") - CommandUtil.runTag(postgres, "1.0.0") + CommandUtil.runDropAll(h2) + CommandUtil.runSnapshot(h2, "target/test-classes/snapshot.json") + CommandUtil.runTag(h2, "1.0.0") def diffFile = "target/test-classes/diff.json" def url = "offline:postgresql?snapshot=target/test-classes/snapshot.json" Database targetDatabase = - DatabaseFactory.getInstance().openDatabase(postgres.getConnectionUrl(), postgres.getUsername(), postgres.getPassword(), null, new SearchPathResourceAccessor(".")) + DatabaseFactory.getInstance().openDatabase(h2.getConnectionUrl(), h2.getUsername(), h2.getPassword(), null, new SearchPathResourceAccessor(".")) def refUrl = "offline:postgresql?snapshot=target/test-classes/snapshot.json" Database refDatabase = @@ -72,8 +72,8 @@ class DiffIntegrationTest extends Specification { } catch (Exception ignored) { } - CommandUtil.runDropAll(postgres) - postgres.getConnection().close() + CommandUtil.runDropAll(h2) + h2.getConnection().close() refDatabase.close() targetDatabase.close() } diff --git a/liquibase-integration-tests/src/test/groovy/liquibase/util/ShowSummaryUtilCommandTest.groovy b/liquibase-integration-tests/src/test/groovy/liquibase/util/ShowSummaryUtilCommandTest.groovy index 094b15e7db5..86d4aeefa90 100644 --- a/liquibase-integration-tests/src/test/groovy/liquibase/util/ShowSummaryUtilCommandTest.groovy +++ b/liquibase-integration-tests/src/test/groovy/liquibase/util/ShowSummaryUtilCommandTest.groovy @@ -20,7 +20,7 @@ import java.util.logging.Level @LiquibaseIntegrationTest class ShowSummaryUtilCommandTest extends Specification { @Shared - private DatabaseTestSystem postgres = (DatabaseTestSystem) Scope.getCurrentScope().getSingleton(TestSystemFactory.class).getTestSystem("postgresql") + private DatabaseTestSystem h2 = (DatabaseTestSystem) Scope.getCurrentScope().getSingleton(TestSystemFactory.class).getTestSystem("h2") def "Should show summary output when run multiple times"() { given: @@ -28,7 +28,7 @@ class ShowSummaryUtilCommandTest extends Specification { when: new File(outputFile).delete() - CommandUtil.runUpdate(postgres,'changelogs/pgsql/update/showSummaryWithLabels.xml', "testtable1", "none", outputFile) + CommandUtil.runUpdate(h2,'changelogs/pgsql/update/showSummaryWithLabels.xml', "testtable1", "none", outputFile) then: new File(outputFile).getText("UTF-8").contains("Run: 2") @@ -36,16 +36,16 @@ class ShowSummaryUtilCommandTest extends Specification { when: new File(outputFile).delete() - CommandUtil.runUpdate(postgres,'changelogs/pgsql/update/showSummaryWithLabels.xml', "testtable1", "none", outputFile) + CommandUtil.runUpdate(h2,'changelogs/pgsql/update/showSummaryWithLabels.xml', "testtable1", "none", outputFile) then: new File(outputFile).getText("UTF-8").contains("Run: 0") new File(outputFile).getText("UTF-8").contains("Filtered out: 4") cleanup: - CommandUtil.runDropAll(postgres) - if (postgres.getConnection() != null) { - postgres.getConnection().close() + CommandUtil.runDropAll(h2) + if (h2.getConnection() != null) { + h2.getConnection().close() } } @@ -60,9 +60,9 @@ class ShowSummaryUtilCommandTest extends Specification { @Override void run() throws Exception { CommandScope commandScope = new CommandScope(UpdateCommandStep.COMMAND_NAME) - commandScope.addArgumentValue(DbUrlConnectionArgumentsCommandStep.URL_ARG, postgres.getConnectionUrl()) - commandScope.addArgumentValue(DbUrlConnectionArgumentsCommandStep.USERNAME_ARG, postgres.getUsername()) - commandScope.addArgumentValue(DbUrlConnectionArgumentsCommandStep.PASSWORD_ARG, postgres.getPassword()) + commandScope.addArgumentValue(DbUrlConnectionArgumentsCommandStep.URL_ARG, h2.getConnectionUrl()) + commandScope.addArgumentValue(DbUrlConnectionArgumentsCommandStep.USERNAME_ARG, h2.getUsername()) + commandScope.addArgumentValue(DbUrlConnectionArgumentsCommandStep.PASSWORD_ARG, h2.getPassword()) commandScope.addArgumentValue(UpdateCommandStep.CHANGELOG_FILE_ARG, "changelogs/pgsql/update/showSummaryWithLabels.xml") commandScope.addArgumentValue(UpdateCommandStep.LABEL_FILTER_ARG, "testtable1") commandScope.addArgumentValue(UpdateCommandStep.CONTEXTS_ARG, null) @@ -88,9 +88,9 @@ class ShowSummaryUtilCommandTest extends Specification { !outputStream.toString().contains("UPDATE SUMMARY") cleanup: - CommandUtil.runDropAll(postgres) - if (postgres.getConnection() != null) { - postgres.getConnection().close() + CommandUtil.runDropAll(h2) + if (h2.getConnection() != null) { + h2.getConnection().close() } } @@ -105,9 +105,9 @@ class ShowSummaryUtilCommandTest extends Specification { @Override void run() throws Exception { CommandScope commandScope = new CommandScope(UpdateCommandStep.COMMAND_NAME) - commandScope.addArgumentValue(DbUrlConnectionArgumentsCommandStep.URL_ARG, postgres.getConnectionUrl()) - commandScope.addArgumentValue(DbUrlConnectionArgumentsCommandStep.USERNAME_ARG, postgres.getUsername()) - commandScope.addArgumentValue(DbUrlConnectionArgumentsCommandStep.PASSWORD_ARG, postgres.getPassword()) + commandScope.addArgumentValue(DbUrlConnectionArgumentsCommandStep.URL_ARG, h2.getConnectionUrl()) + commandScope.addArgumentValue(DbUrlConnectionArgumentsCommandStep.USERNAME_ARG, h2.getUsername()) + commandScope.addArgumentValue(DbUrlConnectionArgumentsCommandStep.PASSWORD_ARG, h2.getPassword()) commandScope.addArgumentValue(UpdateCommandStep.CHANGELOG_FILE_ARG, "changelogs/pgsql/update/showSummaryWithLabels.xml") commandScope.addArgumentValue(UpdateCommandStep.LABEL_FILTER_ARG, "testtable1") commandScope.addArgumentValue(UpdateCommandStep.CONTEXTS_ARG, null) @@ -135,9 +135,9 @@ class ShowSummaryUtilCommandTest extends Specification { !logContent.contains("UPDATE SUMMARY") cleanup: - CommandUtil.runDropAll(postgres) - if (postgres.getConnection() != null) { - postgres.getConnection().close() + CommandUtil.runDropAll(h2) + if (h2.getConnection() != null) { + h2.getConnection().close() } } @@ -152,9 +152,9 @@ class ShowSummaryUtilCommandTest extends Specification { @Override void run() throws Exception { CommandScope commandScope = new CommandScope(UpdateCommandStep.COMMAND_NAME) - commandScope.addArgumentValue(DbUrlConnectionArgumentsCommandStep.URL_ARG, postgres.getConnectionUrl()) - commandScope.addArgumentValue(DbUrlConnectionArgumentsCommandStep.USERNAME_ARG, postgres.getUsername()) - commandScope.addArgumentValue(DbUrlConnectionArgumentsCommandStep.PASSWORD_ARG, postgres.getPassword()) + commandScope.addArgumentValue(DbUrlConnectionArgumentsCommandStep.URL_ARG, h2.getConnectionUrl()) + commandScope.addArgumentValue(DbUrlConnectionArgumentsCommandStep.USERNAME_ARG, h2.getUsername()) + commandScope.addArgumentValue(DbUrlConnectionArgumentsCommandStep.PASSWORD_ARG, h2.getPassword()) commandScope.addArgumentValue(UpdateCommandStep.CHANGELOG_FILE_ARG, "changelogs/pgsql/update/showSummaryWithLabels.xml") commandScope.addArgumentValue(UpdateCommandStep.LABEL_FILTER_ARG, "testtable1") commandScope.addArgumentValue(UpdateCommandStep.CONTEXTS_ARG, null) @@ -190,9 +190,9 @@ class ShowSummaryUtilCommandTest extends Specification { streamContent.contains("DBMS mismatch: 1") cleanup: - CommandUtil.runDropAll(postgres) - if (postgres.getConnection() != null) { - postgres.getConnection().close() + CommandUtil.runDropAll(h2) + if (h2.getConnection() != null) { + h2.getConnection().close() } }