go-scopes/tests/matrix_test.go

43 lines
968 B
Go

package scopes_test
import (
"os"
tbase "testing"
lib "git.sr.ht/~cco/go-scopes"
"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 TestMatrixApp(tb *tbase.T) {
logfile := "log/matrix.log"
os.Remove(logfile) // make sure we start with a fresh log file
t := testing.SetUpApp(tb, etc.ConfigMx())
t.Run("app-matrix", MxTest)
t.TearDownApp("matrix")
t.AssertEqual(t.LogCheck(logfile, false), 13)
}
func MxTest(t *testing.T) {
ctx := t.Ctx
t.AssertEqual(len(ctx.Services()), 3)
c0 := ctx.Services()["cell-0"]
rcvr := ctx.Services()["test-receiver"]
msg := message.New("matrix", "create").WithSender(rcvr)
c0.Send(msg)
msg = message.New("matrix", "data")
c0.Send(msg)
}
// action handlers
func MxReceiver(act lib.Action) bool {
t := testing.GetT(act.Context())
t.AssertEqual(act.Message().Action(), "data")
return true
}
func init() {
etc.AH_MxReceiver = MxReceiver
}