-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
config_test.go
70 lines (62 loc) · 1.53 KB
/
config_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
package main
import (
"os"
"path"
"testing"
"github.com/stretchr/testify/assert"
)
func TestReadConfigFromFile(t *testing.T) {
temporaryDirectory, err := os.MkdirTemp(os.TempDir(), "sentlog-*")
if err != nil {
t.Fatalf("creating temporary directory: %v", err)
}
t.Cleanup(func() {
err := os.RemoveAll(temporaryDirectory)
if err != nil {
t.Log(err)
}
})
// Write temporary file
payload := []byte(`---
# Sentry DSN (also can be configured via environment)
sentry_dsn: https://[email protected]/YYY
# Additional Grok pattern files
pattern_files:
- ./patterns1.txt
- ../patterns2.txt
# List of files that we want to watch
inputs:
- file: /var/log/nginx/error.log
# Patterns to find and report
patterns:
- "%{NGINX_ERROR_LOG}"
# Additional tags that will be added to the Sentry event
tags:
pattern: nginx_error
custom: tag`)
fileName := path.Join(temporaryDirectory, "config.yml")
err = os.WriteFile(fileName, payload, 0644)
if err != nil {
t.Fatalf("writing temporary file: %v", err)
}
config, err := ReadConfigFromFile(fileName)
if err != nil {
t.Error(err)
}
assert.Equal(t, &Config{
SentryDsn: "https://[email protected]/YYY",
PatternFiles: []string{"./patterns1.txt", "../patterns2.txt"},
Inputs: []FileInputConfig{
{
File: "/var/log/nginx/error.log",
Follow: nil,
FromLineNumber: nil,
Patterns: []string{"%{NGINX_ERROR_LOG}"},
Tags: map[string]string{
"pattern": "nginx_error",
"custom": "tag",
},
},
},
}, config)
}