From 0a4df95fdde8d42a0ce5c15406d7def08a43c486 Mon Sep 17 00:00:00 2001 From: Timothy Messier Date: Wed, 1 Dec 2021 18:57:03 -0500 Subject: [PATCH] ci: Run sdk and api tests in ci This adds new makefile targets and configuration to run the tests in the api and sdk modules. These do not run by default since `go test ./...` does not cross module boundaries. --- .circleci/config.yml | 56 ++++++++++++++++++++++++ .circleci/config/commands/install-go.yml | 14 ++++++ .circleci/config/jobs/build.yml | 1 + .circleci/config/jobs/test-api.yml | 9 ++++ .circleci/config/jobs/test-sdk.yml | 9 ++++ .circleci/config/workflows/ci.yml | 2 + CONTRIBUTING.md | 16 +++++++ Makefile | 12 ++++- api/Makefile | 6 +++ sdk/Makefile | 6 +++ 10 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 .circleci/config/commands/install-go.yml create mode 100644 .circleci/config/jobs/test-api.yml create mode 100644 .circleci/config/jobs/test-sdk.yml create mode 100644 api/Makefile create mode 100644 sdk/Makefile diff --git a/.circleci/config.yml b/.circleci/config.yml index fba641e585..ed2eca497d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -179,6 +179,28 @@ jobs: name: Save package cache paths: - .buildcache/packages/store + test-api: + machine: + image: ubuntu-2004:202107-02 + resource_class: medium + working_directory: ~/boundary + steps: + - checkout + - run: + command: | + make install-go + source ~/.bashrc + echo 'export GOROOT=$GOROOT' >> "$BASH_ENV" + echo 'export GOPATH=$GOPATH' >> "$BASH_ENV" + echo 'export PATH=$PATH' >> "$BASH_ENV" + echo "$ go version" + go version + name: Install go + - run: + command: | + make test-api + name: Run API Tests + no_output_timeout: 15m darwin_arm64_package: docker: - image: docker.mirror.hashicorp.services/circleci/buildpack-deps @@ -591,6 +613,28 @@ jobs: name: Save package cache paths: - .buildcache/packages/store + test-sdk: + machine: + image: ubuntu-2004:202107-02 + resource_class: medium + working_directory: ~/boundary + steps: + - checkout + - run: + command: | + make install-go + source ~/.bashrc + echo 'export GOROOT=$GOROOT' >> "$BASH_ENV" + echo 'export GOPATH=$GOPATH' >> "$BASH_ENV" + echo 'export PATH=$PATH' >> "$BASH_ENV" + echo "$ go version" + go version + name: Install go + - run: + command: | + make test-sdk + name: Run SDK Tests + no_output_timeout: 15m algolia-index: docker: - image: docker.mirror.hashicorp.services/node:12 @@ -1052,6 +1096,16 @@ jobs: working_directory: ~/boundary steps: - checkout + - run: + command: | + make install-go + source ~/.bashrc + echo 'export GOROOT=$GOROOT' >> "$BASH_ENV" + echo 'export GOPATH=$GOPATH' >> "$BASH_ENV" + echo 'export PATH=$PATH' >> "$BASH_ENV" + echo "$ go version" + go version + name: Install go - run: command: | which pg_isready || sudo apt-get update && sudo apt-get install -y postgresql-client @@ -1650,6 +1704,8 @@ workflows: ci: jobs: - build + - test-api + - test-sdk - test-sql-latest - test-sql-11-alpine - test-sql-12-alpine diff --git a/.circleci/config/commands/install-go.yml b/.circleci/config/commands/install-go.yml new file mode 100644 index 0000000000..4be4861ae7 --- /dev/null +++ b/.circleci/config/commands/install-go.yml @@ -0,0 +1,14 @@ +--- +description: > + Ensure the right version of Go is installed and set PATH, GOPATH, GOROOT +steps: + - run: + name: "Install go" + command: | + make install-go + source ~/.bashrc + echo 'export GOROOT=$GOROOT' >> "$BASH_ENV" + echo 'export GOPATH=$GOPATH' >> "$BASH_ENV" + echo 'export PATH=$PATH' >> "$BASH_ENV" + echo "$ go version" + go version diff --git a/.circleci/config/jobs/build.yml b/.circleci/config/jobs/build.yml index 08880157ba..6c7582e23a 100644 --- a/.circleci/config/jobs/build.yml +++ b/.circleci/config/jobs/build.yml @@ -1,6 +1,7 @@ executor: go-machine steps: - checkout +- install-go - run: name: "Initialize Test Database" command: | diff --git a/.circleci/config/jobs/test-api.yml b/.circleci/config/jobs/test-api.yml new file mode 100644 index 0000000000..f0e28bf033 --- /dev/null +++ b/.circleci/config/jobs/test-api.yml @@ -0,0 +1,9 @@ +executor: go-machine-medium +steps: +- checkout +- install-go +- run: + name: "Run API Tests" + no_output_timeout: 15m + command: | + make test-api diff --git a/.circleci/config/jobs/test-sdk.yml b/.circleci/config/jobs/test-sdk.yml new file mode 100644 index 0000000000..441cd9e82d --- /dev/null +++ b/.circleci/config/jobs/test-sdk.yml @@ -0,0 +1,9 @@ +executor: go-machine-medium +steps: +- checkout +- install-go +- run: + name: "Run SDK Tests" + no_output_timeout: 15m + command: | + make test-sdk diff --git a/.circleci/config/workflows/ci.yml b/.circleci/config/workflows/ci.yml index 2f893263f9..9c811992b8 100644 --- a/.circleci/config/workflows/ci.yml +++ b/.circleci/config/workflows/ci.yml @@ -1,5 +1,7 @@ jobs: - build + - test-api + - test-sdk - test-sql: matrix: parameters: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5490871abc..9c210cd68e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -192,4 +192,20 @@ Note that if `max_connections` is set too low, it may result in sporadic test failures if a connection cannot be established. In this case, reduce the number of concurrent tests via `GOMAXPROCS` or selectively run tests. +### SDK and API tests + +Tests for the SDK and API modules can also be run. These do not require a test +database: + +``` +$ make test-api +$ make test-sdk +``` + +Or all of the test can be run with a single target: + +``` +$ make test-all +``` + ## [Adding additional field to an existing API (or new API)](internal/adding-a-new-field-readme.md) diff --git a/Makefile b/Makefile index 01f8e04190..b17c925184 100644 --- a/Makefile +++ b/Makefile @@ -189,7 +189,6 @@ test-database-down: make -C testing/dbtest/docker clean .PHONY: test-ci -test-ci: install-go test-ci: export CI_BUILD=1 test-ci: CGO_ENABLED=$(CGO_ENABLED) BUILD_TAGS='$(BUILD_TAGS)' sh -c "'$(CURDIR)/scripts/build.sh'" @@ -203,6 +202,17 @@ test-sql: test: go test ./... -timeout 30m +.PHONY: test-sdk +test-sdk: + $(MAKE) -C sdk/ test + +.PHONY: test-api +test-api: + $(MAKE) -C api/ test + +.PHONY: test-all +test-all: test-sdk test-api test + .PHONY: install-go install-go: ./ci/goinstall.sh diff --git a/api/Makefile b/api/Makefile new file mode 100644 index 0000000000..427fb37c2d --- /dev/null +++ b/api/Makefile @@ -0,0 +1,6 @@ +.PHONY: all +all: test + +.PHONY: test +test: + go test -v ./... diff --git a/sdk/Makefile b/sdk/Makefile new file mode 100644 index 0000000000..427fb37c2d --- /dev/null +++ b/sdk/Makefile @@ -0,0 +1,6 @@ +.PHONY: all +all: test + +.PHONY: test +test: + go test -v ./...