sourcegraph/testing/codeintel_integration_test.sh
Jean-Hadrien Chabran 7fdf85a653
bzl+doc: improve and document how to write a server integration test (#53673)
We recently refactored how to run server integration tests with Bazel,
so they are standalone tasks requiring no prior setup to run them.

This PR takes this further, by providing a macro named
`server_integration_test` to be used in `testing/BUILD.bazel` to
centralize all test runners/wrapper to run those tests who are targeting
the server image.

It also adds a how-to describing how they work at high level as well as
step-by-step guide to help teammates to start writing or maintaining the
existing scripts.

@peterguy I'm tagging you here, as per this
[message](https://sourcegraph.slack.com/archives/C04MYFW01NV/p1686850329953539?thread_ts=1686661082.758009&cid=C04MYFW01NV)
where it looked you needed to do exactly this. This makes it sound
you're the perfect reviewer for this bit of documentation.

## Test plan

<!-- All pull requests REQUIRE a test plan:
https://docs.sourcegraph.com/dev/background-information/testing_principles
-->

CI + local preview for the docs.

---------

Co-authored-by: Dave Try <davetry@gmail.com>
2023-06-19 17:44:01 +00:00

54 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bash
set -eu
source ./testing/tools/integration_runner.sh || exit 1
tarball="$1"
image_name="$2"
init_sg="$3"
src_cli="$4"
cmd_download="$5"
cmd_clear="$6"
cmd_upload="$7"
cmd_query="$8"
testdata_repos="$9"
url="http://localhost:$PORT"
SOURCEGRAPH_BASE_URL="$url"
export SOURCEGRAPH_BASE_URL
ALLOW_SINGLE_DOCKER_CODE_INSIGHTS="true"
export ALLOW_SINGLE_DOCKER_CODE_INSIGHTS
run_server_image "$tarball" "$image_name" "$url" "$PORT"
echo '--- Initializing instance'
"$init_sg" initSG -sg_envrc="./sg_envrc"
# shellcheck disable=SC1091
source ./sg_envrc
echo '--- :horse: Running init-sg addRepos'
"$init_sg" addRepos -config "$testdata_repos"
echo '--- :brain: Running the test suite'
echo '--- :zero: downloading test data from GCS'
"$cmd_download"
echo '--- :one: clearing existing state'
"$cmd_clear"
# src-cli must be in the PATH for upload to find it.
echo '--- :two: integration test
./dev/codeintel-qa/cmd/upload'
"$cmd_upload" --timeout=5m --index-dir="./dev/codeintel-qa/testdata/indexes" --src-path="$(rlocation "$src_cli")"
echo '--- :three: integration test ./dev/codeintel-qa/cmd/query'
"$cmd_query" --index-dir="./dev/codeintel-qa/testdata/indexes"
echo "--- done"