complement.sh 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 master 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.
  12. #
  13. # By default Synapse is run in monolith mode. This can be overridden by
  14. # setting the WORKERS environment variable.
  15. #
  16. # A regular expression of test method names can be supplied as the first
  17. # argument to the script. Complement will then only run those tests. If
  18. # no regex is supplied, all tests are run. For example;
  19. #
  20. # ./complement.sh "TestOutboundFederation(Profile|Send)"
  21. #
  22. # Exit if a line returns a non-zero exit code
  23. set -e
  24. # Change to the repository root
  25. cd "$(dirname $0)/.."
  26. # Check for a user-specified Complement checkout
  27. if [[ -z "$COMPLEMENT_DIR" ]]; then
  28. echo "COMPLEMENT_DIR not set. Fetching the latest Complement checkout..."
  29. wget -Nq https://github.com/matrix-org/complement/archive/master.tar.gz
  30. tar -xzf master.tar.gz
  31. COMPLEMENT_DIR=complement-master
  32. echo "Checkout available at 'complement-master'"
  33. fi
  34. # Build the base Synapse image from the local checkout
  35. docker build -t matrixdotorg/synapse -f "docker/Dockerfile" .
  36. # If we're using workers, modify the docker files slightly.
  37. if [[ -n "$WORKERS" ]]; then
  38. # Build the workers docker image (from the base Synapse image).
  39. docker build -t matrixdotorg/synapse-workers -f "docker/Dockerfile-workers" .
  40. export COMPLEMENT_BASE_IMAGE=complement-synapse-workers
  41. COMPLEMENT_DOCKERFILE=SynapseWorkers.Dockerfile
  42. # And provide some more configuration to complement.
  43. export COMPLEMENT_CA=true
  44. export COMPLEMENT_VERSION_CHECK_ITERATIONS=500
  45. else
  46. export COMPLEMENT_BASE_IMAGE=complement-synapse
  47. COMPLEMENT_DOCKERFILE=Synapse.Dockerfile
  48. fi
  49. # Build the Complement image from the Synapse image we just built.
  50. docker build -t $COMPLEMENT_BASE_IMAGE -f "$COMPLEMENT_DIR/dockerfiles/$COMPLEMENT_DOCKERFILE" "$COMPLEMENT_DIR/dockerfiles"
  51. cd "$COMPLEMENT_DIR"
  52. EXTRA_COMPLEMENT_ARGS=""
  53. if [[ -n "$1" ]]; then
  54. # A test name regex has been set, supply it to Complement
  55. EXTRA_COMPLEMENT_ARGS+="-run $1 "
  56. fi
  57. # Run the tests!
  58. go test -v -tags synapse_blacklist,msc2946,msc3083,msc2403,msc2716 -count=1 $EXTRA_COMPLEMENT_ARGS ./tests/...