From c17d42278f1c1683b7e345ac56f2ec6c0d5b3276 Mon Sep 17 00:00:00 2001 From: mmetc <92726601+mmetc@users.noreply.github.com> Date: Mon, 14 Apr 2025 16:21:32 +0200 Subject: [PATCH] replace go-acc, richgo with gotestsum (#3567) --- .github/workflows/bats-sqlite-coverage.yml | 11 +--- .github/workflows/go-tests-windows.yml | 9 +-- .github/workflows/go-tests.yml | 22 ++++---- .github/workflows/publish-tarball-release.yml | 2 +- .gitignore | 2 +- Makefile | 55 ++++++++++++++----- go.mod | 2 +- go.sum | 4 +- .../modules/cloudwatch/cloudwatch_test.go | 20 +++---- .../modules/journalctl/journalctl_test.go | 21 ++----- pkg/acquisition/modules/kafka/kafka_test.go | 15 ++--- .../modules/kinesis/kinesis_test.go | 26 ++++----- pkg/acquisition/modules/loki/loki_test.go | 22 +++----- .../modules/victorialogs/victorialogs_test.go | 22 +++----- pkg/csplugin/watcher_test.go | 13 ++--- pkg/setup/detect_test.go | 13 +---- test/README.md | 10 +--- test/bats.mk | 6 +- test/dyn-bats/README.md | 2 - 19 files changed, 118 insertions(+), 159 deletions(-) delete mode 100644 test/dyn-bats/README.md diff --git a/.github/workflows/bats-sqlite-coverage.yml b/.github/workflows/bats-sqlite-coverage.yml index a5b2758b6..d93c5f0ec 100644 --- a/.github/workflows/bats-sqlite-coverage.yml +++ b/.github/workflows/bats-sqlite-coverage.yml @@ -52,16 +52,7 @@ jobs: - name: "Collect coverage data" run: | - go tool covdata textfmt -i test/coverage -o coverage-bats-raw.out - # filter out unwanted packages, should match the argument to "go-acc --ignore" - grep -v \ - -e '/pkg/database' \ - -e '/plugins/notifications' \ - -e '/pkg/protobufs' \ - -e '/pkg/cwversions' \ - -e '/pkg/models' \ - < coverage-bats-raw.out \ - > coverage-bats.out + go tool covdata textfmt -i test/coverage -o coverage-bats.out # # In case you need to inspect the database status after the failure of a given test diff --git a/.github/workflows/go-tests-windows.yml b/.github/workflows/go-tests-windows.yml index b7c794963..e08bbecd6 100644 --- a/.github/workflows/go-tests-windows.yml +++ b/.github/workflows/go-tests-windows.yml @@ -15,7 +15,6 @@ on: - 'README.md' env: - RICHGO_FORCE_COLOR: 1 CROWDSEC_FEATURE_DISABLE_HTTP_RETRY_BACKOFF: true jobs: @@ -44,12 +43,10 @@ jobs: run: | .github/generate-codecov-yml.sh >> .github/codecov.yml - - name: Run tests + - name: Unit tests run: | - go install github.com/kyoh86/richgo@v0.3.10 - go test -tags expr_debug -coverprofile coverage.out -covermode=atomic ./... > out.txt - if(!$?) { cat out.txt | sed 's/ *coverage:.*of statements in.*//' | richgo testfilter; Exit 1 } - cat out.txt | sed 's/ *coverage:.*of statements in.*//' | richgo testfilter + go install gotest.tools/gotestsum@v1.12.1 + make testcover - name: Upload unit coverage to Codecov uses: codecov/codecov-action@v4 diff --git a/.github/workflows/go-tests.yml b/.github/workflows/go-tests.yml index 0c5b0fec1..abe923d05 100644 --- a/.github/workflows/go-tests.yml +++ b/.github/workflows/go-tests.yml @@ -21,7 +21,6 @@ on: # these env variables are for localstack, so we can emulate aws services env: - RICHGO_FORCE_COLOR: 1 AWS_HOST: localstack # these are to mimic aws config AWS_ACCESS_KEY_ID: test @@ -170,24 +169,25 @@ jobs: run: | .github/generate-codecov-yml.sh >> .github/codecov.yml - - name: Build and run tests, static + - name: Ensure we can do a dynamic build run: | sudo apt -qq -y -o=Dpkg::Use-Pty=0 install build-essential libre2-dev - go install github.com/ory/go-acc@v0.2.8 - go install github.com/kyoh86/richgo@v0.3.10 - set -o pipefail - make build BUILD_STATIC=1 - make go-acc | sed 's/ *coverage:.*of statements in.*//' | richgo testfilter + make build + + - name: Ensure we can do a static build + run: | + make clean build BUILD_STATIC=1 + + - name: Unit tests + run: | + go install gotest.tools/gotestsum@v1.12.1 + make testcover # check if some component stubs are missing - name: "Build profile: minimal" run: | make build BUILD_PROFILE=minimal - - name: Ensure we can do a dynamic build, without tests - run: | - make clean build - - name: Upload unit coverage to Codecov uses: codecov/codecov-action@v4 with: diff --git a/.github/workflows/publish-tarball-release.yml b/.github/workflows/publish-tarball-release.yml index 7a2ac8407..189aeca42 100644 --- a/.github/workflows/publish-tarball-release.yml +++ b/.github/workflows/publish-tarball-release.yml @@ -6,7 +6,7 @@ on: - prereleased permissions: - # Use write for: hub release edit + # Use write for: gh release upload contents: write jobs: diff --git a/.gitignore b/.gitignore index cba570fdb..e1068145e 100644 --- a/.gitignore +++ b/.gitignore @@ -31,7 +31,7 @@ test/bats/.bats/run-logs # Test binaries, built from *_test.go pkg/csplugin/tests/cs_plugin_test* -# Output of go-acc, go -cover +# Output of test coverage *.out test/coverage/* diff --git a/Makefile b/Makefile index 933874880..60014f393 100644 --- a/Makefile +++ b/Makefile @@ -260,7 +260,7 @@ clean-rpm: @$(RM) -r rpm/SRPMS .PHONY: clean -clean: clean-debian clean-rpm testclean ## Remove build artifacts +clean: clean-debian clean-rpm bats-clean ## Remove build artifacts @$(MAKE) -C $(CROWDSEC_FOLDER) clean $(MAKE_FLAGS) @$(MAKE) -C $(CSCLI_FOLDER) clean $(MAKE_FLAGS) @$(RM) $(CROWDSEC_BIN) $(WIN_IGNORE_ERR) @@ -279,28 +279,55 @@ cscli: ## Build cscli crowdsec: ## Build crowdsec @$(MAKE) -C $(CROWDSEC_FOLDER) build $(MAKE_FLAGS) -.PHONY: testclean -testclean: bats-clean ## Remove test artifacts - @$(RM) pkg/apiserver/ent $(WIN_IGNORE_ERR) - @$(RM) pkg/cwhub/hubdir $(WIN_IGNORE_ERR) - @$(RM) pkg/cwhub/install $(WIN_IGNORE_ERR) - @$(RM) pkg/types/example.txt $(WIN_IGNORE_ERR) - # for the tests with localstack export AWS_ENDPOINT_FORCE=http://localhost:4566 export AWS_ACCESS_KEY_ID=test export AWS_SECRET_ACCESS_KEY=test testenv: - @echo 'NOTE: You need to run "make localstack" in a separate shell, "make localstack-stop" to terminate it' +ifeq ($(TEST_LOCAL_ONLY),) + @echo 'NOTE: You need to run "make localstack" in a separate shell, "make localstack-stop" to terminate it; or define the envvar TEST_LOCAL_ONLY to some value.' +else + @echo 'TEST_LOCAL_ONLY: skipping tests that require mock containers (localstack, kafka...)' +endif + +.PHONY: check_gotestsum +check_gotestsum: +ifeq ($(OS),Windows_NT) + @where gotestsum >nul || (echo "Error: gotestsum is not installed. Install it with 'go install gotest.tools/gotestsum@latest'" && exit 1) +else + @command -v gotestsum > /dev/null 2>&1 || (echo "Error: gotestsum is not installed. Install it with 'go install gotest.tools/gotestsum@latest'" && exit 1) +endif + +# Default format +GOTESTSUM_FORMAT := pkgname + +# If running in GitHub Actions, change format +ifdef GITHUB_ACTIONS + GOTESTSUM_FORMAT := github-actions +endif .PHONY: test -test: testenv ## Run unit tests with localstack - $(GOTEST) --tags=$(GO_TAGS) $(LD_OPTS) ./... +test: check_gotestsum testenv ## Run unit tests +# The quotes in the next command are required for PowerShell + gotestsum --format $(GOTESTSUM_FORMAT) --format-hide-empty-pkg -- "-tags=$(GO_TAGS)" ./... -.PHONY: go-acc -go-acc: testenv ## Run unit tests with localstack + coverage - go-acc ./... -o coverage.out --ignore database,notifications,protobufs,cwversion,cstest,models --tags $(GO_TAGS) -- $(LD_OPTS) +.PHONY: testcover +testcover: check_gotestsum testenv ## Run unit tests with coverage report +# The quotes in the next command are required for PowerShell + gotestsum --format $(GOTESTSUM_FORMAT) --format-hide-empty-pkg -- -covermode=atomic "-coverprofile=coverage.out" -coverpkg=./... "-tags=$(GO_TAGS)" ./... + +.PHONY: check_golangci-lint +check_golangci-lint: +ifeq ($(OS),Windows_NT) + @where golangci-lint >nul || (echo "Error: golangci-lint is not installed. Install it from https://github.com/golangci/golangci-lint" && exit 1) +else + @command -v galangci-lint > /dev/null 2>&1 || (echo "Error: golangci-lint is not installed. Install it from https://github.com/golangci/golangci-lint" && exit 1) +endif + +.PHONY: lint +lint: check_golangci-lint ## Run go linters + @golangci-lint run check_docker: @if ! docker info > /dev/null 2>&1; then \ diff --git a/go.mod b/go.mod index cd45b4da5..28540d62e 100644 --- a/go.mod +++ b/go.mod @@ -24,7 +24,7 @@ require ( github.com/coreos/go-systemd/v22 v22.5.0 // indirect github.com/creack/pty v1.1.21 // indirect github.com/crowdsecurity/dlog v0.0.0-20170105205344-4fb5f8204f26 - github.com/crowdsecurity/go-cs-lib v0.0.16 + github.com/crowdsecurity/go-cs-lib v0.0.17 github.com/crowdsecurity/grokky v0.2.2 github.com/crowdsecurity/machineid v1.0.2 github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc diff --git a/go.sum b/go.sum index c3ff8dcf9..ca1093431 100644 --- a/go.sum +++ b/go.sum @@ -111,8 +111,8 @@ github.com/crowdsecurity/coraza/v3 v3.0.0-20250320231801-749b8bded21a h1:2Nyr+47 github.com/crowdsecurity/coraza/v3 v3.0.0-20250320231801-749b8bded21a/go.mod h1:xSaXWOhFMSbrV8qOOfBKAyw3aOqfwaSaOy5BgSF8XlA= github.com/crowdsecurity/dlog v0.0.0-20170105205344-4fb5f8204f26 h1:r97WNVC30Uen+7WnLs4xDScS/Ex988+id2k6mDf8psU= github.com/crowdsecurity/dlog v0.0.0-20170105205344-4fb5f8204f26/go.mod h1:zpv7r+7KXwgVUZnUNjyP22zc/D7LKjyoY02weH2RBbk= -github.com/crowdsecurity/go-cs-lib v0.0.16 h1:2/htodjwc/sfsv4deX8F/2Fzg1bOI8w3O1/BPSvvsB0= -github.com/crowdsecurity/go-cs-lib v0.0.16/go.mod h1:XwGcvTt4lMq4Tm1IRMSKMDf0CVrnytTU8Uoofa7AR+g= +github.com/crowdsecurity/go-cs-lib v0.0.17 h1:VM++7EDa34kVCXsCRwOjaua3XHru8FVfKUAbqEoQPas= +github.com/crowdsecurity/go-cs-lib v0.0.17/go.mod h1:XwGcvTt4lMq4Tm1IRMSKMDf0CVrnytTU8Uoofa7AR+g= github.com/crowdsecurity/grokky v0.2.2 h1:yALsI9zqpDArYzmSSxfBq2dhYuGUTKMJq8KOEIAsuo4= github.com/crowdsecurity/grokky v0.2.2/go.mod h1:33usDIYzGDsgX1kHAThCbseso6JuWNJXOzRQDGXHtWM= github.com/crowdsecurity/machineid v1.0.2 h1:wpkpsUghJF8Khtmn/tg6GxgdhLA1Xflerh5lirI+bdc= diff --git a/pkg/acquisition/modules/cloudwatch/cloudwatch_test.go b/pkg/acquisition/modules/cloudwatch/cloudwatch_test.go index 2bc4f5d4a..49d306631 100644 --- a/pkg/acquisition/modules/cloudwatch/cloudwatch_test.go +++ b/pkg/acquisition/modules/cloudwatch/cloudwatch_test.go @@ -64,6 +64,10 @@ func TestMain(m *testing.M) { os.Exit(0) } + if os.Getenv("TEST_LOCAL_ONLY") != "" { + os.Exit(0) + } + if err := checkForLocalStackAvailability(); err != nil { log.Fatalf("local stack error : %s", err) } @@ -80,9 +84,7 @@ func TestMain(m *testing.M) { func TestWatchLogGroupForStreams(t *testing.T) { ctx := t.Context() - if runtime.GOOS == "windows" { - t.Skip("Skipping test on windows") - } + cstest.SkipOnWindows(t) log.SetLevel(log.DebugLevel) @@ -533,9 +535,7 @@ stream_name: test_stream`), func TestConfiguration(t *testing.T) { ctx := t.Context() - if runtime.GOOS == "windows" { - t.Skip("Skipping test on windows") - } + cstest.SkipOnWindows(t) log.SetLevel(log.DebugLevel) @@ -611,9 +611,7 @@ stream_name: test_stream`), } func TestConfigureByDSN(t *testing.T) { - if runtime.GOOS == "windows" { - t.Skip("Skipping test on windows") - } + cstest.SkipOnWindows(t) log.SetLevel(log.DebugLevel) @@ -660,9 +658,7 @@ func TestConfigureByDSN(t *testing.T) { func TestOneShotAcquisition(t *testing.T) { ctx := t.Context() - if runtime.GOOS == "windows" { - t.Skip("Skipping test on windows") - } + cstest.SkipOnWindows(t) log.SetLevel(log.DebugLevel) diff --git a/pkg/acquisition/modules/journalctl/journalctl_test.go b/pkg/acquisition/modules/journalctl/journalctl_test.go index 843230e92..424612d8b 100644 --- a/pkg/acquisition/modules/journalctl/journalctl_test.go +++ b/pkg/acquisition/modules/journalctl/journalctl_test.go @@ -4,7 +4,6 @@ import ( "os" "os/exec" "path/filepath" - "runtime" "testing" "time" @@ -21,9 +20,7 @@ import ( ) func TestBadConfiguration(t *testing.T) { - if runtime.GOOS == "windows" { - t.Skip("Skipping test on windows") - } + cstest.SkipOnWindows(t) tests := []struct { config string @@ -59,9 +56,7 @@ journalctl_filter: } func TestConfigureDSN(t *testing.T) { - if runtime.GOOS == "windows" { - t.Skip("Skipping test on windows") - } + cstest.SkipOnWindows(t) tests := []struct { dsn string @@ -107,11 +102,9 @@ func TestConfigureDSN(t *testing.T) { } func TestOneShot(t *testing.T) { - ctx := t.Context() + cstest.SkipOnWindows(t) - if runtime.GOOS == "windows" { - t.Skip("Skipping test on windows") - } + ctx := t.Context() tests := []struct { config string @@ -190,11 +183,9 @@ journalctl_filter: } func TestStreaming(t *testing.T) { - ctx := t.Context() + cstest.SkipOnWindows(t) - if runtime.GOOS == "windows" { - t.Skip("Skipping test on windows") - } + ctx := t.Context() tests := []struct { config string diff --git a/pkg/acquisition/modules/kafka/kafka_test.go b/pkg/acquisition/modules/kafka/kafka_test.go index 1d07159d0..186cd19bc 100644 --- a/pkg/acquisition/modules/kafka/kafka_test.go +++ b/pkg/acquisition/modules/kafka/kafka_test.go @@ -3,7 +3,6 @@ package kafkaacquisition import ( "context" "net" - "runtime" "strconv" "testing" "time" @@ -128,11 +127,10 @@ func createTopic(topic string, broker string) { } func TestStreamingAcquisition(t *testing.T) { - ctx := t.Context() + cstest.SkipOnWindows(t) + cstest.SkipIfDefined(t, "TEST_LOCAL_ONLY") - if runtime.GOOS == "windows" { - t.Skip("Skipping test on windows") - } + ctx := t.Context() tests := []struct { name string @@ -202,11 +200,10 @@ topic: crowdsecplaintext`), subLogger, configuration.METRICS_NONE) } func TestStreamingAcquisitionWithSSL(t *testing.T) { - ctx := t.Context() + cstest.SkipIfDefined(t, "TEST_LOCAL_ONLY") + cstest.SkipOnWindows(t) - if runtime.GOOS == "windows" { - t.Skip("Skipping test on windows") - } + ctx := t.Context() tests := []struct { name string diff --git a/pkg/acquisition/modules/kinesis/kinesis_test.go b/pkg/acquisition/modules/kinesis/kinesis_test.go index 4eb3563fd..7b0a26674 100644 --- a/pkg/acquisition/modules/kinesis/kinesis_test.go +++ b/pkg/acquisition/modules/kinesis/kinesis_test.go @@ -7,7 +7,6 @@ import ( "fmt" "net" "os" - "runtime" "strconv" "strings" "testing" @@ -112,9 +111,7 @@ func TestMain(m *testing.M) { } func TestBadConfiguration(t *testing.T) { - if runtime.GOOS == "windows" { - t.Skip("Skipping test on windows") - } + cstest.SkipOnWindows(t) tests := []struct { config string @@ -156,11 +153,10 @@ stream_arn: arn:aws:kinesis:eu-west-1:123456789012:stream/my-stream`, } func TestReadFromStream(t *testing.T) { - ctx := t.Context() + cstest.SkipOnWindows(t) + cstest.SkipIfDefined(t, "TEST_LOCAL_ONLY") - if runtime.GOOS == "windows" { - t.Skip("Skipping test on windows") - } + ctx := t.Context() tests := []struct { config string @@ -204,11 +200,10 @@ stream_name: stream-1-shard`, } func TestReadFromMultipleShards(t *testing.T) { - ctx := t.Context() + cstest.SkipOnWindows(t) + cstest.SkipIfDefined(t, "TEST_LOCAL_ONLY") - if runtime.GOOS == "windows" { - t.Skip("Skipping test on windows") - } + ctx := t.Context() tests := []struct { config string @@ -255,11 +250,10 @@ stream_name: stream-2-shards`, } func TestFromSubscription(t *testing.T) { - ctx := t.Context() + cstest.SkipOnWindows(t) + cstest.SkipIfDefined(t, "TEST_LOCAL_ONLY") - if runtime.GOOS == "windows" { - t.Skip("Skipping test on windows") - } + ctx := t.Context() tests := []struct { config string diff --git a/pkg/acquisition/modules/loki/loki_test.go b/pkg/acquisition/modules/loki/loki_test.go index 2a3789b43..5bfd6ff89 100644 --- a/pkg/acquisition/modules/loki/loki_test.go +++ b/pkg/acquisition/modules/loki/loki_test.go @@ -9,7 +9,6 @@ import ( "net/http" "net/url" "os" - "runtime" "strings" "testing" "time" @@ -332,11 +331,10 @@ func feedLoki(ctx context.Context, logger *log.Entry, n int, title string) error } func TestOneShotAcquisition(t *testing.T) { - ctx := t.Context() + cstest.SkipIfDefined(t, "TEST_LOCAL_ONLY") + cstest.SkipOnWindows(t) - if runtime.GOOS == "windows" { - t.Skip("Skipping test on windows") - } + ctx := t.Context() log.SetOutput(os.Stdout) log.SetLevel(log.InfoLevel) @@ -394,11 +392,10 @@ since: 1h } func TestStreamingAcquisition(t *testing.T) { - ctx := t.Context() + cstest.SkipOnWindows(t) + cstest.SkipIfDefined(t, "TEST_LOCAL_ONLY") - if runtime.GOOS == "windows" { - t.Skip("Skipping test on windows") - } + ctx := t.Context() log.SetOutput(os.Stdout) log.SetLevel(log.InfoLevel) @@ -510,11 +507,10 @@ query: > } func TestStopStreaming(t *testing.T) { - ctx := t.Context() + cstest.SkipOnWindows(t) + cstest.SkipIfDefined(t, "TEST_LOCAL_ONLY") - if runtime.GOOS == "windows" { - t.Skip("Skipping test on windows") - } + ctx := t.Context() config := ` mode: tail diff --git a/pkg/acquisition/modules/victorialogs/victorialogs_test.go b/pkg/acquisition/modules/victorialogs/victorialogs_test.go index 972523cd5..e8e43cdba 100644 --- a/pkg/acquisition/modules/victorialogs/victorialogs_test.go +++ b/pkg/acquisition/modules/victorialogs/victorialogs_test.go @@ -9,7 +9,6 @@ import ( "net/http" "net/url" "os" - "runtime" "strconv" "strings" "testing" @@ -254,11 +253,10 @@ func feedVLogs(ctx context.Context, logger *log.Entry, n int, title string) erro } func TestOneShotAcquisition(t *testing.T) { - ctx := t.Context() + cstest.SkipOnWindows(t) + cstest.SkipIfDefined(t, "TEST_LOCAL_ONLY") - if runtime.GOOS == "windows" { - t.Skip("Skipping test on windows") - } + ctx := t.Context() log.SetOutput(os.Stdout) log.SetLevel(log.InfoLevel) @@ -319,11 +317,10 @@ since: 1h } func TestStreamingAcquisition(t *testing.T) { - ctx := t.Context() + cstest.SkipOnWindows(t) + cstest.SkipIfDefined(t, "TEST_LOCAL_ONLY") - if runtime.GOOS == "windows" { - t.Skip("Skipping test on windows") - } + ctx := t.Context() log.SetOutput(os.Stdout) log.SetLevel(log.InfoLevel) @@ -431,11 +428,10 @@ query: > } func TestStopStreaming(t *testing.T) { - ctx := t.Context() + cstest.SkipOnWindows(t) + cstest.SkipIfDefined(t, "TEST_LOCAL_ONLY") - if runtime.GOOS == "windows" { - t.Skip("Skipping test on windows") - } + ctx := t.Context() config := ` mode: tail diff --git a/pkg/csplugin/watcher_test.go b/pkg/csplugin/watcher_test.go index 2414612ab..7321852a3 100644 --- a/pkg/csplugin/watcher_test.go +++ b/pkg/csplugin/watcher_test.go @@ -3,7 +3,6 @@ package csplugin import ( "context" "log" - "runtime" "testing" "time" @@ -49,11 +48,9 @@ func listenChannelWithTimeout(ctx context.Context, channel chan string) error { } func TestPluginWatcherInterval(t *testing.T) { - ctx := t.Context() + cstest.SkipOnWindowsBecause(t, "timing is not reliable") - if runtime.GOOS == "windows" { - t.Skip("Skipping test on windows because timing is not reliable") - } + ctx := t.Context() pw := PluginWatcher{} alertsByPluginName := make(map[string][]*models.Alert) @@ -85,11 +82,9 @@ func TestPluginWatcherInterval(t *testing.T) { } func TestPluginAlertCountWatcher(t *testing.T) { - ctx := t.Context() + cstest.SkipOnWindowsBecause(t, "timing is not reliable") - if runtime.GOOS == "windows" { - t.Skip("Skipping test on windows because timing is not reliable") - } + ctx := t.Context() pw := PluginWatcher{} alertsByPluginName := make(map[string][]*models.Alert) diff --git a/pkg/setup/detect_test.go b/pkg/setup/detect_test.go index 00b6e356b..5fa652a6e 100644 --- a/pkg/setup/detect_test.go +++ b/pkg/setup/detect_test.go @@ -392,9 +392,7 @@ func TestDetectSimpleRule(t *testing.T) { } func TestDetectUnitError(t *testing.T) { - if runtime.GOOS == "windows" { - t.Skip("skipping on windows") - } + cstest.SkipOnWindows(t) require := require.New(t) setup.ExecCommand = fakeExecCommandNotFound @@ -563,10 +561,7 @@ func TestDetectForcedUnit(t *testing.T) { } func TestDetectForcedProcess(t *testing.T) { - if runtime.GOOS == "windows" { - // while looking for service wizard: rule 'ProcessRunning("foobar")': while looking up running processes: could not get Name: A device attached to the system is not functioning. - t.Skip("skipping on windows") - } + cstest.SkipOnWindows(t) require := require.New(t) setup.ExecCommand = fakeExecCommand @@ -593,9 +588,7 @@ func TestDetectForcedProcess(t *testing.T) { } func TestDetectSkipService(t *testing.T) { - if runtime.GOOS == "windows" { - t.Skip("skipping on windows") - } + cstest.SkipOnWindows(t) require := require.New(t) setup.ExecCommand = fakeExecCommand diff --git a/test/README.md b/test/README.md index f7b036e79..b1489f1b7 100644 --- a/test/README.md +++ b/test/README.md @@ -356,15 +356,7 @@ If you are not using Docker, you may need to adjust the `PGHOST`/`PGPORT`/`PGPAS An additional user and database both named `crowdsec_test` will be created. -Now you can build and run the tests (we skip bats-test-hub here, they really -should not be affected by a change in DB). - -``` -$ export DB_BACKEND=postgres -$ make clean bats-build bats-fixture bats-test -``` - -or with the pgx driver: +Now you can build and run the tests: ``` $ export DB_BACKEND=pgx diff --git a/test/bats.mk b/test/bats.mk index 7d05d2450..e25156ed9 100644 --- a/test/bats.mk +++ b/test/bats.mk @@ -55,7 +55,7 @@ export GOCOVERDIR="$(TEST_DIR)/coverage" export PATH="$(TEST_DIR)/tools:$(PATH)" endef -bats-all: bats-clean bats-build bats-fixture bats-test bats-test-hub +bats-all: bats-clean bats-build bats-fixture bats-test # Source this to run the scripts outside of the Makefile # Old versions of make don't have $(file) directive @@ -102,9 +102,6 @@ bats-clean: ## Remove functional test environment bats-test: bats-environment ## Run functional tests $(TEST_DIR)/run-tests $(TEST_DIR)/bats -bats-test-hub: bats-environment bats-check-requirements ## Run all hub tests - $(TEST_DIR)/run-tests $(TEST_DIR)/dyn-bats - # Not failproof but they can catch bugs and improve learning of sh/bash bats-lint: ## Static checks for the test scripts. @shellcheck --version >/dev/null 2>&1 || (echo "ERROR: shellcheck is required."; exit 1) @@ -113,4 +110,3 @@ bats-lint: ## Static checks for the test scripts. bats-test-package: bats-environment ## CI only - test a binary package (deb, rpm, ...) $(TEST_DIR)/instance-data make $(TEST_DIR)/run-tests $(TEST_DIR)/bats - $(TEST_DIR)/run-tests $(TEST_DIR)/dyn-bats diff --git a/test/dyn-bats/README.md b/test/dyn-bats/README.md deleted file mode 100644 index 1e4dec1d6..000000000 --- a/test/dyn-bats/README.md +++ /dev/null @@ -1,2 +0,0 @@ -This directory is for dynamically generated tests. Do not commit them. -Any `*.bats` file here will be removed by the Makefile.