2021-12-21 12:18:17 -08:00
|
|
|
package middleware
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
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/services"
|
|
|
|
"git.grosinger.net/tgrosinger/saasitone/pkg/tests"
|
2021-12-21 12:18:17 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
c *services.Container
|
2024-07-11 21:09:15 -07:00
|
|
|
usr *sqlc.User
|
2021-12-21 12:18:17 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMain(m *testing.M) {
|
|
|
|
// Set the environment to test
|
|
|
|
config.SwitchEnvironment(config.EnvTest)
|
|
|
|
|
|
|
|
// Create a new container
|
|
|
|
c = services.NewContainer()
|
|
|
|
|
|
|
|
// Create a user
|
|
|
|
var err error
|
2024-07-11 21:31:54 -07:00
|
|
|
if usr, err = tests.CreateUser(c.DB.C); err != nil {
|
2021-12-21 12:18:17 -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-21 12:18:17 -08:00
|
|
|
os.Exit(exitVal)
|
|
|
|
}
|