1
0

complement.sh 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/usr/bin/env bash
  2. # This script is designed for developers who want to test their code
  3. # against Complement.
  4. #
  5. # It makes a Synapse image which represents the current checkout,
  6. # builds a synapse-complement image on top, then runs tests with it.
  7. #
  8. # By default the script will fetch the latest Complement main branch and
  9. # run tests with that. This can be overridden to use a custom Complement
  10. # checkout by setting the COMPLEMENT_DIR environment variable to the
  11. # filepath of a local Complement checkout or by setting the COMPLEMENT_REF
  12. # environment variable to pull a different branch or commit.
  13. #
  14. # By default Synapse is run in monolith mode. This can be overridden by
  15. # setting the WORKERS environment variable.
  16. #
  17. # A regular expression of test method names can be supplied as the first
  18. # argument to the script. Complement will then only run those tests. If
  19. # no regex is supplied, all tests are run. For example;
  20. #
  21. # ./complement.sh "TestOutboundFederation(Profile|Send)"
  22. #
  23. # Exit if a line returns a non-zero exit code
  24. set -e
  25. # enable buildkit for the docker builds
  26. export DOCKER_BUILDKIT=1
  27. # Change to the repository root
  28. cd "$(dirname $0)/.."
  29. # Check for a user-specified Complement checkout
  30. if [[ -z "$COMPLEMENT_DIR" ]]; then
  31. COMPLEMENT_REF=${COMPLEMENT_REF:-main}
  32. echo "COMPLEMENT_DIR not set. Fetching Complement checkout from ${COMPLEMENT_REF}..."
  33. wget -Nq https://github.com/matrix-org/complement/archive/${COMPLEMENT_REF}.tar.gz
  34. tar -xzf ${COMPLEMENT_REF}.tar.gz
  35. COMPLEMENT_DIR=complement-${COMPLEMENT_REF}
  36. echo "Checkout available at 'complement-${COMPLEMENT_REF}'"
  37. fi
  38. # Build the base Synapse image from the local checkout
  39. docker build -t matrixdotorg/synapse -f "docker/Dockerfile" .
  40. # If we're using workers, modify the docker files slightly.
  41. if [[ -n "$WORKERS" ]]; then
  42. # Build the workers docker image (from the base Synapse image).
  43. docker build -t matrixdotorg/synapse-workers -f "docker/Dockerfile-workers" .
  44. export COMPLEMENT_BASE_IMAGE=complement-synapse-workers
  45. COMPLEMENT_DOCKERFILE=SynapseWorkers.Dockerfile
  46. # And provide some more configuration to complement.
  47. export COMPLEMENT_CA=true
  48. export COMPLEMENT_SPAWN_HS_TIMEOUT_SECS=25
  49. else
  50. export COMPLEMENT_BASE_IMAGE=complement-synapse
  51. COMPLEMENT_DOCKERFILE=Synapse.Dockerfile
  52. fi
  53. # Build the Complement image from the Synapse image we just built.
  54. docker build -t $COMPLEMENT_BASE_IMAGE -f "$COMPLEMENT_DIR/dockerfiles/$COMPLEMENT_DOCKERFILE" "$COMPLEMENT_DIR/dockerfiles"
  55. cd "$COMPLEMENT_DIR"
  56. EXTRA_COMPLEMENT_ARGS=""
  57. if [[ -n "$1" ]]; then
  58. # A test name regex has been set, supply it to Complement
  59. EXTRA_COMPLEMENT_ARGS+="-run $1 "
  60. fi
  61. # Run the tests!
  62. echo "Images built; running complement"
  63. go test -v -tags synapse_blacklist,msc2403,msc2716,msc3030 -count=1 $EXTRA_COMPLEMENT_ARGS ./tests/...