Add test faker
This commit is contained in:
parent
037295cd1a
commit
627add5ee9
|
@ -79,6 +79,10 @@ func InitEvents() (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Publish(event Event) error {
|
func Publish(event Event) error {
|
||||||
|
if isUnderTest {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
content, err := json.Marshal(event)
|
content, err := json.Marshal(event)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
|
@ -17,6 +17,7 @@
|
||||||
package integrations
|
package integrations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"code.vikunja.io/api/pkg/events"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
@ -85,6 +86,7 @@ func setupTestEnv() (e *echo.Echo, err error) {
|
||||||
files.InitTests()
|
files.InitTests()
|
||||||
user.InitTests()
|
user.InitTests()
|
||||||
models.SetupTests()
|
models.SetupTests()
|
||||||
|
events.Fake()
|
||||||
|
|
||||||
err = db.LoadFixtures()
|
err = db.LoadFixtures()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
package migration
|
package migration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"code.vikunja.io/api/pkg/events"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -37,5 +38,6 @@ func TestMain(m *testing.M) {
|
||||||
files.InitTests()
|
files.InitTests()
|
||||||
user.InitTests()
|
user.InitTests()
|
||||||
models.SetupTests()
|
models.SetupTests()
|
||||||
|
events.Fake()
|
||||||
os.Exit(m.Run())
|
os.Exit(m.Run())
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ package user
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"code.vikunja.io/api/pkg/db"
|
"code.vikunja.io/api/pkg/db"
|
||||||
|
"code.vikunja.io/api/pkg/events"
|
||||||
"code.vikunja.io/api/pkg/log"
|
"code.vikunja.io/api/pkg/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -37,4 +38,6 @@ func InitTests() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
events.Fake()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue