diff --git a/pkg/events/events.go b/pkg/events/events.go index aebfbc837..7bac20188 100644 --- a/pkg/events/events.go +++ b/pkg/events/events.go @@ -79,6 +79,10 @@ func InitEvents() (err error) { } func Publish(event Event) error { + if isUnderTest { + return nil + } + content, err := json.Marshal(event) if err != nil { return err diff --git a/pkg/events/testing.go b/pkg/events/testing.go new file mode 100644 index 000000000..500a5cf87 --- /dev/null +++ b/pkg/events/testing.go @@ -0,0 +1,26 @@ +// Vikunja is a to-do list application to facilitate your life. +// Copyright 2018-2021 Vikunja and contributors. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public Licensee as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public Licensee for more details. +// +// You should have received a copy of the GNU Affero General Public Licensee +// along with this program. If not, see . + +package events + +var isUnderTest bool + +// Fake sets up the "test mode" of the events package. Typically you'd call this function in the TestMain function +// in the package you're testing. It will prevent any events from being fired, instead they will be recorded and be +// available for assertions. +func Fake() { + isUnderTest = true +} diff --git a/pkg/integrations/integrations.go b/pkg/integrations/integrations.go index a24045011..33c081933 100644 --- a/pkg/integrations/integrations.go +++ b/pkg/integrations/integrations.go @@ -17,6 +17,7 @@ package integrations import ( + "code.vikunja.io/api/pkg/events" "net/http" "net/http/httptest" "net/url" @@ -85,6 +86,7 @@ func setupTestEnv() (e *echo.Echo, err error) { files.InitTests() user.InitTests() models.SetupTests() + events.Fake() err = db.LoadFixtures() if err != nil { diff --git a/pkg/modules/migration/main_test.go b/pkg/modules/migration/main_test.go index 4dee87927..7e09c32f5 100644 --- a/pkg/modules/migration/main_test.go +++ b/pkg/modules/migration/main_test.go @@ -17,6 +17,7 @@ package migration import ( + "code.vikunja.io/api/pkg/events" "os" "testing" @@ -37,5 +38,6 @@ func TestMain(m *testing.M) { files.InitTests() user.InitTests() models.SetupTests() + events.Fake() os.Exit(m.Run()) } diff --git a/pkg/user/test.go b/pkg/user/test.go index fd726b01e..45d339f01 100644 --- a/pkg/user/test.go +++ b/pkg/user/test.go @@ -18,6 +18,7 @@ package user import ( "code.vikunja.io/api/pkg/db" + "code.vikunja.io/api/pkg/events" "code.vikunja.io/api/pkg/log" ) @@ -37,4 +38,6 @@ func InitTests() { if err != nil { log.Fatal(err) } + + events.Fake() }