-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfiguration_test.go
More file actions
111 lines (109 loc) · 3.18 KB
/
Copy pathconfiguration_test.go
File metadata and controls
111 lines (109 loc) · 3.18 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
package bugsnag
import "testing"
func TestConfigurationValidation(t *testing.T) {
for _, tc := range []struct {
name string
expMsg string
cfg Configuration
}{
{
name: "valid",
cfg: Configuration{
APIKey: "b1234590abcabcabcabcddddddddabcd",
EndpointNotify: "http://localhost:8080",
EndpointSessions: "https://sessions.bugsnag.com",
ReleaseStage: "production",
AppVersion: "1.2.3",
},
},
{
name: "API key contains non-hex chars",
cfg: Configuration{
APIKey: "q1234590abcabcabcabcddddddddabcd",
EndpointNotify: "http://localhost:8080",
EndpointSessions: "https://sessions.bugsnag.com",
},
expMsg: `API key must be 32 hex characters, but got "q1234590abcabcabcabcddddddddabcd"`,
},
{
name: "API key too short",
cfg: Configuration{
APIKey: "01234590",
EndpointNotify: "http://localhost:8080",
EndpointSessions: "https://sessions.bugsnag.com",
},
expMsg: `API key must be 32 hex characters, but got "01234590"`,
},
{
name: "API key too long",
cfg: Configuration{
APIKey: "12345678901234567890123456789012345678901234567890",
EndpointNotify: "http://localhost:8080",
EndpointSessions: "https://sessions.bugsnag.com",
},
expMsg: `API key must be 32 hex characters, but got "12345678901234567890123456789012345678901234567890"`,
},
{
name: "notify endpoint not a url",
cfg: Configuration{
APIKey: "b1234590abcabcabcabcddddddddabcd",
EndpointNotify: "fluff",
EndpointSessions: "https://sessions.bugsnag.com",
},
expMsg: `notify endpoint be a valid URL, got "fluff"`,
},
{
name: "sessions endpoint not a url",
cfg: Configuration{
APIKey: "b1234590abcabcabcabcddddddddabcd",
EndpointNotify: "https://notify.bugsnag.com",
EndpointSessions: "fluff",
},
expMsg: `sessions endpoint be a valid URL, got "fluff"`,
},
{
name: "release stage missing",
cfg: Configuration{
APIKey: "b1234590abcabcabcabcddddddddabcd",
EndpointNotify: "https://notify.bugsnag.com",
EndpointSessions: "http://localhost:8080",
},
expMsg: `release stage must be set`,
},
{
name: "app version invalid",
cfg: Configuration{
APIKey: "b1234590abcabcabcabcddddddddabcd",
EndpointNotify: "https://notify.bugsnag.com",
EndpointSessions: "http://localhost:8080",
ReleaseStage: "dev",
AppVersion: "asdfbasdfbasdf",
},
expMsg: `app version must be valid semver`,
},
{
name: "app version invalid",
cfg: Configuration{
APIKey: "b1234590abcabcabcabcddddddddabcd",
EndpointNotify: "https://notify.bugsnag.com",
EndpointSessions: "http://localhost:8080",
ReleaseStage: "dev",
AppVersion: "",
},
expMsg: `app version must be valid semver`,
},
} {
t.Run(tc.name, func(t *testing.T) {
err := tc.cfg.validate()
if err == nil {
if tc.expMsg != "" {
t.Fatalf("expected error message '%s' but didn't get any errors", tc.expMsg)
}
return
}
if err.Error() != tc.expMsg {
t.Errorf("expected error message '%s' but got '%s'", tc.expMsg, err.Error())
}
})
}
}