-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsource_test.go
More file actions
63 lines (57 loc) · 1.22 KB
/
Copy pathsource_test.go
File metadata and controls
63 lines (57 loc) · 1.22 KB
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
58
59
60
61
62
63
package oops
import (
"strings"
"testing"
)
// wrap is a helper function to test the correct call depth.
func wrap() *Source {
return source()
}
func Test_source(t *testing.T) {
defer func() { EnableSource(true) }()
tests := []struct {
name string
enabled bool
want *Source
}{
{
name: "enabled",
enabled: true,
want: &Source{
Function: "github.com/jesse0michael/oops.Test_source.func2",
File: "source_test.go",
Line: 38,
},
},
{
name: "disabled",
enabled: false,
want: nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
EnableSource(tt.enabled)
got := wrap()
if tt.want == nil {
if got != nil {
t.Errorf("source() = %v, want %v", got, tt.want)
}
return
}
if got == nil {
t.Errorf("source() = %v, want %v", got, tt.want)
return
}
if got.Function != tt.want.Function {
t.Errorf("source().Function = %v, want %v", got.Function, tt.want.Function)
}
if !strings.HasSuffix(got.File, tt.want.File) {
t.Errorf("source().File = %v, want suffix %v", got.File, tt.want.File)
}
if got.Line != tt.want.Line {
t.Errorf("source().Line = %v, want %v", got.Line, tt.want.Line)
}
})
}
}