Added shutdown method to containers.
This commit is contained in:
parent
85981e75a7
commit
40f0d7251d
@ -3,10 +3,18 @@ package config
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetConfig(t *testing.T) {
|
func TestGetConfig(t *testing.T) {
|
||||||
_, err := GetConfig()
|
_, err := GetConfig()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
var env Environment
|
||||||
|
env = "abc"
|
||||||
|
SwitchEnvironment(env)
|
||||||
|
cfg, err := GetConfig()
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, env, cfg.App.Environment)
|
||||||
}
|
}
|
||||||
|
@ -32,12 +32,14 @@ func TestMain(m *testing.M) {
|
|||||||
|
|
||||||
// Create a new container
|
// Create a new container
|
||||||
c = services.NewContainer()
|
c = services.NewContainer()
|
||||||
|
defer func() {
|
||||||
|
if err := c.Shutdown(); err != nil {
|
||||||
|
c.Web.Logger.Fatal(err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
// Run tests
|
// Run tests
|
||||||
exitVal := m.Run()
|
exitVal := m.Run()
|
||||||
if err := c.Shutdown(); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
os.Exit(exitVal)
|
os.Exit(exitVal)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
6
main.go
6
main.go
@ -13,7 +13,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
// Start a new container
|
||||||
c := services.NewContainer()
|
c := services.NewContainer()
|
||||||
|
defer func() {
|
||||||
|
if err := c.Shutdown(); err != nil {
|
||||||
|
c.Web.Logger.Fatal(err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
// Build the router
|
// Build the router
|
||||||
routes.BuildRouter(c)
|
routes.BuildRouter(c)
|
||||||
|
@ -54,7 +54,7 @@ func ServeCachedPage(ch *cache.Cache) echo.MiddlewareFunc {
|
|||||||
c.Response().Header().Set(k, v)
|
c.Response().Header().Set(k, v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c.Logger().Infof("serving cached page")
|
c.Logger().Info("serving cached page")
|
||||||
|
|
||||||
return c.HTMLBlob(page.StatusCode, page.HTML)
|
return c.HTMLBlob(page.StatusCode, page.HTML)
|
||||||
}
|
}
|
||||||
|
@ -25,17 +25,21 @@ func TestMain(m *testing.M) {
|
|||||||
// Set the environment to test
|
// Set the environment to test
|
||||||
config.SwitchEnvironment(config.EnvTest)
|
config.SwitchEnvironment(config.EnvTest)
|
||||||
|
|
||||||
// Start a test HTTP server
|
// Start a new container
|
||||||
c = services.NewContainer()
|
c = services.NewContainer()
|
||||||
|
defer func() {
|
||||||
|
if err := c.Shutdown(); err != nil {
|
||||||
|
c.Web.Logger.Fatal(err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
// Start a test HTTP server
|
||||||
BuildRouter(c)
|
BuildRouter(c)
|
||||||
srv = httptest.NewServer(c.Web)
|
srv = httptest.NewServer(c.Web)
|
||||||
|
|
||||||
// Run tests
|
// Run tests
|
||||||
exitVal := m.Run()
|
exitVal := m.Run()
|
||||||
srv.Close()
|
srv.Close()
|
||||||
if err := c.Shutdown(); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
os.Exit(exitVal)
|
os.Exit(exitVal)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user