From 4119d61c56e0d675428297af1e04a1cef00cb71e Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Sat, 3 Jun 2023 09:16:24 +0200 Subject: [PATCH] some code improvements and rearrangements --- common/common.go | 3 +-- config/config.go | 4 ---- examples/demo/etc/etc.go | 5 ++++- examples/demo/main.go | 3 +-- testing/testing.go | 7 +++++++ tests/etc/etc.go | 5 ++++- tests/scopes_test.go | 7 +------ 7 files changed, 18 insertions(+), 16 deletions(-) diff --git a/common/common.go b/common/common.go index 52d8daf..7bfb3cf 100644 --- a/common/common.go +++ b/common/common.go @@ -46,8 +46,7 @@ func (ctx *context) ChildContext(cfg Config) Context { } func makeCtx(cfg Config, parent Context) *context { - ctx := context{cfg, parent, nil} - return &ctx + return &context{cfg, parent, nil} } // top-level application context diff --git a/config/config.go b/config/config.go index fb01064..88b5d17 100644 --- a/config/config.go +++ b/config/config.go @@ -46,10 +46,6 @@ func MakeBase(name string, starter common.StartFct) *Base { } } -func Setup(cfg common.Config) common.Config { - return cfg -} - // overridable settings type Settings map[string]string diff --git a/examples/demo/etc/etc.go b/examples/demo/etc/etc.go index 12d303b..8cf868c 100644 --- a/examples/demo/etc/etc.go +++ b/examples/demo/etc/etc.go @@ -14,7 +14,10 @@ func Config() common.Config { Home: ovr(".", HOME), AppType: "standard", } - cfg.Add(config.Cfg{b("config", config.Start), "etc"}) + cfg.Add(config.Cfg{ + Base: b("config", config.Start), + ConfigFormat: "etc", + }) return &cfg } diff --git a/examples/demo/main.go b/examples/demo/main.go index c328038..610e882 100644 --- a/examples/demo/main.go +++ b/examples/demo/main.go @@ -6,11 +6,10 @@ import ( "demo/etc" "git.sr.ht/~cco/go-scopes" - "git.sr.ht/~cco/go-scopes/config" ) func main() { - cfg := config.Setup(etc.Config()) + cfg := etc.Config() fmt.Println(cfg.Name()) appCfg := cfg.(*scopes.Cfg) fmt.Println(appCfg.Home) diff --git a/testing/testing.go b/testing/testing.go index 5ab3f24..3034374 100644 --- a/testing/testing.go +++ b/testing/testing.go @@ -27,6 +27,13 @@ func SetUp(tbase *testing.T) *T { return t } +func SetUpApp(tbase *testing.T, cfg common.Config) *T { + t := SetUp(tbase) + t.Ctx = common.AppContext(cfg) + cfg.Starter()(t.Ctx) + return t +} + // testing methods func (t *T) Run(name string, f func(*T)) bool { diff --git a/tests/etc/etc.go b/tests/etc/etc.go index 86e4686..71d0734 100644 --- a/tests/etc/etc.go +++ b/tests/etc/etc.go @@ -14,7 +14,10 @@ func Config() common.Config { Home: ovr(".", HOME), AppType: "standard", } - cfg.Add(config.Cfg{b("config", config.Start), "etc"}) + cfg.Add(config.Cfg{ + Base: b("config", config.Start), + ConfigFormat: "etc", + }) return &cfg } diff --git a/tests/scopes_test.go b/tests/scopes_test.go index 18360ba..91f7982 100644 --- a/tests/scopes_test.go +++ b/tests/scopes_test.go @@ -4,17 +4,12 @@ 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" ) func TestConfig(tb *tbase.T) { - t := testing.SetUp(tb) - cfg := config.Setup(etc.Config()) - t.Ctx = common.AppContext(cfg) - cfg.Starter()(t.Ctx) + t := testing.SetUpApp(tb, etc.Config()) t.Run("config", ConfigTest) }