chore: Refactor test setup for Gin framework

- Removed redundant `gin.SetMode(gin.TestMode)` calls from individual test files.
- Introduced a centralized `TestMain` function in `testmain_test.go` to set the Gin mode for all tests.
- Ensured consistent test environment setup across various handler test files.
This commit is contained in:
GitHub Actions
2026-03-25 22:00:07 +00:00
parent f40fca844f
commit e6c4e46dd8
93 changed files with 58 additions and 1203 deletions
@@ -47,7 +47,6 @@ func TestReadAcquisitionConfig_ErrorsAndSuccess(t *testing.T) {
}
func TestCrowdsec_AcquisitionEndpoints_InvalidConfiguredPath(t *testing.T) {
gin.SetMode(gin.TestMode)
t.Setenv("CHARON_CROWDSEC_ACQUIS_PATH", "relative/path.yaml")
h := newTestCrowdsecHandler(t, OpenTestDB(t), &fakeExec{}, "/bin/false", t.TempDir())
@@ -68,7 +67,6 @@ func TestCrowdsec_AcquisitionEndpoints_InvalidConfiguredPath(t *testing.T) {
}
func TestCrowdsec_GetBouncerKey_NotConfigured(t *testing.T) {
gin.SetMode(gin.TestMode)
t.Setenv("CROWDSEC_API_KEY", "")
t.Setenv("CROWDSEC_BOUNCER_API_KEY", "")
t.Setenv("CERBERUS_SECURITY_CROWDSEC_API_KEY", "")