generated from golang-templates/seed
/
logger_test.go
57 lines (48 loc) · 1.28 KB
/
logger_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package goyek_test
import (
"context"
"strings"
"testing"
"github.com/goyek/goyek/v2"
)
func TestCodeLineLogger(t *testing.T) {
flow := &goyek.Flow{}
out := &strings.Builder{}
flow.SetOutput(out)
loggerSpy := &goyek.CodeLineLogger{}
flow.SetLogger(loggerSpy)
flow.Define(goyek.Task{
Name: "task",
Action: func(a *goyek.A) {
a.Log("message")
helperFn(a)
a.Cleanup(func() {
a.Log("cleanup")
})
},
})
_ = flow.Execute(context.Background(), []string{"task"})
assertContains(t, out, " logger_test.go:20: message", "should contain code line info")
assertContains(t, out, " logger_test.go:21: message from helper", "should respect a.Helper()")
assertContains(t, out, " logger_test.go:23: cleanup", "should respect a.Cleanup()")
}
func TestCodeLineLogger_helper_in_action(t *testing.T) {
flow := &goyek.Flow{}
out := &strings.Builder{}
flow.SetOutput(out)
loggerSpy := &goyek.CodeLineLogger{}
flow.SetLogger(loggerSpy)
flow.Define(goyek.Task{
Name: "task",
Action: func(a *goyek.A) {
a.Helper()
a.Log("message")
},
})
_ = flow.Execute(context.Background(), []string{"task"})
assertContains(t, out, " logger_test.go:45: message", "should contain code line info")
}
func helperFn(a *goyek.A) {
a.Helper()
a.Log("message from helper")
}