saasitone/pkg/services/services_test.go

47 lines
753 B
Go
Raw Normal View History

2021-12-18 13:57:34 -08:00
package services
import (
"os"
"testing"
2022-01-01 07:44:18 -08:00
"github.com/mikestefanello/pagoda/config"
"github.com/mikestefanello/pagoda/ent"
2022-11-02 16:23:26 -07:00
"github.com/mikestefanello/pagoda/pkg/tests"
2021-12-18 13:57:34 -08:00
"github.com/labstack/echo/v4"
)
var (
c *Container
ctx echo.Context
usr *ent.User
)
func TestMain(m *testing.M) {
// Set the environment to test
config.SwitchEnvironment(config.EnvTest)
// Create a new container
c = NewContainer()
// Create a web context
ctx, _ = tests.NewContext(c.Web, "/")
tests.InitSession(ctx)
2021-12-18 13:57:34 -08:00
// Create a test user
var err error
if usr, err = tests.CreateUser(c.ORM); err != nil {
2021-12-18 13:57:34 -08:00
panic(err)
}
// Run tests
exitVal := m.Run()
// Shutdown the container
if err = c.Shutdown(); err != nil {
panic(err)
}
2021-12-18 13:57:34 -08:00
os.Exit(exitVal)
}