Debian Codegraph @

kokoro/gcp_ubuntu/gomod/run_tests.sh

raw symbols SCIP
1 #!/bin/bash
2 # Copyright 2022 Google LLC
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 ################################################################################
16
17 # By default when run locally this script runs the command below directly on the
18 # host. The CONTAINER_IMAGE variable can be set to run on a custom container
19 # image for local testing. E.g.:
20 #
21 # CONTAINER_IMAGE="gcr.io/tink-test-infrastructure/linux-tink-go-base:latest" \
22 # sh ./kokoro/gcp_ubuntu/gomod/run_tests.sh
23
24 # Generated with openssl rand -hex 10
25 echo "==========================================================================="
26 echo "Tink Script ID: c4ca71c9525173f869e1 (to quickly find the script from logs)"
27 echo "==========================================================================="
28
29 set -euo pipefail
30
31 RUN_COMMAND_ARGS=()
32 if [[ -n "${KOKORO_ROOT:-}" ]]; then
33 readonly TINK_BASE_DIR="$(echo "${KOKORO_ARTIFACTS_DIR}"/git*)"
34 cd "${TINK_BASE_DIR}/tink_go_hcvault"
35 source "kokoro/testutils/go_test_container_images.sh"
36 CONTAINER_IMAGE="${TINK_GO_BASE_IMAGE}"
37 RUN_COMMAND_ARGS+=( -k "${TINK_GCR_SERVICE_KEY}" )
38 fi
39 readonly CONTAINER_IMAGE
40
41 if [[ -n "${CONTAINER_IMAGE:-}" ]]; then
42 RUN_COMMAND_ARGS+=( -c "${CONTAINER_IMAGE}" )
43 fi
44
45 ./kokoro/testutils/docker_execute.sh "${RUN_COMMAND_ARGS[@]}" \
46 ./kokoro/testutils/check_go_generated_files_up_to_date.sh .
47
48 cat <<EOF > env_variables.txt
49 GOARCH
50 EOF
51
52 RUN_COMMAND_ARGS+=( -e env_variables.txt )
53
54 readonly RUN_COMMAND_ARGS
55
56 cat <<EOF > _run_test.sh
57 #!/bin/bash
58 set -euo pipefail
59
60 set -x
61 go build -v ./...
62 go test -v ./...
63 EOF
64
65 chmod +x _run_test.sh
66
67 # Run cleanup on EXIT.
68 trap cleanup EXIT
69
70 cleanup() {
71 rm -rf _run_test.sh
72 rm -rf env_variables.txt
73 }
74
75 ./kokoro/testutils/docker_execute.sh "${RUN_COMMAND_ARGS[@]}" \
76 ./_run_test.sh