Skip to content

Commit

Permalink
feat(ci): run upgrade tests for multiple "old" versions
Browse files Browse the repository at this point in the history
Currently only 2.8.0 is used to run migration tests, all the way up to
the "new" (current) version. This means that only features that are
shared across all versions from "old" to "new" can be tested, e.g. a
plugin that is not available in `2.8.0` cannot be configured and used
in migration tests.

This commit introduces a list of "old_versions" and repeats the tests
for each. Tests can use the `OLD_KONG_VERSION` environment variable to
determine whether they should execute for the current version.
  • Loading branch information
samugi committed Feb 9, 2024
1 parent 82d8c7f commit bc9e00b
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 25 deletions.
2 changes: 2 additions & 0 deletions scripts/upgrade-tests/source-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
2.8.0
3.4.0
51 changes: 29 additions & 22 deletions scripts/upgrade-tests/test-upgrade-path.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,6 @@ set -e

trap "echo exiting because of error" 0

function get_current_version() {
local image_tag=$1
local version_from_rockspec=$(perl -ne 'print "$1\n" if (/^\s*tag = "(.*)"/)' kong*.rockspec)
if docker pull $image_tag:$version_from_rockspec >/dev/null 2>/dev/null
then
echo $version_from_rockspec-ubuntu
else
echo master-ubuntu
fi
}

export OLD_KONG_VERSION=2.8.0
export OLD_KONG_IMAGE=kong:$OLD_KONG_VERSION-ubuntu
export KONG_PG_HOST=localhost
export KONG_TEST_PG_HOST=localhost

Expand Down Expand Up @@ -91,13 +78,19 @@ function prepare_container() {
}

function build_containers() {
# Kong version >= 3.3 moved non Bazel-built dev setup to make dev-legacy
if (( $(echo "$OLD_KONG_VERSION" | sed 's/\.//g') >= 330 )); then
old_make_target="dev-legacy"
else
old_make_target="dev"
fi

echo "Building containers"

[ -d worktree/$OLD_KONG_VERSION ] || git worktree add worktree/$OLD_KONG_VERSION $OLD_KONG_VERSION
$COMPOSE up --wait
prepare_container $OLD_CONTAINER
docker exec -w /kong $OLD_CONTAINER make dev CRYPTO_DIR=/usr/local/kong
# Kong version >= 3.3 moved non Bazel-built dev setup to make dev-legacy
docker exec -w /kong $OLD_CONTAINER make $old_make_target CRYPTO_DIR=/usr/local/kong
make dev-legacy CRYPTO_DIR=/usr/local/kong
}

Expand Down Expand Up @@ -155,7 +148,7 @@ function initialize_test_list() {

function run_tests() {
# Run the tests
BUSTED_ENV="env KONG_DATABASE=$1 KONG_DNS_RESOLVER= KONG_TEST_PG_DATABASE=kong"
BUSTED_ENV="env KONG_DATABASE=$1 KONG_DNS_RESOLVER= KONG_TEST_PG_DATABASE=kong OLD_KONG_VERSION=$OLD_KONG_VERSION"

shift

Expand Down Expand Up @@ -186,15 +179,29 @@ function run_tests() {
}

function cleanup() {
git worktree remove worktree/$OLD_KONG_VERSION --force
sudo git worktree remove worktree/$OLD_KONG_VERSION --force
$COMPOSE down
deactivate
}


source $venv_script
build_containers
initialize_test_list
run_tests postgres
[ -z "$UPGRADE_ENV_PREFIX" ] && cleanup

# Load supported "old" versions to run migration tests against
old_versions=()
mapfile -t old_versions < "scripts/upgrade-tests/source-versions"

for old_version in "${old_versions[@]}"; do
export OLD_KONG_VERSION=$old_version
export OLD_KONG_IMAGE=kong:$OLD_KONG_VERSION-ubuntu

echo "Running tests using $OLD_KONG_VERSION as \"old version\" of Kong"

build_containers
initialize_test_list
run_tests postgres
[ -z "$UPGRADE_ENV_PREFIX" ] && cleanup
done

deactivate

trap "" 0
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ local uh = require "spec.upgrade_helpers"
-- to test the migration process. do not change it to use dynamic port.
local HTTP_PORT = 29100

describe("http-log plugin migration", function()
local OLD_KONG_VERSION = os.getenv("OLD_KONG_VERSION")
local handler = OLD_KONG_VERSION:sub(1,3) == "2.8" and describe or pending

handler("http-log plugin migration", function()
local mock
lazy_setup(function()
assert(uh.start_kong())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@

local uh = require "spec/upgrade_helpers"

describe("post-function plugin migration", function()

local OLD_KONG_VERSION = os.getenv("OLD_KONG_VERSION")
local handler = OLD_KONG_VERSION:sub(1,3) == "2.8" and describe or pending


handler("post-function plugin migration", function()

lazy_setup(function()
assert(uh.start_kong())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@

local uh = require "spec/upgrade_helpers"

describe("pre-function plugin migration", function()
local OLD_KONG_VERSION = os.getenv("OLD_KONG_VERSION")
local handler = OLD_KONG_VERSION:sub(1,3) == "2.8" and describe or pending

handler("pre-function plugin migration", function()

lazy_setup(function()
assert(uh.start_kong())
Expand Down

0 comments on commit bc9e00b

Please sign in to comment.