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
|
package testing
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
@ -57,6 +60,23 @@ func (t *T) TearDownApp() {
|
||||||
//t.AssertNoUncheckedMessages()
|
//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
|
// testing methods
|
||||||
|
|
||||||
func (t *T) Run(name string, f func(*T)) bool {
|
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("config", ConfigTest)
|
||||||
t.Run("send", SendTest)
|
t.Run("send", SendTest)
|
||||||
t.TearDownApp()
|
t.TearDownApp()
|
||||||
|
t.AssertEqual(t.LogCount(true), 7)
|
||||||
}
|
}
|
||||||
|
|
||||||
func AppTest(t *testing.T) {
|
func AppTest(t *testing.T) {
|
||||||
|
@ -44,8 +45,7 @@ func SendTest(t *testing.T) {
|
||||||
// action handlers
|
// action handlers
|
||||||
|
|
||||||
func Receiver(act lib.Action) bool {
|
func Receiver(act lib.Action) bool {
|
||||||
// t := testing.GetT(act.Context())
|
t := testing.GetT(act.Context())
|
||||||
t := act.Context().Parent().State().(*testing.T)
|
|
||||||
t.AssertEqual(act.Message().Action(), "demo")
|
t.AssertEqual(act.Message().Action(), "demo")
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue