From b4d7a55d7a137b3802eb84453ad0a93fef229f3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Budnik?= Date: Wed, 1 Sep 2021 08:52:48 +0200 Subject: [PATCH 1/4] integration testing only main db flavours (all the MySQL and PostgreSQL flavours are tested already by their drivers) --- .github/workflows/build.yml | 2 +- .travis.yml | 2 +- README.md | 4 +-- db/db_integration_test.go | 2 +- test/docker-compose-dbs-only.yaml | 46 +++++++++++++++++++++++++++++++ test/docker-compose.yaml | 30 +------------------- test/migrator-mariadb.yaml | 8 ------ test/migrator-percona.yaml | 8 ------ 8 files changed, 51 insertions(+), 51 deletions(-) create mode 100644 test/docker-compose-dbs-only.yaml delete mode 100644 test/migrator-mariadb.yaml delete mode 100644 test/migrator-percona.yaml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7cea791..4ed7a07 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,7 +26,7 @@ jobs: password: ${{ secrets.DOCKER_HUB_TOKEN }} - name: Start docker-compose services - run: docker-compose -f test/docker-compose.yaml up -d + run: docker-compose -f test/docker-compose-dbs-only.yaml up -d - name: Build and test migrator env: diff --git a/.travis.yml b/.travis.yml index b0d2d05..30bb6ac 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ go: - '1.17' before_script: - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin -- docker-compose -f test/docker-compose.yaml up -d +- docker-compose -f test/docker-compose-dbs-only.yaml up -d script: - "./coverage.sh" after_success: diff --git a/README.md b/README.md index 7cea724..0b3061c 100644 --- a/README.md +++ b/README.md @@ -267,9 +267,7 @@ docker-compose will start and configure the following services: 2. `migrator-dev` - service built from local branch, listening on port `8282` 3. `postgres` - PostgreSQL service, listening on port `54325` 4. `mysql` - MySQL service, listening on port `3306` -5. `mariadb` - MariaDB (MySQL flavour), listening on port `13306` -6. `percona` - Percona (MySQL flavour), listening on port `23306` -7. `mssql` - MS SQL Server, listening on port `1433` +5. `mssql` - MS SQL Server, listening on port `1433` > Note: Every database container has a ready-to-use migrator config in `test` directory. You can edit `test/docker-compose.yaml` file and switch to a different database. By default `migrator` and `migrator-dev` services use `test/migrator-docker.yaml` which connects to `mysql` service. diff --git a/db/db_integration_test.go b/db/db_integration_test.go index 973ab0a..06fd4ed 100644 --- a/db/db_integration_test.go +++ b/db/db_integration_test.go @@ -11,7 +11,7 @@ import ( ) func getSupportedDatabases() []string { - return []string{"postgresql", "mysql", "mariadb", "percona", "mssql"} + return []string{"postgresql", "mysql", "mssql"} } func TestGetTenants(t *testing.T) { diff --git a/test/docker-compose-dbs-only.yaml b/test/docker-compose-dbs-only.yaml new file mode 100644 index 0000000..80fe604 --- /dev/null +++ b/test/docker-compose-dbs-only.yaml @@ -0,0 +1,46 @@ +version: "3.6" +services: + postgres: + image: postgres + ports: + - "5432:5432" + environment: + - POSTGRES_PASSWORD=supersecret + - POSTGRES_DB=migrator + volumes: + - ./create-test-tenants.sql:/docker-entrypoint-initdb.d/create-test-tenants.sql + mysql: + image: mysql + ports: + - "3306:3306" + environment: + - MYSQL_ROOT_PASSWORD=supersecret + volumes: + - ./create-test-tenants.sql:/docker-entrypoint-initdb.d/create-test-tenants.sql + mssql: + image: mcr.microsoft.com/mssql/server:2017-latest + ports: + - "1433:1433" + environment: + - SA_PASSWORD=Super5ecret + - ACCEPT_EULA=Y + volumes: + - ./create-test-tenants-mssql.sql:/docker-entrypoint-initdb.d/create-test-tenants-mssql.sql + command: + - /bin/bash + - -c + - | + /opt/mssql/bin/sqlservr & + PID=$$! + is_up=-1 + while [ $$is_up -ne 0 ] && [ $$is_up -ne 16 ] ; do + /opt/mssql-tools/bin/sqlcmd -l 30 -S localhost -h-1 -V1 -U sa -P $$SA_PASSWORD -Q "CREATE DATABASE migrator" + is_up=$$? + sleep 5 + done + if [ $$is_up -eq 0 ]; then + for script in /docker-entrypoint-initdb.d/*.sql + do /opt/mssql-tools/bin/sqlcmd -U sa -P $$SA_PASSWORD -d migrator -l 30 -e -i $$script + done + fi + wait $$PID diff --git a/test/docker-compose.yaml b/test/docker-compose.yaml index b3e3677..84900f7 100644 --- a/test/docker-compose.yaml +++ b/test/docker-compose.yaml @@ -25,38 +25,18 @@ services: - MYSQL_ROOT_PASSWORD=supersecret volumes: - ./create-test-tenants.sql:/docker-entrypoint-initdb.d/create-test-tenants.sql - mariadb: - image: mariadb - ports: - - "13306:3306" - environment: - - MYSQL_ROOT_PASSWORD=supersecret - volumes: - - ./create-test-tenants.sql:/docker-entrypoint-initdb.d/create-test-tenants.sql - percona: - image: percona - ports: - - "23306:3306" - environment: - - MYSQL_ROOT_PASSWORD=supersecret - volumes: - - ./create-test-tenants.sql:/docker-entrypoint-initdb.d/create-test-tenants.sql # phpmyadmin: # image: phpmyadmin/phpmyadmin # depends_on: # - mysql - # - mariadb - # - percona # ports: # - "8888:80" # environment: - # - PMA_HOSTS=mysql,mariadb,percona + # - PMA_HOSTS=mysql # - PMA_USER=root # - PMA_PASSWORD=supersecret # links: # - mysql - # - mariadb - # - percona mssql: image: mcr.microsoft.com/mssql/server:2017-latest ports: @@ -88,8 +68,6 @@ services: image: lukasz/migrator:latest depends_on: - mysql - - mariadb - - percona - postgres - mssql ports: @@ -100,8 +78,6 @@ services: - .:/data links: - mysql - - mariadb - - percona - postgres - mssql migrator-dev: @@ -111,8 +87,6 @@ services: dockerfile: test/migrator-dev/Dockerfile depends_on: - mysql - - mariadb - - percona - postgres - mssql ports: @@ -123,7 +97,5 @@ services: - .:/data links: - mysql - - mariadb - - percona - postgres - mssql diff --git a/test/migrator-mariadb.yaml b/test/migrator-mariadb.yaml deleted file mode 100644 index ef9c329..0000000 --- a/test/migrator-mariadb.yaml +++ /dev/null @@ -1,8 +0,0 @@ -baseLocation: test/migrations -driver: mysql -dataSource: "root:supersecret@tcp(127.0.0.1:13306)/migrator?parseTime=true&timeout=1s" -singleMigrations: - - ref - - config -tenantMigrations: - - tenants diff --git a/test/migrator-percona.yaml b/test/migrator-percona.yaml deleted file mode 100644 index 8dce17f..0000000 --- a/test/migrator-percona.yaml +++ /dev/null @@ -1,8 +0,0 @@ -baseLocation: test/migrations -driver: mysql -dataSource: "root:supersecret@tcp(127.0.0.1:23306)/migrator?parseTime=true&timeout=1s" -singleMigrations: - - ref - - config -tenantMigrations: - - tenants From 37c2e579104df793807f12fa3876068fd03379ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Budnik?= Date: Wed, 1 Sep 2021 09:38:30 +0200 Subject: [PATCH 2/4] added back migrator-dev for the http integration tests --- .github/workflows/build.yml | 2 +- .travis.yml | 3 ++- ...e-dbs-only.yaml => docker-compose-it.yaml} | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) rename test/{docker-compose-dbs-only.yaml => docker-compose-it.yaml} (78%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4ed7a07..e63b549 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,7 +26,7 @@ jobs: password: ${{ secrets.DOCKER_HUB_TOKEN }} - name: Start docker-compose services - run: docker-compose -f test/docker-compose-dbs-only.yaml up -d + run: docker-compose -f test/docker-compose-it.yaml up -d - name: Build and test migrator env: diff --git a/.travis.yml b/.travis.yml index 30bb6ac..3e6843b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,9 +5,10 @@ go: - '1.17' before_script: - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin -- docker-compose -f test/docker-compose-dbs-only.yaml up -d +- docker-compose -f test/docker-compose-it.yaml up -d script: - "./coverage.sh" +- "./test/./test/http-integration-tests.sh" after_success: - bash <(curl -s https://codecov.io/bash) env: diff --git a/test/docker-compose-dbs-only.yaml b/test/docker-compose-it.yaml similarity index 78% rename from test/docker-compose-dbs-only.yaml rename to test/docker-compose-it.yaml index 80fe604..6901f98 100644 --- a/test/docker-compose-dbs-only.yaml +++ b/test/docker-compose-it.yaml @@ -44,3 +44,22 @@ services: done fi wait $$PID + migrator-dev: + image: migrator-dev + build: + context: .. + dockerfile: test/migrator-dev/Dockerfile + depends_on: + - mysql + - postgres + - mssql + ports: + - "8282:8080" + environment: + - MIGRATOR_YAML=/data/migrator-docker.yaml + volumes: + - .:/data + links: + - mysql + - postgres + - mssql From d49d991d3ceeebd39800947b6f88cec440e169f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Budnik?= Date: Wed, 1 Sep 2021 09:55:00 +0200 Subject: [PATCH 3/4] path fix --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3e6843b..fb6c653 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ before_script: - docker-compose -f test/docker-compose-it.yaml up -d script: - "./coverage.sh" -- "./test/./test/http-integration-tests.sh" +- "./test/http-integration-tests.sh" after_success: - bash <(curl -s https://codecov.io/bash) env: From 820084dbc2826ee17ecbcea79a16a0aa6b6127d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Budnik?= Date: Wed, 1 Sep 2021 10:12:28 +0200 Subject: [PATCH 4/4] strict jq errors on Travis... missing jq filters added --- test/http-integration-tests.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/http-integration-tests.sh b/test/http-integration-tests.sh index 0d5a70f..49efea1 100755 --- a/test/http-integration-tests.sh +++ b/test/http-integration-tests.sh @@ -97,7 +97,7 @@ if [ "$version_create_name" != "$VERSION_NAME" ]; then exit 1 fi echo "New version successfully created" -echo $version_create | jq +echo $version_create | jq '.' # 4. Fetch migrator versions - will now contain version created above @@ -155,7 +155,7 @@ if [ "$tenant_create_version_name" != "$VERSION_NAME" ]; then exit 1 fi echo "New tenant successfully created" -echo $tenant_create | jq +echo $tenant_create | jq '.' # 6. Fetch tenants - will now contain tenant create above @@ -176,4 +176,4 @@ echo "-------------------------------------------------------------------------- echo "All good!" -cleanup \ No newline at end of file +cleanup