diff --git a/config/config.go b/config/config.go index b2c0e00..4e13bd8 100644 --- a/config/config.go +++ b/config/config.go @@ -1,6 +1,7 @@ package config import ( + "os" "time" "github.com/joeshaw/envdecode" @@ -85,3 +86,9 @@ func GetConfig() (Config, error) { err := envdecode.StrictDecode(&cfg) return cfg, err } + +func SwitchEnv(env Env) { + if err := os.Setenv("APP_ENV", string(env)); err != nil { + panic(err) + } +} diff --git a/routes/controllers_test.go b/routes/routes_test.go similarity index 95% rename from routes/controllers_test.go rename to routes/routes_test.go index 1358712..54df035 100644 --- a/routes/controllers_test.go +++ b/routes/routes_test.go @@ -23,15 +23,14 @@ var ( func TestMain(m *testing.M) { // Set the environment to test - if err := os.Setenv("APP_ENV", string(config.EnvTest)); err != nil { - panic(err) - } + config.SwitchEnv(config.EnvTest) // Start a test HTTP server c = container.NewContainer() BuildRouter(c) srv = httptest.NewServer(c.Web) + // Run tests exitVal := m.Run() srv.Close() os.Exit(exitVal)