Skip to content

Commit

Permalink
Add schema migration test
Browse files Browse the repository at this point in the history
Signed-off-by: Brad Davidson <[email protected]>
  • Loading branch information
brandond committed Mar 1, 2024
1 parent 57fbf01 commit 540ea9e
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions scripts/test
Original file line number Diff line number Diff line change
Expand Up @@ -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 $?"

Expand Down
1 change: 1 addition & 0 deletions scripts/test-helpers
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
62 changes: 62 additions & 0 deletions scripts/test-run-schema-migration
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 540ea9e

Please sign in to comment.