Skip to content

Commit

Permalink
add liquibase harness tests v.1.0.10 (#375)
Browse files Browse the repository at this point in the history
* add liquibase harness tests v.1.0.10

* add test runner for Liquibase test harness

* Ignore Data loadUpdate liquibase harness test

* add new workflow

* fixing dependency

* resolve comments

* Add tests and clarifications for ignored tests

* chore: delete derby.log file

---------

Co-authored-by: Knut Olav Løite <[email protected]>
  • Loading branch information
vladimirevd and olavloite authored Dec 13, 2024
1 parent 876d6ef commit 21725a3
Show file tree
Hide file tree
Showing 86 changed files with 886 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ jobs:
distribution: zulu
java-version: ${{matrix.java}}
- run: java -version
- run: ./gradlew clean build
- run: ./gradlew clean build
25 changes: 25 additions & 0 deletions .github/workflows/harness.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
on:
pull_request:
name: gradle harness test
jobs:
ubuntu:
services:
emulator:
image: gcr.io/cloud-spanner-emulator/emulator:latest
ports:
- 9010:9010
- 9020:9020
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
java: [11, 17]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: zulu
java-version: ${{matrix.java}}
- run: java -version
- run: ./gradlew clean liquibaseHarnessTest
- run: ./gradlew clean build
46 changes: 34 additions & 12 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
plugins {
id "java"
id "groovy"
id "com.google.cloud.tools.jib" version "2.8.0"
id "com.github.johnrengelman.shadow" version "6.1.0"
id "com.github.harbby.gradle.serviceloader" version "1.1.2"
id "com.google.cloud.tools.jib" version "3.4.4"
id "com.github.johnrengelman.shadow" version "8.1.1"
id "com.github.harbby.gradle.serviceloader" version "1.1.8"
}


Expand Down Expand Up @@ -90,20 +90,20 @@ dependencies {
testImplementation("org.junit.jupiter:junit-jupiter-api:5.11.3")
testImplementation("org.testcontainers:testcontainers:1.20.3")
testImplementation("net.java.dev.jna:jna:5.15.0")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.11.3")
testImplementation("com.google.truth:truth:1.4.4") {
exclude group: 'com.google.guava', module: 'guava'
}
testImplementation("org.mockito:mockito-core:1.10.19")

// For using the Liquibase test harness
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.liquibase:liquibase-test-harness:1.0.0'
testImplementation('org.codehaus.groovy:groovy-all:2.5.23') {
testImplementation ('org.liquibase:liquibase-test-harness:1.0.10'){
exclude group: 'org.firebirdsql.jdbc', module: 'jaybird'
}
testImplementation('org.apache.groovy:groovy-all:4.0.23') {
exclude module: 'org.codehaus.groovy:groovy-testng'
exclude module: 'org.codehaus.groovy:groovy-swing'
}
testImplementation 'org.spockframework:spock-core:1.3-groovy-2.5'
testImplementation 'org.spockframework:spock-core:2.3-groovy-4.0'

// For testing runtime
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.11.3")
Expand All @@ -125,16 +125,20 @@ test {

useJUnitPlatform {
excludeTags "integration"
exclude '**/CloudSpannerBaseHarnessSuiteTest*'
exclude '**/CloudSpannerAdvancedHarnessSuiteTest*'
}
}

task liquibaseHarnessTest(type: Test) {
tasks.register('liquibaseHarnessTest', Test) {

// serviceLoaderBuild is necessary for Liquibase to find the extensions
dependsOn "serviceLoaderBuild"

// Use JUnit4 for Liquibase harness tests.
useJUnit {
useJUnitPlatform {
include '**/CloudSpannerBaseHarnessSuiteTest*'
include '**/CloudSpannerAdvancedHarnessSuiteTest*'
include '**/CloudSpannerFoundationalHarnessSuiteTest*'
}
}

Expand All @@ -143,7 +147,7 @@ task liquibaseHarnessTest(type: Test) {
// Requires SPANNER_PROJECT and SPANNER_INSTANCE environment variables.
// Also requires GOOGLE_APPLICATION_CREDENTIALS environment variable
// if using a JSON key for authentication.
task integrationTest(type: Test) {
tasks.register('integrationTest', Test) {
shouldRunAfter "test"

// serviceLoaderBuild is necessary for Liquibase to find the extensions
Expand All @@ -154,6 +158,24 @@ task integrationTest(type: Test) {
}
}

tasks.withType(Test).configureEach {
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(8)
}
dependencies {
testImplementation("org.mockito:mockito-core:3.12.4")
}
}

tasks.named('liquibaseHarnessTest', Test).configure {
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(11)
}
dependencies {
testImplementation("org.mockito:mockito-core:5.14.1")
}
}

build {

// Build shadowJar during normal build
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
13 changes: 13 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
<groovy.version>2.5.23</groovy.version>
<dependency.spock.version>1.3-groovy-2.4</dependency.spock.version>
<picocli.version>4.7.6</picocli.version>
<junit-platform.version>1.11.3</junit-platform.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -123,6 +124,18 @@
<version>3.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite</artifactId>
<version>${junit-platform.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>${junit-platform.version}</version>
<scope>test</scope>
</dependency>

<!-- Generic test dependencies -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package liquibase.ext.spanner

import liquibase.harness.AdvancedHarnessSuite
import liquibase.harness.snapshot.SnapshotObjectTests
import org.junit.platform.suite.api.SelectClasses

@SelectClasses(SnapshotObjectTests.class)
class CloudSpannerAdvancedHarnessSuiteTest extends AdvancedHarnessSuite{
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package liquibase.ext.spanner

import liquibase.harness.BaseHarnessSuite

class CloudSpannerHarnessTest extends BaseHarnessSuite {
class CloudSpannerBaseHarnessSuiteTest extends BaseHarnessSuite {
}
2 changes: 1 addition & 1 deletion src/test/resources/harness-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ context: testContext
databasesUnderTest:
- name: cloudspanner
version: 1.0
url: jdbc:cloudspanner://localhost:9010/projects/my-project/instances/my-instance/databases/my-database?usePlainText=true
url: jdbc:cloudspanner://localhost:9010/projects/my-project/instances/my-instance/databases/my-database?usePlainText=true;autoConfigEmulator=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">
<changeSet id="1" author="spanner-liquibase-tests">
<sqlFile path="init.txt"
relativeToChangelogFile="true"
stripComments="true"/>
<rollback/>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">
<changeSet author="spanner-liquibase-tests" id="1">
<addLookupTable
existingColumnName="email"
existingTableName="authors"
newColumnDataType="STRING(100)"
newColumnName="authors_email"
newTableName="authors_data"/>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">
<changeSet id="1" author="spanner-liquibase-tests">
<createTable tableName="lms_create_table_test">
<column name="lms_test_id" type="INTEGER">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="lms_test_timestamp" type="TIMESTAMP"/>
</createTable>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
<changeSet id="2" author="oleh">
<createView viewName="test_view">
select authors.id, authors.first_name, authors.last_name, authors.email from authors
</createView>
<rollback>
<dropView viewName="test_view"/>
</rollback>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">

<changeSet id="2" author="oleh">
<createView viewName="test_view">
select authors.id, authors.first_name, authors.last_name, authors.email from authors
</createView>
<dropView viewName="test_view"/>
<rollback/>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
DROP TABLE IF EXISTS authors;

CREATE TABLE authors (
id INT64 NOT NULL,
first_name STRING(1024),
last_name STRING(1024),
email STRING(1024),
birthdate DATE,
added TIMESTAMP
) PRIMARY KEY (id);


INSERT INTO authors (id, first_name, last_name, email, birthdate, added)
VALUES (1, 'Alice', 'Doe', '[email protected]', '1990-07-15', '2012-12-25T10:45:00Z');

INSERT INTO authors (id, first_name, last_name, email, birthdate, added)
VALUES (2, 'John', 'Smith', '[email protected]', '1985-11-22', '2015-08-10T14:30:00Z');

DROP TABLE IF EXISTS posts;

CREATE TABLE posts (
id INT64 NOT NULL,
author_id INT64 NOT NULL,
title STRING(1024),
description STRING(1024),
content STRING(1024),
inserted_date DATE,
)
PRIMARY KEY (id);


INSERT INTO posts (id, author_id, title, description, content, inserted_date)
VALUES (1, 1, 'libero', 'perspiciatis', 'Saepe laboriosam cupiditate consequatur distinctio.', '2020-07-14');

INSERT INTO posts (id, author_id, title, description, content, inserted_date)
VALUES (2, 2, 'rerum', 'voluptates', 'Consequuntur assumenda adipisci vel repellendus.', '1982-02-25');

Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">
<changeSet id="1" author="spanner-liquibase-tests">
<createTable tableName="full_name_table">
<column name="id" type="int">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="first_name"
type="string(50)"/>
<column name="last_name"
type="string(50)"/>
</createTable>
<rollback/>
</changeSet>
<changeSet id="2" author="spanner-liquibase-tests">
<insert tableName="full_name_table">
<column name="id"
valueNumeric="1"/>
<column name="first_name"
value="John"/>
</insert>
<update tableName="full_name_table">
<column name="last_name"
value="Doe"/>
<where>first_name='John'</where>
</update>
<insert tableName="full_name_table">
<column name="id"
valueNumeric="2"/>
<column name="first_name"
value="Jane"/>
</insert>
<update tableName="full_name_table">
<column name="last_name"
value="Doe"/>
<where>first_name='Jane'</where>
</update>
<rollback/>
</changeSet>
<changeSet id="3" author="spanner-liquibase-tests">
<mergeColumns column1Name="first_name"
column2Name="last_name"
finalColumnName="full_name"
finalColumnType="string(255)"
joinString=" "
tableName="full_name_table"/>
<rollback>
<dropTable tableName="full_name_table"/>
</rollback>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
<changeSet id="1" author="spanner-liquibase-tests">
<createTable tableName="modify_data_type_test">
<column name="id" type="int">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="stringColumn" type="string(50)"/>
<column name="dateColumn" type="date"/>
</createTable>
<rollback>
<dropTable tableName="modify_data_type_test"/>
</rollback>
</changeSet>
<changeSet id="2" author="as">
<sql>
ALTER TABLE modify_data_type_test ALTER COLUMN stringColumn BYTES(50)
</sql>
<!-- <modifyDataType columnName="stringColumn"-->
<!-- newDataType="binary"-->
<!-- tableName="modify_data_type_test"/>-->
<rollback/>
</changeSet>
</databaseChangeLog>
Loading

0 comments on commit 21725a3

Please sign in to comment.