2021-12-18 13:57:34 -08:00
|
|
|
package services
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/labstack/echo/v4"
|
2024-07-09 17:57:05 -07:00
|
|
|
|
|
|
|
"git.grosinger.net/tgrosinger/saasitone/config"
|
2024-07-11 21:09:15 -07:00
|
|
|
"git.grosinger.net/tgrosinger/saasitone/pkg/models/sqlc"
|
2024-07-09 17:57:05 -07:00
|
|
|
"git.grosinger.net/tgrosinger/saasitone/pkg/tests"
|
2021-12-18 13:57:34 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
c *Container
|
|
|
|
ctx echo.Context
|
2024-07-11 21:09:15 -07:00
|
|
|
usr *sqlc.User
|
2021-12-18 13:57:34 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMain(m *testing.M) {
|
|
|
|
// Set the environment to test
|
|
|
|
config.SwitchEnvironment(config.EnvTest)
|
|
|
|
|
|
|
|
// Create a new container
|
|
|
|
c = NewContainer()
|
|
|
|
|
|
|
|
// 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
|
2024-07-11 21:31:54 -07:00
|
|
|
if usr, err = tests.CreateUser(c.DB.C); err != nil {
|
2021-12-18 13:57:34 -08:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run tests
|
|
|
|
exitVal := m.Run()
|
2022-02-02 18:24:52 -08:00
|
|
|
|
|
|
|
// Shutdown the container
|
|
|
|
if err = c.Shutdown(); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2021-12-18 13:57:34 -08:00
|
|
|
os.Exit(exitVal)
|
|
|
|
}
|