From e63a3ab92b3e0d42167c328c2f839ef979e1c930 Mon Sep 17 00:00:00 2001 From: mmetc <92726601+mmetc@users.noreply.github.com> Date: Wed, 8 Mar 2023 14:41:16 +0100 Subject: [PATCH] Unit tests: fix authentication to localstack (#2106) --- .github/workflows/go-tests.yml | 6 +----- .gitignore | 2 +- Makefile | 16 +++++++++++++--- test/localstack/docker-compose.yml | 1 - 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/.github/workflows/go-tests.yml b/.github/workflows/go-tests.yml index dcdbc5508..d7b1b149b 100644 --- a/.github/workflows/go-tests.yml +++ b/.github/workflows/go-tests.yml @@ -27,8 +27,6 @@ env: AWS_ACCESS_KEY_ID: AKIAIOSFODNN7EXAMPLE AWS_SECRET_ACCESS_KEY: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY AWS_REGION: us-east-1 - # and to override our endpoint in aws sdk - AWS_ENDPOINT_FORCE: http://localhost:4566 KINESIS_INITIALIZE_STREAMS: "stream-1-shard:1,stream-2-shards:2" CROWDSEC_FEATURE_DISABLE_HTTP_RETRY_BACKOFF: true @@ -142,9 +140,7 @@ jobs: go install github.com/kyoh86/richgo@v0.3.10 set -o pipefail make build - go-acc ./... -o coverage.out --ignore database,notifications,protobufs,cwversion,cstest,models \ - | sed 's/ *coverage:.*of statements in.*//' \ - | richgo testfilter + make go-acc | richgo testfilter - name: Build and run tests (static) run: | diff --git a/.gitignore b/.gitignore index 082eeec3f..e6cfcea52 100644 --- a/.gitignore +++ b/.gitignore @@ -15,7 +15,7 @@ # Test binaries, built from *_test.go pkg/csplugin/tests/cs_plugin_test* -# Output of the go coverage tool, specifically when used with LiteIDE +# Output of go-acc *.out # Development artifacts, backups, etc diff --git a/Makefile b/Makefile index de7915678..ac94a8c46 100644 --- a/Makefile +++ b/Makefile @@ -106,12 +106,22 @@ testclean: bats-clean @$(RM) pkg/cwhub/install $(WIN_IGNORE_ERR) @$(RM) pkg/types/example.txt $(WIN_IGNORE_ERR) -.PHONY: test -test: export AWS_ENDPOINT_FORCE=http://localhost:4566 -test: goversion +export AWS_ENDPOINT_FORCE=http://localhost:4566 +export AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE +export AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY + +testenv: @echo 'NOTE: You need Docker, docker-compose and run "make localstack" in a separate shell ("make localstack-stop" to terminate it)' + +.PHONY: test +test: testenv goversion $(GOTEST) $(LD_OPTS) ./... +.PHONY: go-acc +go-acc: testenv goversion + go-acc ./... -o coverage.out --ignore database,notifications,protobufs,cwversion,cstest,models -- $(LD_OPTS) | \ + sed 's/ *coverage:.*of statements in.*//' + .PHONY: localstack localstack: docker-compose -f test/localstack/docker-compose.yml up diff --git a/test/localstack/docker-compose.yml b/test/localstack/docker-compose.yml index 385683123..66a820da3 100644 --- a/test/localstack/docker-compose.yml +++ b/test/localstack/docker-compose.yml @@ -22,7 +22,6 @@ services: AWS_ACCESS_KEY_ID: "AKIAIOSFODNN7EXAMPLE" AWS_SECRET_ACCESS_KEY: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY" AWS_REGION: "us-east-1" - AWS_ENDPOINT_FORCE: "http://localhost:4566" volumes: - "${TMPDIR:-/tmp}/localstack:/var/lib/localstack"