diff --git a/backend/.golangci.yml b/backend/.golangci.yml new file mode 100644 index 00000000..21bc7d40 --- /dev/null +++ b/backend/.golangci.yml @@ -0,0 +1,35 @@ +version: "2" + +run: + timeout: 5m + tests: true + +linters: + enable: + - bodyclose + - gocritic + - gosec + - govet + - ineffassign + - staticcheck + - unused + - revive + + settings: + gocritic: + enabled-tags: + - diagnostic + - experimental + - opinionated + - performance + - style + disabled-checks: + - whyNoLint + - wrapperFunc + govet: + enable: + - shadow + revive: + rules: + - name: exported + severity: warning diff --git a/backend/internal/api/handlers/certificate_handler_test.go b/backend/internal/api/handlers/certificate_handler_test.go index 15fb486a..1f8c63e5 100644 --- a/backend/internal/api/handlers/certificate_handler_test.go +++ b/backend/internal/api/handlers/certificate_handler_test.go @@ -133,7 +133,8 @@ func TestCertificateHandler_Upload(t *testing.T) { func TestCertificateHandler_Delete(t *testing.T) { // Setup tmpDir := t.TempDir() - db, err := gorm.Open(sqlite.Open("file::memory:?cache=shared"), &gorm.Config{}) + // Use WAL mode and busy timeout for better concurrency with race detector + db, err := gorm.Open(sqlite.Open("file::memory:?cache=shared&_journal_mode=WAL&_busy_timeout=5000"), &gorm.Config{}) require.NoError(t, err) require.NoError(t, db.AutoMigrate(&models.SSLCertificate{})) @@ -147,6 +148,8 @@ func TestCertificateHandler_Delete(t *testing.T) { require.NotZero(t, cert.ID) service := services.NewCertificateService(tmpDir, db) + // Allow background sync goroutine to complete before testing + time.Sleep(50 * time.Millisecond) ns := services.NewNotificationService(db) handler := NewCertificateHandler(service, ns) diff --git a/backend/internal/services/notification_service_test.go b/backend/internal/services/notification_service_test.go index 87b288f6..454b34a2 100644 --- a/backend/internal/services/notification_service_test.go +++ b/backend/internal/services/notification_service_test.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "net/http" + "sync/atomic" "testing" "time" @@ -498,12 +499,13 @@ func TestNotificationService_SendExternal_EdgeCases(t *testing.T) { db := setupNotificationTestDB(t) svc := NewNotificationService(db) - receivedCustom := "" + var receivedCustom atomic.Value + receivedCustom.Store("") ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { var body map[string]interface{} json.NewDecoder(r.Body).Decode(&body) if custom, ok := body["custom"]; ok { - receivedCustom = custom.(string) + receivedCustom.Store(custom.(string)) } w.WriteHeader(http.StatusOK) })) @@ -525,7 +527,7 @@ func TestNotificationService_SendExternal_EdgeCases(t *testing.T) { svc.SendExternal("proxy_host", "Title", "Message", customData) time.Sleep(100 * time.Millisecond) - assert.Equal(t, "test-value", receivedCustom) + assert.Equal(t, "test-value", receivedCustom.Load().(string)) }) }