saasitone/pkg/middleware/middleware_test.go

41 lines
716 B
Go
Raw Permalink Normal View History

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"
)
var (
c *services.Container
2024-07-11 21:09:15 -07:00
usr *sqlc.User
)
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
if usr, err = tests.CreateUser(c.DB.C); err != nil {
panic(err)
}
// Run tests
exitVal := m.Run()
// Shutdown the container
if err = c.Shutdown(); err != nil {
panic(err)
}
os.Exit(exitVal)
}