Skip to content

Commit

Permalink
Added test for getTables and getViews with an underscore in the table…
Browse files Browse the repository at this point in the history
… name
  • Loading branch information
nvoxland committed Feb 10, 2022
1 parent f6d9a4c commit fd08168
Showing 1 changed file with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package liquibase.snapshot

import liquibase.Scope
import liquibase.database.DatabaseFactory
import liquibase.database.jvm.JdbcConnection
import liquibase.extension.testing.testsystem.DatabaseTestSystem
import liquibase.extension.testing.testsystem.TestSystemFactory
import liquibase.statement.SqlStatement
import liquibase.statement.core.RawSqlStatement
import liquibase.structure.core.Table
import liquibase.structure.core.View
import org.junit.Rule
import spock.lang.Shared
import spock.lang.Specification
import spock.lang.Unroll

import java.sql.Connection

class JdbcDatabaseSnapshotTest extends Specification {

@Rule
public DatabaseTestSystem h2 = Scope.currentScope.getSingleton(TestSystemFactory).getTestSystem("h2")

@Unroll
def "getTables and getViews works with underscores in schema names"() {
when:
def connection = h2.getConnection()
def db = DatabaseFactory.instance.findCorrectDatabaseImplementation(new JdbcConnection(connection))
db.execute([
new RawSqlStatement("create schema if not exists \"TEST_SCHEMA\""),
new RawSqlStatement("create schema if not exists \"TEST-SCHEMA\""),
new RawSqlStatement("create table if not exists \"TEST-SCHEMA\".test_table (id int)"),
new RawSqlStatement("create view if not exists \"TEST-SCHEMA\".test_view as select * from \"TEST-SCHEMA\".test_table"),
] as SqlStatement[], null)

then:
SnapshotGeneratorFactory.instance.has(new Table(null, "TEST-SCHEMA", "TEST_TABLE"), db)
!SnapshotGeneratorFactory.instance.has(new Table(null, "TEST_SCHEMA", "TEST_TABLE"), db)

SnapshotGeneratorFactory.instance.has(new View(null, "TEST-SCHEMA", "TEST_VIEW"), db)
!SnapshotGeneratorFactory.instance.has(new View(null, "TEST_SCHEMA", "TEST_VIEW"), db)

cleanup:
db.execute([
new RawSqlStatement("drop schema \"test_schema\" if exists"),
new RawSqlStatement("drop schema \"test-schema\" if exists"),
] as SqlStatement[], null)
}
}

0 comments on commit fd08168

Please sign in to comment.