check log: count and optionally print log records
This commit is contained in:
parent
9dc12deb19
commit
68f937042c
2 changed files with 22 additions and 2 deletions
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue