From 68f937042cbd7dcda1e4aced9129747912e3150e Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Tue, 27 Jun 2023 17:32:07 +0200 Subject: [PATCH] check log: count and optionally print log records --- testing/testing.go | 20 ++++++++++++++++++++ tests/scopes_test.go | 4 ++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/testing/testing.go b/testing/testing.go index 1d55436..5b08c65 100644 --- a/testing/testing.go +++ b/testing/testing.go @@ -3,6 +3,9 @@ package testing import ( + "bufio" + "fmt" + "os" "regexp" "testing" "time" @@ -57,6 +60,23 @@ func (t *T) TearDownApp() { //t.AssertNoUncheckedMessages() } +func (t *T) LogCount(pr bool) (count int) { + f, _ := os.Open("log/scopes.log") + defer f.Close() + scanner := bufio.NewScanner(f) + for scanner.Scan() { + if pr { + fmt.Println(scanner.Text()) + } + count++ + } + return count +} + +func GetT(ctx lib.Context) *T { + return ctx.Parent().State().(*T) +} + // testing methods func (t *T) Run(name string, f func(*T)) bool { diff --git a/tests/scopes_test.go b/tests/scopes_test.go index 127670b..917a387 100644 --- a/tests/scopes_test.go +++ b/tests/scopes_test.go @@ -18,6 +18,7 @@ func TestConfig(tb *tbase.T) { t.Run("config", ConfigTest) t.Run("send", SendTest) t.TearDownApp() + t.AssertEqual(t.LogCount(true), 7) } func AppTest(t *testing.T) { @@ -44,8 +45,7 @@ func SendTest(t *testing.T) { // action handlers func Receiver(act lib.Action) bool { - // t := testing.GetT(act.Context()) - t := act.Context().Parent().State().(*testing.T) + t := testing.GetT(act.Context()) t.AssertEqual(act.Message().Action(), "demo") return true }