forked from wichert/k8s-sentry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplication_test.go
82 lines (64 loc) · 1.79 KB
/
application_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
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
package main
import (
"os"
"testing"
"github.com/getsentry/sentry-go"
v1 "k8s.io/api/core/v1"
)
func TestSkipEvent(t *testing.T) {
t.Parallel()
evt := &v1.Event{Type: v1.EventTypeNormal}
if !skipEvent(evt) {
t.Error("Normal events must be skipped")
}
evt.Type = v1.EventTypeWarning
if skipEvent(evt) {
t.Error("Warnings events must not be skipped")
}
evt.Type = "Error"
if skipEvent(evt) {
t.Error("Error events must not be skipped")
}
evt.Type = "Unknown"
if skipEvent(evt) {
t.Error("Unknown event types must not be skipped")
}
}
func TestGetSentryLevel(t *testing.T) {
t.Parallel()
evt := &v1.Event{Type: "Warning"}
if getSentryLevel(evt) != sentry.LevelWarning {
t.Error("Type Warning not reported with warning level")
}
evt.Type = "Error"
if getSentryLevel(evt) != sentry.LevelError {
t.Error("Type Error not reported with error level")
}
evt.Type = "Other"
if getSentryLevel(evt) != sentry.LevelInfo {
t.Error("Unknown event types not reported with info level")
}
}
func TestInCluster(t *testing.T) {
os.Unsetenv("KUBERNETES_SERVICE_HOST")
os.Unsetenv("KUBERNETES_SERVICE_PORT")
if inCluster() {
t.Error("inCluster returns true if Kubernetes service env is missing")
}
os.Setenv("KUBERNETES_SERVICE_HOST", "api")
if inCluster() {
t.Error("inCluster returns true if KUBERNETES_SERVICE_PORT is missing")
}
os.Unsetenv("KUBERNETES_SERVICE_HOST")
os.Setenv("KUBERNETES_SERVICE_PORT", "4138")
if inCluster() {
t.Error("inCluster returns true if KUBERNETES_SERVICE_HOST is missing")
}
os.Setenv("KUBERNETES_SERVICE_HOST", "api")
os.Setenv("KUBERNETES_SERVICE_PORT", "4138")
if !inCluster() {
t.Error("inCluster returns false with Kubernetes service env present")
}
os.Unsetenv("KUBERNETES_SERVICE_HOST")
os.Unsetenv("KUBERNETES_SERVICE_PORT")
}