starting with 'matrix' (cells) sub-project: tests

This commit is contained in:
Helmut Merz 2023-07-23 18:58:12 +02:00
parent 22e541f391
commit f55416dddf
5 changed files with 72 additions and 6 deletions

View file

@ -52,18 +52,24 @@ func SetUpApp(tbase *testing.T, cfg lib.Config) *T {
return t
}
func (t *T) TearDownApp() {
func (t *T) TearDownApp(name string) {
if name == "" {
name = "testing"
}
// give actors time to recieve all messages:
time.Sleep(100 * time.Millisecond)
//t.Check()
lib.Send(t.Ctx, message.SimpleAddress("testing"), message.Quit)
lib.Send(t.Ctx, message.SimpleAddress(name), message.Quit)
t.Ctx.WaitGroup().Wait()
//t.AssertNoUncheckedMessages()
}
func (t *T) LogCheck(pr bool) int {
func (t *T) LogCheck(logfile string, pr bool) int {
count := 0
f, _ := os.Open("log/scopes.log")
if logfile == "" {
logfile = "log/scopes.log"
}
f, _ := os.Open(logfile)
defer f.Close()
scanner := bufio.NewScanner(f)
for scanner.Scan() {

1
matrix/matrix.go Normal file
View file

@ -0,0 +1 @@
package matrix

36
tests/etc/etc_mx.go Normal file
View file

@ -0,0 +1,36 @@
package etc
import (
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/config"
"git.sr.ht/~cco/go-scopes/core"
"git.sr.ht/~cco/go-scopes/core/action"
"git.sr.ht/~cco/go-scopes/logging"
)
func ConfigMx() lib.Config {
b := config.Base
app_c := &app.Cfg{
BaseCfg: b("matrix", testing.Start),
Logging: &logging.Cfg{
Logfile: "log/matrix.log",
Level: "debug",
},
}
app_c.AddAction("demo", action.Base(action.Forward, "test-receiver"))
test_rcvr := b("test-receiver", core.Start).
AddAction("demo", action.Base(AH_MxReceiver))
app_c.Add(test_rcvr)
return app_c
}
// register action handlers from ..._test.go here.
var (
AH_MxReceiver lib.ActionHandler
)

23
tests/matrix_test.go Normal file
View file

@ -0,0 +1,23 @@
package scopes
import (
"os"
tbase "testing"
"git.sr.ht/~cco/go-scopes/common/testing"
"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, true), 3)
}
func MxTest(t *testing.T) {
ctx := t.Ctx
t.AssertEqual(len(ctx.Services()), 2)
}

View file

@ -18,8 +18,8 @@ func TestScopesApp(tb *tbase.T) {
t.Run("config", ConfigTest)
t.Run("send", SendTest)
t.Run("client", ClientTest)
t.TearDownApp()
t.AssertEqual(t.LogCheck(true), 12)
t.TearDownApp("")
t.AssertEqual(t.LogCheck("", true), 12)
}
func AppTest(t *testing.T) {