mirror of https://github.com/status-im/consul.git
enable go tests (#5863)
This commit is contained in:
parent
ee393e34fb
commit
c8dc8049c4
|
@ -26,32 +26,98 @@ jobs:
|
||||||
# Runs go fmt and go vet
|
# Runs go fmt and go vet
|
||||||
go-fmt-and-vet:
|
go-fmt-and-vet:
|
||||||
docker:
|
docker:
|
||||||
- image: *GOLANG_IMAGE
|
- image: *GOLANG_IMAGE
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
- restore_cache:
|
- restore_cache:
|
||||||
keys:
|
keys:
|
||||||
- consul-modcache-v1-{{ checksum "go.mod" }}
|
- consul-modcache-v1-{{ checksum "go.mod" }}
|
||||||
- run:
|
- run:
|
||||||
command: go mod download
|
command: go mod download
|
||||||
- save_cache:
|
- save_cache:
|
||||||
key: consul-modcache-v1-{{ checksum "go.mod" }}
|
key: consul-modcache-v1-{{ checksum "go.mod" }}
|
||||||
paths:
|
paths:
|
||||||
- /go/pkg/mod
|
- /go/pkg/mod
|
||||||
- run:
|
- run:
|
||||||
name: check go fmt
|
name: check go fmt
|
||||||
command: |
|
command: |
|
||||||
files=$(go fmt ./...)
|
files=$(go fmt ./...)
|
||||||
if [ -n "$files" ]; then
|
if [ -n "$files" ]; then
|
||||||
echo "The following file(s) do not conform to go fmt:"
|
echo "The following file(s) do not conform to go fmt:"
|
||||||
echo "$files"
|
echo "$files"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
- run:
|
- run:
|
||||||
command: go vet ./...
|
command: go vet ./...
|
||||||
environment:
|
environment:
|
||||||
<<: *ENVIRONMENT
|
<<: *ENVIRONMENT
|
||||||
|
|
||||||
|
go-test:
|
||||||
|
docker:
|
||||||
|
- image: *GOLANG_IMAGE
|
||||||
|
parallelism: 4
|
||||||
|
environment:
|
||||||
|
<<: *ENVIRONMENT
|
||||||
|
GOTAGS: '' # No tags for OSS but there are for enterprise
|
||||||
|
steps:
|
||||||
|
- checkout
|
||||||
|
- restore_cache: # restore cache from dev-build job
|
||||||
|
keys:
|
||||||
|
- consul-modcache-v1-{{ checksum "go.mod" }}
|
||||||
|
- attach_workspace:
|
||||||
|
at: /go/bin
|
||||||
|
- run: mkdir -p $TEST_RESULTS_DIR
|
||||||
|
- run: sudo apt-get update && sudo apt-get install -y rsyslog
|
||||||
|
- run: sudo service rsyslog start
|
||||||
|
# Use CircleCI test splitting by classname. Since there are no classes in go,
|
||||||
|
# we fake it by taking everything after github.com/hashicorp/consul/ and setting
|
||||||
|
# it as the classname.
|
||||||
|
|
||||||
|
# This loop writes go test results to <reportname>.xml per go package
|
||||||
|
- run: |
|
||||||
|
for pkg in $(go list ./... | circleci tests split --split-by=timings --timings-type=classname | tr '\n' ' '); do
|
||||||
|
reportname=$(echo $pkg | cut -d '/' -f3- | sed "s#/#_#g")
|
||||||
|
gotestsum --format=short-verbose --junitfile $TEST_RESULTS_DIR/$reportname.xml -- -tags=$GOTAGS $pkg
|
||||||
|
done
|
||||||
|
|
||||||
|
- store_test_results:
|
||||||
|
path: /tmp/test-results
|
||||||
|
- store_artifacts:
|
||||||
|
path: /tmp/test-results
|
||||||
|
|
||||||
|
# split off a job for the API package since it is separate
|
||||||
|
go-test-api:
|
||||||
|
docker:
|
||||||
|
- image: *GOLANG_IMAGE
|
||||||
|
environment:
|
||||||
|
<<: *ENVIRONMENT
|
||||||
|
GOTAGS: '' # No tags for OSS but there are for enterprise
|
||||||
|
steps:
|
||||||
|
- checkout
|
||||||
|
- restore_cache: # restore cache from dev-build job
|
||||||
|
keys:
|
||||||
|
- consul-modcache-v1-{{ checksum "go.mod" }}
|
||||||
|
- attach_workspace:
|
||||||
|
at: /go/bin
|
||||||
|
- run: mkdir -p $TEST_RESULTS_DIR
|
||||||
|
# Use CircleCI test splitting by classname. Since there are no classes in go,
|
||||||
|
# we fake it by taking everything after github.com/hashicorp/consul/ and setting
|
||||||
|
# it as the classname.
|
||||||
|
|
||||||
|
# This loop writes go test results to <reportname>.xml per go package
|
||||||
|
- run:
|
||||||
|
working_directory: api
|
||||||
|
command: |
|
||||||
|
for pkg in $(go list ./... | circleci tests split --split-by=timings --timings-type=classname | tr '\n' ' '); do
|
||||||
|
reportname=$(echo $pkg | cut -d '/' -f3- | sed "s#/#_#g")
|
||||||
|
gotestsum --format=short-verbose --junitfile $TEST_RESULTS_DIR/$reportname.xml -- -tags=$GOTAGS $pkg
|
||||||
|
done
|
||||||
|
|
||||||
|
- store_test_results:
|
||||||
|
path: /tmp/test-results
|
||||||
|
- store_artifacts:
|
||||||
|
path: /tmp/test-results
|
||||||
|
|
||||||
# build all distros
|
# build all distros
|
||||||
build-distros: &build-distros
|
build-distros: &build-distros
|
||||||
docker:
|
docker:
|
||||||
|
@ -97,7 +163,15 @@ jobs:
|
||||||
- image: *GOLANG_IMAGE
|
- image: *GOLANG_IMAGE
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
- run: make dev
|
- restore_cache:
|
||||||
|
keys:
|
||||||
|
- consul-modcache-v1-{{ checksum "go.mod" }}
|
||||||
|
- run:
|
||||||
|
command: make dev
|
||||||
|
- save_cache:
|
||||||
|
key: consul-modcache-v1-{{ checksum "go.mod" }}
|
||||||
|
paths:
|
||||||
|
- /go/pkg/mod
|
||||||
|
|
||||||
# save dev build to pass to downstream jobs
|
# save dev build to pass to downstream jobs
|
||||||
- persist_to_workspace:
|
- persist_to_workspace:
|
||||||
|
@ -361,6 +435,14 @@ workflows:
|
||||||
test-integrations:
|
test-integrations:
|
||||||
jobs:
|
jobs:
|
||||||
- dev-build
|
- dev-build
|
||||||
|
- go-test: &go-test
|
||||||
|
requires:
|
||||||
|
- dev-build
|
||||||
|
filters:
|
||||||
|
branches:
|
||||||
|
only:
|
||||||
|
- /^bug\/flaky-test-.*$/ # only run go tests on bug/flaky-test-* for now since we are fixing tests
|
||||||
|
- go-test-api: *go-test
|
||||||
- dev-upload-s3:
|
- dev-upload-s3:
|
||||||
requires:
|
requires:
|
||||||
- dev-build
|
- dev-build
|
||||||
|
|
Loading…
Reference in New Issue