-
Notifications
You must be signed in to change notification settings - Fork 3
/
caller_test.go
56 lines (46 loc) · 1.18 KB
/
caller_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
package logf
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestEntryCallerFileWithPackage(t *testing.T) {
cases := []struct {
caller EntryCaller
golden string
}{
{
caller: EntryCaller{0, "/a/b/c/d.go", 66, true},
golden: "c/d.go",
},
{
caller: EntryCaller{0, "c/d.go", 66, true},
golden: "c/d.go",
},
{
caller: EntryCaller{0, "d.go", 66, true},
golden: "d.go",
},
}
for _, c := range cases {
assert.Equal(t, c.golden, c.caller.FileWithPackage())
}
}
func TestEntryCaller(t *testing.T) {
caller := NewEntryCaller(0)
assert.True(t, caller.Specified)
assert.True(t, caller.Line > 0 && caller.Line < 1000)
assert.Equal(t, "logf/caller_test.go", caller.FileWithPackage())
assert.Contains(t, caller.File, "/logf/caller_test.go")
}
func TestShortCallerEncoder(t *testing.T) {
enc := testTypeEncoder{}
caller := EntryCaller{0, "/a/b/c/d.go", 66, true}
ShortCallerEncoder(caller, &enc)
assert.EqualValues(t, "c/d.go:66", enc.result)
}
func TestFullCallerEncoder(t *testing.T) {
enc := testTypeEncoder{}
caller := EntryCaller{0, "/a/b/c/d.go", 66, true}
FullCallerEncoder(caller, &enc)
assert.EqualValues(t, "/a/b/c/d.go:66", enc.result)
}