improve testing for correct set up of application (context) structure
This commit is contained in:
parent
e30052b297
commit
87ff5d5d93
4 changed files with 14 additions and 4 deletions
|
@ -41,6 +41,8 @@ func (ctx *context) ChildContext(cfg Config) Context {
|
||||||
return &cctx
|
return &cctx
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// top-level application context
|
||||||
|
|
||||||
type appContext struct {
|
type appContext struct {
|
||||||
*context
|
*context
|
||||||
services map[string]Context
|
services map[string]Context
|
||||||
|
|
|
@ -5,12 +5,15 @@ package testing
|
||||||
import (
|
import (
|
||||||
"regexp"
|
"regexp"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"git.sr.ht/~cco/go-scopes/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Map map[string]interface{}
|
type Map map[string]interface{}
|
||||||
|
|
||||||
type T struct {
|
type T struct {
|
||||||
Base *testing.T
|
Base *testing.T
|
||||||
|
Ctx common.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
func MakeT(tbase *testing.T) *T {
|
func MakeT(tbase *testing.T) *T {
|
||||||
|
|
|
@ -28,6 +28,6 @@ const (
|
||||||
// file `settings.go` that should not be stored in code repository.
|
// file `settings.go` that should not be stored in code repository.
|
||||||
func Overrides() config.Settings {
|
func Overrides() config.Settings {
|
||||||
return config.Settings{
|
return config.Settings{
|
||||||
HOME: "/home/scopes",
|
HOME: "tests",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
tbase "testing"
|
tbase "testing"
|
||||||
|
|
||||||
"git.sr.ht/~cco/go-scopes"
|
"git.sr.ht/~cco/go-scopes"
|
||||||
|
"git.sr.ht/~cco/go-scopes/common"
|
||||||
"git.sr.ht/~cco/go-scopes/config"
|
"git.sr.ht/~cco/go-scopes/config"
|
||||||
"git.sr.ht/~cco/go-scopes/testing"
|
"git.sr.ht/~cco/go-scopes/testing"
|
||||||
"git.sr.ht/~cco/go-scopes/tests/etc"
|
"git.sr.ht/~cco/go-scopes/tests/etc"
|
||||||
|
@ -11,13 +12,17 @@ import (
|
||||||
|
|
||||||
func TestConfig(tb *tbase.T) {
|
func TestConfig(tb *tbase.T) {
|
||||||
t := testing.SetUp(tb)
|
t := testing.SetUp(tb)
|
||||||
|
cfg := config.Setup(etc.Config())
|
||||||
|
t.Ctx = common.AppContext(cfg)
|
||||||
|
cfg.Starter()(t.Ctx)
|
||||||
t.Run("config", ConfigTest)
|
t.Run("config", ConfigTest)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ConfigTest(t *testing.T) {
|
func ConfigTest(t *testing.T) {
|
||||||
cfg := config.Setup(etc.Config())
|
cfg := etc.Config()
|
||||||
t.AssertEqual(cfg.Name(), "dummy")
|
t.AssertEqual(cfg.Name(), "dummy")
|
||||||
appCfg := cfg.(*scopes.Cfg)
|
appCfg := cfg.(*scopes.Cfg)
|
||||||
t.AssertEqual(appCfg.Home, "/home/scopes")
|
t.AssertEqual(appCfg.Home, "tests")
|
||||||
scopes.RunApp(cfg)
|
confCtx := t.Ctx.Services()["config"]
|
||||||
|
t.AssertEqual(confCtx.Config().Name(), "config")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue