81 lines
2.4 KiB
YAML
81 lines
2.4 KiB
YAML
description: run go tests
|
|
parameters:
|
|
extra_flags:
|
|
type: string
|
|
default: ""
|
|
log_dir:
|
|
type: string
|
|
default: "/tmp/testlogs"
|
|
cache_dir:
|
|
type: string
|
|
default: /tmp/go-cache
|
|
save_cache:
|
|
type: boolean
|
|
default: false
|
|
steps:
|
|
- 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" }}
|
|
- run:
|
|
name: Run Go tests
|
|
no_output_timeout: 60m
|
|
command: |
|
|
set -x
|
|
|
|
case "<< parameters.extra_flags >>" in
|
|
*-race*) VAULT_CI_GO_TEST_RACE=1;;
|
|
esac
|
|
|
|
# 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"
|
|
|
|
# Split Go tests by prior test times
|
|
package_names=$(go list \
|
|
-tags "${GO_TAGS}" \
|
|
./... \
|
|
| grep -v /integ \
|
|
| grep -v /vendor/ \
|
|
| sort \
|
|
| circleci tests split --split-by=timings --timings-type=classname)
|
|
|
|
# Install gotestsum
|
|
curl -sSL "https://github.com/gotestyourself/gotestsum/releases/download/v${GOTESTSUM_VERSION}/gotestsum_${GOTESTSUM_VERSION}_linux_amd64.tar.gz" \
|
|
| sudo tar --overwrite -xz -C /usr/local/bin gotestsum
|
|
|
|
# Run tests
|
|
make prep
|
|
mkdir -p test-results/go-test
|
|
CGO_ENABLED= \
|
|
VAULT_ADDR= \
|
|
VAULT_TOKEN= \
|
|
VAULT_DEV_ROOT_TOKEN_ID= \
|
|
VAULT_ACC= \
|
|
GOCACHE=<< parameters.cache_dir >> \
|
|
VAULT_TEST_LOG_DIR=<< parameters.log_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}
|
|
|
|
- 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 >>
|