go-scopes/tests/etc/etc.go

72 lines
1.8 KiB
Go

package etc
import (
lib "git.sr.ht/~cco/go-scopes"
"git.sr.ht/~cco/go-scopes/app"
"git.sr.ht/~cco/go-scopes/client"
"git.sr.ht/~cco/go-scopes/common/testing"
"git.sr.ht/~cco/go-scopes/config"
"git.sr.ht/~cco/go-scopes/core"
"git.sr.ht/~cco/go-scopes/core/action"
"git.sr.ht/~cco/go-scopes/logging"
"git.sr.ht/~cco/go-scopes/server"
)
func Config() lib.Config {
ovr := Overrides().Use
b := config.Base
app_c := &app.Cfg{
BaseCfg: b("testing", testing.Start),
Home: ovr(".", HOME),
Logging: &logging.Cfg{
Logfile: ovr("log/scopes.log", LOGFILE),
Level: ovr("info", LOGLEVEL),
},
}
app_c.AddAction("demo", action.Base(action.Forward, "test-receiver"))
server_c := b("server", server.Start(
(&server.Cfg{Port: ovr("8123", SERVER_PORT)}).
AddRoute("/docs", server.FileServer("html")).
AddRoute("/api", server.MsgHandler("demo", server.Async, "test-receiver")),
))
test_client := &client.Cfg{
BaseCfg: b("test-client", core.Start).
WithListener(core.Delayed(core.Listen, 50)),
Url: ovr("http://localhost:8123/api", SERVER_URL),
}
test_client.AddAction("demo", action.Base(client.Send))
test_rcvr := b("test-receiver", core.Start)
test_rcvr.AddAction("demo", action.Base(AH_Receiver))
app_c.Add(server_c, test_client, test_rcvr)
return app_c
}
// register action handlers from ..._test.go here.
var (
AH_Receiver lib.ActionHandler
)
// collect here the names of fields that may be overridden via
// explicit Override() or SCOPES_* environment settings.
const (
HOME = "home"
LOGFILE = "logfile"
LOGLEVEL = "loglevel"
SERVER_PORT = "server_port"
SERVER_URL = "server_url"
)
// in a production scenario this should be put in a separate
// file `settings.go` that should not be stored in code repository.
func Overrides() config.Settings {
return config.Settings{
//HOME: "tests",
LOGLEVEL: "debug",
}
}