improve testing for correct set up of application (context) structure

This commit is contained in:
Helmut Merz 2023-06-02 19:41:51 +02:00
parent e30052b297
commit 87ff5d5d93
4 changed files with 14 additions and 4 deletions

View file

@ -41,6 +41,8 @@ func (ctx *context) ChildContext(cfg Config) Context {
return &cctx
}
// top-level application context
type appContext struct {
*context
services map[string]Context

View file

@ -5,12 +5,15 @@ package testing
import (
"regexp"
"testing"
"git.sr.ht/~cco/go-scopes/common"
)
type Map map[string]interface{}
type T struct {
Base *testing.T
Ctx common.Context
}
func MakeT(tbase *testing.T) *T {

View file

@ -28,6 +28,6 @@ const (
// file `settings.go` that should not be stored in code repository.
func Overrides() config.Settings {
return config.Settings{
HOME: "/home/scopes",
HOME: "tests",
}
}

View file

@ -4,6 +4,7 @@ import (
tbase "testing"
"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/testing"
"git.sr.ht/~cco/go-scopes/tests/etc"
@ -11,13 +12,17 @@ import (
func TestConfig(tb *tbase.T) {
t := testing.SetUp(tb)
cfg := config.Setup(etc.Config())
t.Ctx = common.AppContext(cfg)
cfg.Starter()(t.Ctx)
t.Run("config", ConfigTest)
}
func ConfigTest(t *testing.T) {
cfg := config.Setup(etc.Config())
cfg := etc.Config()
t.AssertEqual(cfg.Name(), "dummy")
appCfg := cfg.(*scopes.Cfg)
t.AssertEqual(appCfg.Home, "/home/scopes")
scopes.RunApp(cfg)
t.AssertEqual(appCfg.Home, "tests")
confCtx := t.Ctx.Services()["config"]
t.AssertEqual(confCtx.Config().Name(), "config")
}