-
Notifications
You must be signed in to change notification settings - Fork 1
/
UsageLoggers_test.go
51 lines (44 loc) · 1.35 KB
/
UsageLoggers_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
// © 2016-2024 Graylog, Inc.
package logger
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestProvidesEmptyDefaultUrl(t *testing.T) {
if _, err := os.Stat(".env"); err == nil {
t.Skip(".env file exists")
}
uLogger, error := GetUsageLoggers()
if error != nil {
assert.Falsef(t, true, "GetUsageLoggers failed: %s", error.Error())
}
//compare to empty string because there is no nil string in go
assert.Equal(t, "", uLogger.UrlByDefault())
}
func TestProvidesDefaultUrl(t *testing.T) {
if _, err := os.Stat(".env"); err == nil {
t.Skip(".env file exists")
}
key := "USAGE_LOGGERS_URL"
defer os.Setenv(key, os.Getenv(key))
url := "http://thisurlisnotfrom.env/file"
os.Setenv(key, url)
uLogger, error := GetUsageLoggers()
if error != nil {
assert.Falsef(t, true, "GetUsageLoggers failed: %s", error.Error())
}
//compare to hard-coded string assigned to url above
assert.Equal(t, url, uLogger.UrlByDefault())
}
func TestProvidesDefaultUrlFromFile(t *testing.T) {
if _, err := os.Stat(".env"); err != nil {
t.Skip(".env file does not exist")
}
uLogger, error := GetUsageLoggers()
if error != nil {
assert.Falsef(t, true, "GetUsageLoggers failed: %s", error.Error())
}
//compare to hard-coded string that must also be set inside a .env file
assert.Equal(t, "http://thisurlisfrom.env/file", uLogger.UrlByDefault())
}