This repository was archived by the owner on Feb 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgomol_runtime_test.go
More file actions
77 lines (62 loc) · 2.13 KB
/
gomol_runtime_test.go
File metadata and controls
77 lines (62 loc) · 2.13 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package gomol
import (
"github.com/aphistic/sweet"
. "github.com/onsi/gomega"
)
/*
This is in its own file so the line numbers don't change.
These tests are testing calling locations so putting them in their own
file will limit the number of changes to that data.
*/
func (s *GomolSuite) TestIsGomolCaller(t sweet.T) {
res, file := isGomolCaller("/home/gomoltest/some/sub/dir/that/is/long/filename.go")
Expect(res).To(Equal(false))
Expect(file).To(Equal("filename.go"))
}
func (s *GomolSuite) TestIsGomolCallerCached(t sweet.T) {
Expect(len(gomolFiles)).To(Equal(0))
res, file := isGomolCaller("/home/gomoltest/some/sub/dir/that/is/long/filename.go")
Expect(len(gomolFiles)).To(Equal(1))
Expect(res).To(Equal(false))
Expect(file).To(Equal("filename.go"))
res, file = isGomolCaller("/home/gomoltest/some/sub/dir/that/is/long/filename.go")
Expect(gomolFiles).To(HaveLen(1))
Expect(res).To(Equal(false))
Expect(file).To(Equal("filename.go"))
}
func (s *GomolSuite) TestIsGomolCallerDirTooShort(t sweet.T) {
res, file := isGomolCaller("1234/thiscanbesuperlong.go")
Expect(len(gomolFiles)).To(Equal(1))
Expect(res).To(Equal(false))
Expect(file).To(Equal("thiscanbesuperlong.go"))
}
func (s *GomolSuite) TestIsGomolCallerFileShort(t sweet.T) {
res, file := isGomolCaller("gomol/s.go")
Expect(len(gomolFiles)).To(Equal(1))
Expect(res).To(Equal(true))
Expect(file).To(Equal("s.go"))
}
func (s *GomolSuite) TestIsGomolCallerFileTest(t sweet.T) {
res, file := isGomolCaller("gomol/s_test.go")
Expect(len(gomolFiles)).To(Equal(1))
Expect(res).To(Equal(false))
Expect(file).To(Equal("s_test.go"))
}
func (s *GomolSuite) TestLogWithRuntimeInfo(t sweet.T) {
setFakeCallerInfo("fakefile.go", 1234)
b := NewBase()
b.config.FilenameAttr = "filename"
b.config.LineNumberAttr = "line"
l := newDefaultMemLogger()
b.AddLogger(l)
b.InitLoggers()
b.Info("test")
b.ShutdownLoggers()
Expect(l.Messages()).To(HaveLen(1))
msg := l.Messages()[0]
Expect(msg.Message).To(Equal("test"))
Expect(msg.Attrs).To(HaveLen(2))
Expect(msg.Attrs["filename"]).To(Equal("fakefile.go"))
Expect(msg.Attrs["line"]).To(Equal(1234))
Expect(msg.Level).To(Equal(LevelInfo))
}