-
Notifications
You must be signed in to change notification settings - Fork 4
/
owl_test.go
97 lines (79 loc) · 2.54 KB
/
owl_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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package owl
import (
"os"
"testing"
"github.com/stretchr/testify/require"
)
func setEnvironmentVariables(t *testing.T) {
for _, envVar := range []string{"OWL_USE_METRIC", "OWL_USE_SENTRY", "OWL_USE_SLACK"} {
err := os.Setenv(envVar, "true")
require.Nil(t, err, "should set environment variable without error")
}
}
func TestOwlInit_OK(t *testing.T) {
setEnvironmentVariables(t)
validLoggerConfig := &LoggerConfiguration{
DisplayLogs: true,
LogFilePath: "logs.json",
SentryDsn: "https://[email protected]/some-digits",
UseColors: true,
}
validMetricConfiguration := &MetricConfiguration{
WavefrontUrl: "localhost:2878",
StatsdUrl: "127.0.0.1:8125",
}
validSlackConfiguration := &SlackConfiguration{
Token: "some-token",
}
validConfigs := []Configuration{
{AppName: "test", Logger: nil, Metric: nil, Slack: nil},
{AppName: "test", Logger: validLoggerConfig, Metric: nil, Slack: nil},
{AppName: "test", Logger: nil, Metric: validMetricConfiguration, Slack: nil},
{AppName: "test", Logger: nil, Metric: nil, Slack: validSlackConfiguration},
}
for _, c := range validConfigs {
err := Init(c)
require.Nil(t, err, "should init `owl` without error")
}
}
func TestOwlInit_KO_EmptyAppName(t *testing.T) {
setEnvironmentVariables(t)
c := Configuration{AppName: "", Logger: nil, Metric: nil, Slack: nil}
err := Init(c)
require.NotNil(t, err, "should not init `owl` without error with empty `AppName`")
Stop()
}
func TestOwlInit_KO_EmptySentryDsn(t *testing.T) {
setEnvironmentVariables(t)
loggerConfig := &LoggerConfiguration{
DisplayLogs: false,
LogFilePath: "logs.json",
SentryDsn: "",
UseColors: false,
}
c := Configuration{AppName: "test", Logger: loggerConfig, Metric: nil, Slack: nil}
err := Init(c)
require.NotNil(t, err, "should not init `owl` without error with empty `AppName`")
Stop()
}
func TestOwlInit_KO_EmptyStatsdWavefrontUrl(t *testing.T) {
setEnvironmentVariables(t)
metricConfig := &MetricConfiguration{
WavefrontUrl: "",
StatsdUrl: "",
}
c := Configuration{AppName: "test", Logger: nil, Metric: metricConfig, Slack: nil}
err := Init(c)
require.NotNil(t, err, "should not init `owl` without error with both empty `StatsdUrl` and `WavefrontUrl`")
Stop()
}
func TestOwlInit_KO_EmptySlackToken(t *testing.T) {
setEnvironmentVariables(t)
slackConfig := &SlackConfiguration{
Token: "",
}
c := Configuration{AppName: "test", Logger: nil, Metric: nil, Slack: slackConfig}
err := Init(c)
require.NotNil(t, err, "should not init `owl` without error with empty Slack `Token`")
Stop()
}