Add test faker

This commit is contained in:
kolaente 2021-02-01 22:18:00 +01:00
parent 037295cd1a
commit 627add5ee9
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
5 changed files with 37 additions and 0 deletions

View File

@ -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

26
pkg/events/testing.go Normal file
View File

@ -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 <https://www.gnu.org/licenses/>.
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
}

View File

@ -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 {

View File

@ -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())
}

View File

@ -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()
}