63 lines
1.4 KiB
Go
63 lines
1.4 KiB
Go
package scopes_test
|
|
|
|
import (
|
|
"os"
|
|
tbase "testing"
|
|
|
|
lib "git.sr.ht/~cco/go-scopes"
|
|
"git.sr.ht/~cco/go-scopes/app"
|
|
"git.sr.ht/~cco/go-scopes/common/testing"
|
|
"git.sr.ht/~cco/go-scopes/core/message"
|
|
"git.sr.ht/~cco/go-scopes/tests/etc"
|
|
)
|
|
|
|
func TestScopesApp(tb *tbase.T) {
|
|
os.Remove("log/scopes.log") // make sure we start with a fresh log file
|
|
t := testing.SetUpApp(tb, etc.Config())
|
|
t.Run("app", AppTest)
|
|
t.Run("config", ConfigTest)
|
|
t.Run("send", SendTest)
|
|
t.Run("client", ClientTest)
|
|
t.TearDownApp()
|
|
t.AssertEqual(t.LogCheck(true), 12)
|
|
}
|
|
|
|
func AppTest(t *testing.T) {
|
|
ctx := t.Ctx
|
|
t.AssertEqual(len(ctx.Services()), 5)
|
|
}
|
|
|
|
func ConfigTest(t *testing.T) {
|
|
cfg := etc.Config()
|
|
t.AssertEqual(cfg.Name(), "testing")
|
|
appCfg := cfg.(*app.Cfg)
|
|
t.AssertEqual(appCfg.Home, ".")
|
|
confCtx := t.Ctx.Services()["config"]
|
|
t.AssertEqual(confCtx.Config().Name(), "config")
|
|
}
|
|
|
|
func SendTest(t *testing.T) {
|
|
ctx := t.Ctx
|
|
rcvr := message.SimpleAddress("testing")
|
|
msg := message.SimpleMessage("demo")
|
|
lib.Send(ctx, rcvr, msg)
|
|
}
|
|
|
|
func ClientTest(t *testing.T) {
|
|
ctx := t.Ctx
|
|
rcvr := message.SimpleAddress("test-client")
|
|
msg := message.SimpleMessage("demo")
|
|
lib.Send(ctx, rcvr, msg)
|
|
}
|
|
|
|
// action handlers
|
|
|
|
func Receiver(act lib.Action) bool {
|
|
t := testing.GetT(act.Context())
|
|
t.AssertEqual(act.Message().Action(), "demo")
|
|
return true
|
|
}
|
|
|
|
func init() {
|
|
etc.AH_Receiver = Receiver
|
|
}
|