diff --git a/common/testing/testing.go b/common/testing/testing.go index d301d37..dc54326 100644 --- a/common/testing/testing.go +++ b/common/testing/testing.go @@ -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() { diff --git a/matrix/matrix.go b/matrix/matrix.go new file mode 100644 index 0000000..2903ff7 --- /dev/null +++ b/matrix/matrix.go @@ -0,0 +1 @@ +package matrix diff --git a/tests/etc/etc_mx.go b/tests/etc/etc_mx.go new file mode 100644 index 0000000..98dd005 --- /dev/null +++ b/tests/etc/etc_mx.go @@ -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 +) diff --git a/tests/matrix_test.go b/tests/matrix_test.go new file mode 100644 index 0000000..e52939f --- /dev/null +++ b/tests/matrix_test.go @@ -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) +} diff --git a/tests/scopes_test.go b/tests/scopes_test.go index 1e3c930..2af5e6a 100644 --- a/tests/scopes_test.go +++ b/tests/scopes_test.go @@ -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) {