diff --git a/Makefile b/Makefile index 0fb36261f..08958ced3 100644 --- a/Makefile +++ b/Makefile @@ -78,6 +78,9 @@ endif GO_TAGS := netgo,osusergo,sqlite_omit_load_extension +# this will be used by Go in the make target, some distributions require it +export PKG_CONFIG_PATH:=/usr/local/lib/pkgconfig:$(PKG_CONFIG_PATH) + ifeq ($(call bool,$(BUILD_RE2_WASM)),0) ifeq ($(PKG_CONFIG),) $(error "pkg-config is not available. Please install pkg-config.") diff --git a/test/bats.mk b/test/bats.mk index 4eb7abcbf..259bef379 100644 --- a/test/bats.mk +++ b/test/bats.mk @@ -66,15 +66,24 @@ bats-environment: bats-check-requirements: @$(TEST_DIR)/bin/check-requirements +# Install/update some of the tools required to run the tests +bats-update-tools: + # yq v4.34.1 + GOBIN=$(TEST_DIR)/tools go install github.com/mikefarah/yq/v4@5ef537f3fd1a9437aa3ee44c32c6459a126efdc4 + # cfssl v1.6.4 + GOBIN=$(TEST_DIR)/tools go install github.com/cloudflare/cfssl/cmd/cfssl@b4d0d877cac528f63db39dfb62d5c96cd3a32a0b + GOBIN=$(TEST_DIR)/tools go install github.com/cloudflare/cfssl/cmd/cfssljson@b4d0d877cac528f63db39dfb62d5c96cd3a32a0b + # Build and installs crowdsec in a local directory. Rebuilds if already exists. -bats-build: bats-environment bats-check-requirements +bats-build: bats-environment @$(MKDIR) $(BIN_DIR) $(LOG_DIR) $(PID_DIR) $(BATS_PLUGIN_DIR) @TEST_COVERAGE=$(TEST_COVERAGE) DEFAULT_CONFIGDIR=$(CONFIG_DIR) DEFAULT_DATADIR=$(DATA_DIR) $(MAKE) build @install -m 0755 cmd/crowdsec/crowdsec cmd/crowdsec-cli/cscli $(BIN_DIR)/ @install -m 0755 plugins/notifications/*/notification-* $(BATS_PLUGIN_DIR)/ # Create a reusable package with initial configuration + data -bats-fixture: +bats-fixture: bats-check-requirements bats-update-tools + @echo "Creating functional test fixture..." @$(TEST_DIR)/instance-data make # Remove the local crowdsec installation and the fixture config + data @@ -87,7 +96,7 @@ bats-clean: @$(RM) test/coverage/* $(WIN_IGNORE_ERR) # Run the test suite -bats-test: bats-environment bats-check-requirements +bats-test: bats-environment $(TEST_DIR)/run-tests $(TEST_DIR)/bats # Generate dynamic tests diff --git a/test/bats/80_alerts.bats b/test/bats/80_alerts.bats index 6a7f1386d..0f70223b6 100644 --- a/test/bats/80_alerts.bats +++ b/test/bats/80_alerts.bats @@ -176,7 +176,7 @@ teardown() { } @test "cscli alerts delete (must ignore the query limit)" { - for i in $(seq 1 200); do + for _i in $(seq 1 200); do rune -0 cscli decisions add -i 1.2.3.4 done rune -0 cscli alerts delete -i 1.2.3.4 diff --git a/test/bin/check-requirements b/test/bin/check-requirements index 0563eec01..c5580c702 100755 --- a/test/bin/check-requirements +++ b/test/bin/check-requirements @@ -62,12 +62,6 @@ check_daemonizer() { echo "Checking requirements..." -GOBIN=${TEST_DIR}/tools -export GOBIN -go install github.com/mikefarah/yq/v4@latest -go install github.com/cloudflare/cfssl/cmd/cfssl@master -go install github.com/cloudflare/cfssl/cmd/cfssljson@master - check_bats_core check_curl check_daemonizer diff --git a/test/lib/config/config-local b/test/lib/config/config-local index f29ecd48a..c4f97e7b5 100755 --- a/test/lib/config/config-local +++ b/test/lib/config/config-local @@ -100,7 +100,7 @@ config_generate() { .api.server.profiles_path=strenv(CONFIG_DIR)+"/profiles.yaml" | .api.server.console_path=strenv(CONFIG_DIR)+"/console.yaml" | .crowdsec_service.console_context_path=strenv(CONFIG_DIR) + "/console/context.yaml" | - .api.server.online_client.credentials_path=strenv(CONFIG_DIR)+"/online_api_credentials.yaml" + del(.api.server.online_client) ' ../config/config.yaml >"${CONFIG_DIR}/config.yaml" } @@ -120,9 +120,9 @@ make_init_data() { ./instance-db config-yaml ./instance-db setup - "$CSCLI" machines add githubciXXXXXXXXXXXXXXXXXXXXXXXX --auto - "$CSCLI" hub update - "$CSCLI" collections install crowdsecurity/linux + "$CSCLI" --warning machines add githubciXXXXXXXXXXXXXXXXXXXXXXXX --auto + "$CSCLI" --warning hub update + "$CSCLI" --warning collections install crowdsecurity/linux mkdir -p "$LOCAL_INIT_DIR" @@ -130,9 +130,6 @@ make_init_data() { echo "${DB_BACKEND}" > "${LOCAL_INIT_DIR}/.backend" - # disable CAPI by default - yq e 'del(.api.server.online_client)' -i "${CONFIG_DIR}/config.yaml" - "${TAR}" -C "${LOCAL_DIR}" --create \ --exclude "${REL_DATA_DIR}"/crowdsec.db \ --file "${LOCAL_INIT_DIR}/init-config-data.tar" "${REL_CONFIG_DIR}" "${REL_DATA_DIR}"