testing: use testing.Start as app starter
This commit is contained in:
		
							parent
							
								
									4119d61c56
								
							
						
					
					
						commit
						92cefca3cb
					
				
					 4 changed files with 28 additions and 3 deletions
				
			
		| 
						 | 
					@ -9,11 +9,15 @@ type Config interface {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Services map[string]Context
 | 
					type Services map[string]Context
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type ContextState interface{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Context interface {
 | 
					type Context interface {
 | 
				
			||||||
	Config() Config
 | 
						Config() Config
 | 
				
			||||||
	Parent() Context
 | 
						Parent() Context
 | 
				
			||||||
	Services() Services
 | 
						Services() Services
 | 
				
			||||||
	ChildContext(Config) Context
 | 
						ChildContext(Config) Context
 | 
				
			||||||
 | 
						State() ContextState
 | 
				
			||||||
 | 
						WithState(ContextState) Context
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type StartFct = func(Context)
 | 
					type StartFct = func(Context)
 | 
				
			||||||
| 
						 | 
					@ -24,6 +28,7 @@ type context struct {
 | 
				
			||||||
	cfg      Config
 | 
						cfg      Config
 | 
				
			||||||
	parent   Context
 | 
						parent   Context
 | 
				
			||||||
	children []Context
 | 
						children []Context
 | 
				
			||||||
 | 
						state    ContextState
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (ctx *context) Config() Config {
 | 
					func (ctx *context) Config() Config {
 | 
				
			||||||
| 
						 | 
					@ -45,8 +50,20 @@ func (ctx *context) ChildContext(cfg Config) Context {
 | 
				
			||||||
	return cctx
 | 
						return cctx
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (ctx *context) State() ContextState {
 | 
				
			||||||
 | 
						return ctx.state
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (ctx *context) WithState(state ContextState) Context {
 | 
				
			||||||
 | 
						ctx.state = state
 | 
				
			||||||
 | 
						return ctx
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func makeCtx(cfg Config, parent Context) *context {
 | 
					func makeCtx(cfg Config, parent Context) *context {
 | 
				
			||||||
	return &context{cfg, parent, nil}
 | 
						return &context{
 | 
				
			||||||
 | 
							cfg:    cfg,
 | 
				
			||||||
 | 
							parent: parent,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// top-level application context
 | 
					// top-level application context
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,9 +6,16 @@ import (
 | 
				
			||||||
	"regexp"
 | 
						"regexp"
 | 
				
			||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"git.sr.ht/~cco/go-scopes"
 | 
				
			||||||
	"git.sr.ht/~cco/go-scopes/common"
 | 
						"git.sr.ht/~cco/go-scopes/common"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func Start(ctx common.Context) {
 | 
				
			||||||
 | 
						scopes.Start(ctx)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// definitions
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Map map[string]interface{}
 | 
					type Map map[string]interface{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type T struct {
 | 
					type T struct {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,13 +4,14 @@ import (
 | 
				
			||||||
	"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/common"
 | 
				
			||||||
	"git.sr.ht/~cco/go-scopes/config"
 | 
						"git.sr.ht/~cco/go-scopes/config"
 | 
				
			||||||
 | 
						"git.sr.ht/~cco/go-scopes/testing"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func Config() common.Config {
 | 
					func Config() common.Config {
 | 
				
			||||||
	ovr := Overrides().Use
 | 
						ovr := Overrides().Use
 | 
				
			||||||
	b := config.MakeBase
 | 
						b := config.MakeBase
 | 
				
			||||||
	cfg := scopes.Cfg{
 | 
						cfg := scopes.Cfg{
 | 
				
			||||||
		Base:    b("dummy", scopes.Start),
 | 
							Base:    b("testing", testing.Start),
 | 
				
			||||||
		Home:    ovr(".", HOME),
 | 
							Home:    ovr(".", HOME),
 | 
				
			||||||
		AppType: "standard",
 | 
							AppType: "standard",
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -15,7 +15,7 @@ func TestConfig(tb *tbase.T) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func ConfigTest(t *testing.T) {
 | 
					func ConfigTest(t *testing.T) {
 | 
				
			||||||
	cfg := etc.Config()
 | 
						cfg := etc.Config()
 | 
				
			||||||
	t.AssertEqual(cfg.Name(), "dummy")
 | 
						t.AssertEqual(cfg.Name(), "testing")
 | 
				
			||||||
	appCfg := cfg.(*scopes.Cfg)
 | 
						appCfg := cfg.(*scopes.Cfg)
 | 
				
			||||||
	t.AssertEqual(appCfg.Home, "tests")
 | 
						t.AssertEqual(appCfg.Home, "tests")
 | 
				
			||||||
	confCtx := t.Ctx.Services()["config"]
 | 
						confCtx := t.Ctx.Services()["config"]
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue