1#!/bin/bash
2# Copyright 2020 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# Fail on any error
17set -eo pipefail
18
19# Display commands being run
20set -x
21
22export SPANNER_EMULATOR_HOST=localhost:9010
23export GCLOUD_TESTS_GOLANG_PROJECT_ID=emulator-test-project
24echo "Running the Cloud Spanner emulator: $SPANNER_EMULATOR_HOST";
25
26# Download the emulator
27EMULATOR_VERSION=0.8.0
28wget https://storage.googleapis.com/cloud-spanner-emulator/releases/${EMULATOR_VERSION}/cloud-spanner-emulator_linux_amd64-${EMULATOR_VERSION}.tar.gz
29tar zxvf cloud-spanner-emulator_linux_amd64-${EMULATOR_VERSION}.tar.gz
30chmod u+x emulator_main
31
32# Start the emulator
33./emulator_main --host_port $SPANNER_EMULATOR_HOST &
34
35EMULATOR_PID=$!
36
37# Stop the emulator & clean the environment variable
38function cleanup() {
39    kill -2 $EMULATOR_PID
40    unset SPANNER_EMULATOR_HOST
41    unset GCLOUD_TESTS_GOLANG_PROJECT_ID
42    echo "Cleanup the emulator";
43}
44trap cleanup EXIT
45
46go test -v -timeout 10m ./... -run '^TestIntegration_' 2>&1 | tee sponge_log.log
47