forked from bugsnag/bugsnag-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfiguration_test.go
More file actions
168 lines (135 loc) · 3.56 KB
/
configuration_test.go
File metadata and controls
168 lines (135 loc) · 3.56 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package bugsnag
import (
"log"
"os"
"testing"
"github.com/juju/loggo"
)
func TestNotifyReleaseStages(t *testing.T) {
var testCases = []struct {
stage string
configured []string
notify bool
msg string
}{
{
stage: "production",
notify: true,
msg: "Should notify in all release stages by default",
},
{
stage: "production",
configured: []string{"development", "production"},
notify: true,
msg: "Failed to notify in configured release stage",
},
{
stage: "staging",
configured: []string{"development", "production"},
notify: false,
msg: "Failed to prevent notification in excluded release stage",
},
}
for _, testCase := range testCases {
Configure(Configuration{ReleaseStage: testCase.stage, NotifyReleaseStages: testCase.configured})
if Config.notifyInReleaseStage() != testCase.notify {
t.Error(testCase.msg)
}
}
}
func TestIsProjectPackage(t *testing.T) {
Configure(Configuration{ProjectPackages: []string{
"main",
"star*",
"example.com/a",
"example.com/b/*",
"example.com/c/*/*",
"example.com/d/**",
"example.com/e",
}})
var testCases = []struct {
Path string
Included bool
}{
{"", false},
{"main", true},
{"runtime", false},
{"star", true},
{"sta", false},
{"starred", true},
{"star/foo", false},
{"example.com/a", true},
{"example.com/b", false},
{"example.com/b/", true},
{"example.com/b/foo", true},
{"example.com/b/foo/bar", false},
{"example.com/c/foo/bar", true},
{"example.com/c/foo/bar/baz", false},
{"example.com/d/foo/bar", true},
{"example.com/d/foo/bar/baz", true},
{"example.com/e", true},
}
for _, s := range testCases {
if Config.isProjectPackage(s.Path) != s.Included {
t.Error("literal project package doesn't work:", s.Path, s.Included)
}
}
}
func TestStripProjectPackage(t *testing.T) {
Configure(Configuration{ProjectPackages: []string{
"main",
"star*",
"example.com/a",
"example.com/b/*",
"example.com/c/**",
}})
var testCases = []struct {
File string
Stripped string
}{
{"main.go", "main.go"},
{"runtime.go", "runtime.go"},
{"star.go", "star.go"},
{"example.com/a/foo.go", "foo.go"},
{"example.com/b/foo/bar.go", "foo/bar.go"},
{"example.com/b/foo.go", "foo.go"},
{"example.com/x/a/b/foo.go", "example.com/x/a/b/foo.go"},
{"example.com/c/a/b/foo.go", "a/b/foo.go"},
}
for _, tc := range testCases {
if s := Config.stripProjectPackages(tc.File); s != tc.Stripped {
t.Error("stripProjectPackage did not remove expected path:", tc.File, tc.Stripped, "was:", s)
}
}
}
type LoggoWrapper struct {
loggo.Logger
}
func (lw *LoggoWrapper) Printf(format string, v ...interface{}) {
lw.Logger.Warningf(format, v...)
}
func TestConfiguringCustomLogger(t *testing.T) {
l1 := log.New(os.Stdout, "", log.Lshortfile)
l2 := &LoggoWrapper{loggo.GetLogger("test")}
var testCases = []struct {
config Configuration
notify bool
msg string
}{
{
config: Configuration{ReleaseStage: "production", NotifyReleaseStages: []string{"development", "production"}, Logger: l1},
notify: true,
msg: "Failed to assign log.Logger",
},
{
config: Configuration{ReleaseStage: "production", NotifyReleaseStages: []string{"development", "production"}, Logger: l2},
notify: true,
msg: "Failed to assign LoggoWrapper",
},
}
for _, testCase := range testCases {
Configure(testCase.config)
// call printf just to illustrate it is present as the compiler does most of the hard work
testCase.config.Logger.Printf("hello %s", "bugsnag")
}
}