saasitone/pkg/services/services_test.go

47 lines
785 B
Go
Raw Permalink Normal View History

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
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.DB.C); 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)
}