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"
|
|
|
|
"github.com/mikestefanello/pagoda/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()
|
2021-12-19 17:09:01 -08:00
|
|
|
defer func() {
|
|
|
|
if err := c.Shutdown(); err != nil {
|
|
|
|
c.Web.Logger.Fatal(err)
|
|
|
|
}
|
|
|
|
}()
|
2021-12-18 13:57:34 -08:00
|
|
|
|
|
|
|
// Create a web context
|
2021-12-21 12:18:17 -08:00
|
|
|
ctx, _ = tests.NewContext(c.Web, "/")
|
|
|
|
tests.InitSession(ctx)
|
2021-12-18 13:57:34 -08:00
|
|
|
|
|
|
|
// Create a test user
|
|
|
|
var err error
|
2021-12-21 12:18:17 -08:00
|
|
|
if usr, err = tests.CreateUser(c.ORM); err != nil {
|
2021-12-18 13:57:34 -08:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run tests
|
|
|
|
exitVal := m.Run()
|
|
|
|
os.Exit(exitVal)
|
|
|
|
}
|