2019-06-11 14:55:53 +00:00
|
|
|
description: run go tests
|
|
|
|
parameters:
|
|
|
|
extra_flags:
|
|
|
|
type: string
|
|
|
|
default: ""
|
2020-05-01 16:26:26 +00:00
|
|
|
log_dir:
|
|
|
|
type: string
|
|
|
|
default: "/tmp/testlogs"
|
2021-04-06 13:42:14 +00:00
|
|
|
cache_dir:
|
|
|
|
type: string
|
|
|
|
default: /tmp/go-cache
|
|
|
|
save_cache:
|
|
|
|
type: boolean
|
|
|
|
default: false
|
2020-09-15 14:01:26 +00:00
|
|
|
go_image:
|
|
|
|
type: string
|
2021-04-06 13:42:14 +00:00
|
|
|
default: "docker.mirror.hashicorp.services/circleci/golang:1.15.11-buster"
|
2020-09-15 14:01:26 +00:00
|
|
|
use_docker:
|
|
|
|
type: boolean
|
|
|
|
default: false
|
2019-06-11 14:55:53 +00:00
|
|
|
steps:
|
2021-04-06 13:42:14 +00:00
|
|
|
- run:
|
|
|
|
name: Compute test cache key
|
|
|
|
command: |
|
|
|
|
TZ=GMT date '+%Y%m%d' > /tmp/go-cache-key
|
|
|
|
- restore_cache:
|
|
|
|
keys:
|
|
|
|
- go-test-cache-date-v1-{{ checksum "/tmp/go-cache-key" }}
|
2019-06-11 14:55:53 +00:00
|
|
|
- run:
|
|
|
|
name: Run Go tests
|
2019-11-12 14:03:42 +00:00
|
|
|
no_output_timeout: 60m
|
2019-06-11 14:55:53 +00:00
|
|
|
command: |
|
2019-07-24 13:13:41 +00:00
|
|
|
set -x
|
2019-06-11 14:55:53 +00:00
|
|
|
|
2020-07-21 14:50:28 +00:00
|
|
|
case "<< parameters.extra_flags >>" in
|
2020-09-15 14:01:26 +00:00
|
|
|
*-race*) export VAULT_CI_GO_TEST_RACE=1;;
|
2020-07-21 14:50:28 +00:00
|
|
|
esac
|
|
|
|
|
2019-06-11 14:55:53 +00:00
|
|
|
# Install CircleCI CLI
|
|
|
|
curl -sSL \
|
|
|
|
"https://github.com/CircleCI-Public/circleci-cli/releases/download/v${CIRCLECI_CLI_VERSION}/circleci-cli_${CIRCLECI_CLI_VERSION}_linux_amd64.tar.gz" \
|
|
|
|
| sudo tar --overwrite -xz \
|
|
|
|
-C /usr/local/bin \
|
|
|
|
"circleci-cli_${CIRCLECI_CLI_VERSION}_linux_amd64/circleci"
|
|
|
|
|
2020-09-15 14:01:26 +00:00
|
|
|
USE_DOCKER=0
|
|
|
|
<<# parameters.use_docker >>
|
|
|
|
USE_DOCKER=1
|
|
|
|
<</ parameters.use_docker >>
|
2019-06-11 14:55:53 +00:00
|
|
|
|
2020-09-15 14:01:26 +00:00
|
|
|
# Split Go tests by prior test times. If use_docker is true, only run
|
|
|
|
# tests that depend on docker, otherwise only those that don't.
|
|
|
|
if [ $USE_DOCKER == 1 ]; then
|
|
|
|
package_names=$(go list -test -json ./... |
|
|
|
|
jq -r 'select(.Deps != null) |
|
|
|
|
select(any(.Deps[] ; contains("github.com/hashicorp/vault/helper/testhelpers/docker"))) |
|
|
|
|
.ForTest | select(. != null)' |
|
|
|
|
sort -u | circleci tests split --split-by=timings --timings-type=classname)
|
|
|
|
else
|
|
|
|
package_names=$(go list -test -json ./... |
|
|
|
|
jq -r 'select(.Deps != null) |
|
|
|
|
select(all(.Deps[] ; contains("github.com/hashicorp/vault/helper/testhelpers/docker")|not)) |
|
|
|
|
.ForTest | select(. != null)' |
|
|
|
|
sort -u | circleci tests split --split-by=timings --timings-type=classname)
|
|
|
|
fi
|
|
|
|
|
|
|
|
# After running tests split step, we are now running the following steps
|
|
|
|
# in multiple different containers, each getting a different subset of
|
|
|
|
# the test packages in their package_names variable. Each container
|
|
|
|
# has its own remote docker VM.
|
2019-06-11 14:55:53 +00:00
|
|
|
|
|
|
|
make prep
|
|
|
|
mkdir -p test-results/go-test
|
2020-09-15 14:01:26 +00:00
|
|
|
|
|
|
|
# Create a docker network for our testcontainer
|
|
|
|
if [ $USE_DOCKER == 1 ]; then
|
2020-09-17 19:24:31 +00:00
|
|
|
# Despite the fact that we're using a circleci image (thus getting the
|
|
|
|
# version they chose for the docker cli) and that we're specifying a
|
|
|
|
# docker version to use for the remote docker instances, we occasionally
|
|
|
|
# see "client version too new, max supported version 1.39" errors for
|
|
|
|
# reasons unclear.
|
|
|
|
export DOCKER_API_VERSION=1.39
|
|
|
|
|
2020-09-15 14:01:26 +00:00
|
|
|
export TEST_DOCKER_NETWORK_ID=$(docker network list -q -f 'name=vaulttest')
|
|
|
|
if [ -z $TEST_DOCKER_NETWORK_ID ]; then
|
|
|
|
TEST_DOCKER_NETWORK_ID=$(docker network create vaulttest)
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Start a docker testcontainer to run the tests in
|
|
|
|
docker run -d -e TEST_DOCKER_NETWORK_ID \
|
|
|
|
-e DOCKER_CERT_PATH -e DOCKER_HOST -e DOCKER_MACHINE_NAME -e DOCKER_TLS_VERIFY -e NO_PROXY \
|
|
|
|
-e VAULT_TEST_LOG_DIR=<< parameters.log_dir >> \
|
|
|
|
--network vaulttest --name \
|
|
|
|
testcontainer << parameters.go_image >> \
|
|
|
|
tail -f /dev/null
|
|
|
|
|
|
|
|
# Run tests
|
2021-04-06 13:42:14 +00:00
|
|
|
test -d << parameters.cache_dir >> && docker cp << parameters.cache_dir >> testcontainer:/tmp/gocache
|
2020-09-15 14:01:26 +00:00
|
|
|
docker exec testcontainer sh -c 'mkdir -p /go/src/github.com/hashicorp/vault'
|
|
|
|
docker cp . testcontainer:/go/src/github.com/hashicorp/vault/
|
|
|
|
docker cp $DOCKER_CERT_PATH/ testcontainer:$DOCKER_CERT_PATH
|
|
|
|
|
|
|
|
docker exec -w /go/src/github.com/hashicorp/vault/ \
|
2021-04-06 13:42:14 +00:00
|
|
|
-e GO111MODULE -e CIRCLECI -e GOCACHE=/tmp/gocache -e VAULT_CI_GO_TEST_RACE \
|
2020-09-15 14:01:26 +00:00
|
|
|
testcontainer \
|
|
|
|
gotestsum --format=short-verbose \
|
|
|
|
--junitfile test-results/go-test/results.xml \
|
|
|
|
--jsonfile test-results/go-test/results.json \
|
|
|
|
-- \
|
|
|
|
-tags "${GO_TAGS}" \
|
2020-09-15 16:03:39 +00:00
|
|
|
-timeout=60m \
|
2020-09-15 14:01:26 +00:00
|
|
|
-parallel=20 \
|
|
|
|
<< parameters.extra_flags >> \
|
|
|
|
${package_names}
|
|
|
|
else
|
2021-04-06 13:42:14 +00:00
|
|
|
GOCACHE=<< parameters.cache_dir >> \
|
|
|
|
gotestsum --format=short-verbose \
|
|
|
|
--junitfile test-results/go-test/results.xml \
|
|
|
|
--jsonfile test-results/go-test/results.json \
|
|
|
|
-- \
|
|
|
|
-tags "${GO_TAGS}" \
|
|
|
|
-timeout=60m \
|
|
|
|
-parallel=20 \
|
|
|
|
<< parameters.extra_flags >> \
|
|
|
|
${package_names}
|
2020-09-15 14:01:26 +00:00
|
|
|
fi
|
2019-06-11 14:55:53 +00:00
|
|
|
|
2020-09-15 14:01:26 +00:00
|
|
|
- when:
|
|
|
|
condition: << parameters.use_docker >>
|
|
|
|
steps:
|
|
|
|
- run:
|
|
|
|
name: Copy test results
|
|
|
|
when: always
|
|
|
|
command: |
|
|
|
|
docker cp testcontainer:/go/src/github.com/hashicorp/vault/test-results .
|
2021-04-06 13:42:14 +00:00
|
|
|
docker cp testcontainer:/tmp/gocache << parameters.cache_dir >>
|
|
|
|
- when:
|
|
|
|
condition: << parameters.save_cache >>
|
|
|
|
steps:
|
|
|
|
- save_cache:
|
|
|
|
when: always
|
|
|
|
key: go-test-cache-date-v1-{{ checksum "/tmp/go-cache-key" }}
|
|
|
|
paths:
|
|
|
|
- << parameters.cache_dir >>
|