From 540ea9e3637a52c0759ed584317876e60563604a Mon Sep 17 00:00:00 2001 From: Brad Davidson Date: Wed, 7 Feb 2024 19:58:16 +0000 Subject: [PATCH] Add schema migration test Signed-off-by: Brad Davidson --- .drone.yml | 17 +++++++++ scripts/test | 3 ++ scripts/test-helpers | 1 + scripts/test-run-schema-migration | 62 +++++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+) create mode 100755 scripts/test-run-schema-migration diff --git a/.drone.yml b/.drone.yml index 0209498f..8d0490b3 100644 --- a/.drone.yml +++ b/.drone.yml @@ -148,6 +148,23 @@ steps: event: - pull_request +- name: test-schema-migration + image: rancher/dapper:v0.6.0 + depends_on: + - build + - test-image + commands: + - > + docker run -i -e ARCH -e REPO -e TAG -e DRONE_TAG -e IMAGE_NAME + -v /var/run/docker.sock:/var/run/docker.sock -v kine-cache:/go/src/github.com/k3s-io/kine/.cache + --privileged kine:test-${DRONE_COMMIT} "./scripts/test schema-migration" + volumes: + - name: docker + path: /var/run/docker.sock + when: + event: + - pull_request + - name: test-nats image: rancher/dapper:v0.6.0 depends_on: diff --git a/scripts/test b/scripts/test index 72af7b11..14814399 100755 --- a/scripts/test +++ b/scripts/test @@ -31,6 +31,9 @@ echo "Did test-run-postgres $?" . ./scripts/test-run-cockroachdb echo "Did test-run-cockroachdb $?" +. ./scripts/test-run-schema-migration +echo "Did test-run-schema-migration $?" + . ./scripts/test-run-nats echo "did test-nats $?" diff --git a/scripts/test-helpers b/scripts/test-helpers index 393028ca..ff8ba8a8 100755 --- a/scripts/test-helpers +++ b/scripts/test-helpers @@ -247,6 +247,7 @@ provision-kine() { docker container run \ -d --name $name \ + $KINE_ENV \ $KINE_IMAGE --endpoint $KINE_ENDPOINT local ip=$(docker container inspect --format '{{.NetworkSettings.IPAddress}}' $name | tee $TEST_DIR/kine/$count/metadata/ip) diff --git a/scripts/test-run-schema-migration b/scripts/test-run-schema-migration new file mode 100755 index 00000000..5836949c --- /dev/null +++ b/scripts/test-run-schema-migration @@ -0,0 +1,62 @@ +#!/bin/bash + +start-test() { + local ip=$(cat $TEST_DIR/databases/*/metadata/ip) + local port=$(cat $TEST_DIR/databases/*/metadata/port) + local pass=$(cat $TEST_DIR/databases/*/metadata/password) + local image=$(cat $TEST_DIR/databases/*/metadata/image) + DB_CONNECTION_TEST=" + docker run --rm + --name connection-test + $image + mysql + --host=$ip + --port=$port + --user=root + --password=$pass + --execute=status" \ + timeout --foreground 1m bash -c "wait-for-db-connection" + KINE_IMAGE=docker.io/rancher/kine:v0.11.4 KINE_ENDPOINT="mysql://root:$pass@tcp($ip:$port)/kine" provision-kine + sleep 10 + for container in $(cat $TEST_DIR/kine/*/metadata/name); do + docker container rm -f -v $container + done + rm -rf $TEST_DIR/kine/* + KINE_IMAGE=$IMAGE KINE_ENDPOINT="mysql://root:$pass@tcp($ip:$port)/kine" KINE_ENV="-e KINE_SCHEMA_MIGRATION=1" provision-kine + local kine_url=$(cat $TEST_DIR/kine/*/metadata/url) + K3S_DATASTORE_ENDPOINT=$kine_url provision-cluster +} +export -f start-test + +LABEL=mariadb-10.11-migration DB_PASSWORD_ENV=MYSQL_ROOT_PASSWORD DB_IMAGE=docker.io/library/mariadb:10.11 run-test + +start-test() { + local ip=$(cat $TEST_DIR/databases/*/metadata/ip) + local port=$(cat $TEST_DIR/databases/*/metadata/port) + local pass=$(cat $TEST_DIR/databases/*/metadata/password) + local image=$(cat $TEST_DIR/databases/*/metadata/image) + DB_CONNECTION_TEST=" + docker run --rm + --name connection-test + -e PGPASSWORD=$pass + $image + psql + --host=$ip + --port=$port + --username=postgres + --command=\\conninfo" \ + timeout --foreground 1m bash -c "wait-for-db-connection" + KINE_IMAGE=docker.io/rancher/kine:v0.11.4 KINE_ENDPOINT="postgres://postgres:$pass@$ip:$port/postgres?sslmode=disable" provision-kine + sleep 10 + for container in $(cat $TEST_DIR/kine/*/metadata/name); do + docker container rm -f -v $container + done + rm -rf $TEST_DIR/kine/* + KINE_IMAGE=$IMAGE KINE_ENDPOINT="postgres://postgres:$pass@$ip:$port/postgres?sslmode=disable" KINE_ENV="-e KINE_SCHEMA_MIGRATION=1" provision-kine + local kine_url=$(cat $TEST_DIR/kine/*/metadata/url) + K3S_DATASTORE_ENDPOINT=$kine_url provision-cluster +} +export -f start-test + +LABEL=postgres-15.4-migration DB_PASSWORD_ENV=POSTGRES_PASSWORD DB_IMAGE=docker.io/library/postgres:15.4 run-test +