-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaller_test.go
49 lines (47 loc) · 1.52 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
package tower
import (
"bytes"
"strings"
"testing"
)
func TestCaller(t *testing.T) {
c := GetCaller(1)
if c == nil {
t.Fatal("Expected caller to be non-nil")
}
if c.Name() != "github.com/tigorlazuardi/tower.TestCaller" {
t.Errorf("Expected caller name to be github.com/tigorlazuardi/tower.TestCaller, got %s", c.Name())
}
if c.ShortName() != "tower.TestCaller" {
t.Errorf("Expected caller short name to be tower.TestCaller, got %s", c.ShortName())
}
if !strings.Contains(c.File(), "caller_test.go") {
t.Errorf("Expected caller file to be caller_test.go, got %s", c.File())
}
if c.PC() == 0 {
t.Errorf("Expected caller pc to be non-zero")
}
if !strings.Contains(c.FormatAsKey(), "caller_test.go_") {
t.Errorf("Expected caller format as key to be caller_test.go_, got %s", c.FormatAsKey())
}
if c.Line() <= 2 {
t.Errorf("expected caller line to be greater than 2, got %d", c.Line())
}
if c.Function() == nil {
t.Errorf("Expected caller function to be non-nil")
}
if !strings.Contains(c.String(), "caller_test.go:") {
t.Errorf("Expected caller string to be caller_test.go:, got %s", c.String())
}
if !strings.Contains(c.ShortSource(), "caller_test.go") {
t.Errorf("Expected caller short source to be caller_test.go, got %s", c.ShortSource())
}
cal := c.(*caller)
b, err := cal.MarshalJSON()
if err != nil {
t.Errorf("Expected caller marshal json to be nil, got %s", err)
}
if !bytes.Contains(b, []byte("caller_test.go:")) {
t.Errorf("Expected caller marshal json to be caller_test.go:, got %s", b)
}
}