2021-03-31 12:58:12 +02:00
|
|
|
#!/usr/bin/env bash
|
2020-09-29 14:47:47 +02:00
|
|
|
# This script is designed for developers who want to test their code
|
|
|
|
# against Complement.
|
|
|
|
#
|
|
|
|
# It makes a Synapse image which represents the current checkout,
|
2021-03-31 12:58:12 +02:00
|
|
|
# builds a synapse-complement image on top, then runs tests with it.
|
|
|
|
#
|
|
|
|
# By default the script will fetch the latest Complement master branch and
|
|
|
|
# run tests with that. This can be overridden to use a custom Complement
|
|
|
|
# checkout by setting the COMPLEMENT_DIR environment variable to the
|
|
|
|
# filepath of a local Complement checkout.
|
|
|
|
#
|
2021-05-24 21:32:45 +02:00
|
|
|
# By default Synapse is run in monolith mode. This can be overridden by
|
|
|
|
# setting the WORKERS environment variable.
|
|
|
|
#
|
2021-03-31 12:58:12 +02:00
|
|
|
# A regular expression of test method names can be supplied as the first
|
|
|
|
# argument to the script. Complement will then only run those tests. If
|
|
|
|
# no regex is supplied, all tests are run. For example;
|
|
|
|
#
|
|
|
|
# ./complement.sh "TestOutboundFederation(Profile|Send)"
|
|
|
|
#
|
|
|
|
|
|
|
|
# Exit if a line returns a non-zero exit code
|
|
|
|
set -e
|
2020-09-29 14:47:47 +02:00
|
|
|
|
2021-03-31 12:58:12 +02:00
|
|
|
# Change to the repository root
|
2020-09-29 14:47:47 +02:00
|
|
|
cd "$(dirname $0)/.."
|
|
|
|
|
2021-03-31 12:58:12 +02:00
|
|
|
# Check for a user-specified Complement checkout
|
|
|
|
if [[ -z "$COMPLEMENT_DIR" ]]; then
|
|
|
|
echo "COMPLEMENT_DIR not set. Fetching the latest Complement checkout..."
|
|
|
|
wget -Nq https://github.com/matrix-org/complement/archive/master.tar.gz
|
|
|
|
tar -xzf master.tar.gz
|
|
|
|
COMPLEMENT_DIR=complement-master
|
|
|
|
echo "Checkout available at 'complement-master'"
|
|
|
|
fi
|
|
|
|
|
2021-05-24 21:32:45 +02:00
|
|
|
# If we're using workers, modify the docker files slightly.
|
|
|
|
if [[ -n "$WORKERS" ]]; then
|
|
|
|
BASE_IMAGE=matrixdotorg/synapse-workers
|
|
|
|
BASE_DOCKERFILE=docker/Dockerfile-workers
|
|
|
|
export COMPLEMENT_BASE_IMAGE=complement-synapse-workers
|
|
|
|
COMPLEMENT_DOCKERFILE=SynapseWorkers.Dockerfile
|
|
|
|
# And provide some more configuration to complement.
|
|
|
|
export COMPLEMENT_CA=true
|
|
|
|
export COMPLEMENT_VERSION_CHECK_ITERATIONS=500
|
|
|
|
else
|
|
|
|
BASE_IMAGE=matrixdotorg/synapse
|
|
|
|
BASE_DOCKERFILE=docker/Dockerfile
|
|
|
|
export COMPLEMENT_BASE_IMAGE=complement-synapse
|
|
|
|
COMPLEMENT_DOCKERFILE=Synapse.Dockerfile
|
|
|
|
fi
|
|
|
|
|
2020-09-29 14:47:47 +02:00
|
|
|
# Build the base Synapse image from the local checkout
|
2021-05-24 21:32:45 +02:00
|
|
|
docker build -t $BASE_IMAGE -f "$BASE_DOCKERFILE" .
|
2021-03-31 12:58:12 +02:00
|
|
|
# Build the Synapse monolith image from Complement, based on the above image we just built
|
2021-05-24 21:32:45 +02:00
|
|
|
docker build -t $COMPLEMENT_BASE_IMAGE -f "$COMPLEMENT_DIR/dockerfiles/$COMPLEMENT_DOCKERFILE" "$COMPLEMENT_DIR/dockerfiles"
|
2020-09-29 14:47:47 +02:00
|
|
|
|
2021-03-31 12:58:12 +02:00
|
|
|
cd "$COMPLEMENT_DIR"
|
2020-09-29 14:47:47 +02:00
|
|
|
|
2021-03-31 12:58:12 +02:00
|
|
|
EXTRA_COMPLEMENT_ARGS=""
|
|
|
|
if [[ -n "$1" ]]; then
|
|
|
|
# A test name regex has been set, supply it to Complement
|
|
|
|
EXTRA_COMPLEMENT_ARGS+="-run $1 "
|
|
|
|
fi
|
2020-09-29 14:47:47 +02:00
|
|
|
|
2021-03-31 12:58:12 +02:00
|
|
|
# Run the tests!
|
2021-07-22 22:19:30 +02:00
|
|
|
go test -v -tags synapse_blacklist,msc2946,msc3083,msc2403 -count=1 $EXTRA_COMPLEMENT_ARGS ./tests
|