From 87ff5d5d93b9dc6407dd6e214db2be6b46e5f664 Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Fri, 2 Jun 2023 19:41:51 +0200 Subject: [PATCH] improve testing for correct set up of application (context) structure --- common/common.go | 2 ++ testing/testing.go | 3 +++ tests/etc/etc.go | 2 +- tests/scopes_test.go | 11 ++++++++--- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/common/common.go b/common/common.go index df362e4..70aeaab 100644 --- a/common/common.go +++ b/common/common.go @@ -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 diff --git a/testing/testing.go b/testing/testing.go index 1b94ebe..5ab3f24 100644 --- a/testing/testing.go +++ b/testing/testing.go @@ -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 { diff --git a/tests/etc/etc.go b/tests/etc/etc.go index 1b2685f..86e4686 100644 --- a/tests/etc/etc.go +++ b/tests/etc/etc.go @@ -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", } } diff --git a/tests/scopes_test.go b/tests/scopes_test.go index 610800d..18360ba 100644 --- a/tests/scopes_test.go +++ b/tests/scopes_test.go @@ -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") }