-
Notifications
You must be signed in to change notification settings - Fork 4
/
rsyslog-logger_test.go
91 lines (76 loc) · 1.99 KB
/
rsyslog-logger_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
package main
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestRenderRsyslogTemplate(t *testing.T) {
hostname, err := os.Hostname()
var rsyslog = Rsyslog{
WorkDir: "/foo/bar",
}
label := map[string]string{
"logs.enabled": "true",
}
taskInfo := TaskInfo{
App: "/test.aayush.http",
Hostname: hostname,
Labels: label,
TaskID: "abcdefghij",
CWD: "/foo/bar",
FileNames: []string{"test_file_name.txt"},
}
expected := `
######################################
# Created via marathon-logger,
# PLEASE DON'T EDIT THIS FILE MANUALLY
# Name - /test.aayush.http
# File - [test_file_name.txt]
######################################
module(load="imfile")
input(type="imfile"
File="/foo/bar/abcdefghij/test_file_name.txt"
Tag="test.aayush.http abcdefghij test_file_name.txt"
Severity="info")
`
template, err := rsyslog.render(taskInfo)
assert.NoError(t, err)
assert.Equal(t, expected, template)
}
func TestRenderRsyslogTemplateForMultipleFiles(t *testing.T) {
hostname, err := os.Hostname()
var rsyslog = Rsyslog{
WorkDir: "/foo/bar",
}
label := map[string]string{
"logs.enabled": "true",
}
taskInfo := TaskInfo{
App: "/test.aayush.http",
Hostname: hostname,
Labels: label,
TaskID: "abcdefghij",
CWD: "/foo/bar",
FileNames: []string{"test_file_name1.txt","test_file_name2.txt"},
}
expected := `
######################################
# Created via marathon-logger,
# PLEASE DON'T EDIT THIS FILE MANUALLY
# Name - /test.aayush.http
# File - [test_file_name1.txt test_file_name2.txt]
######################################
module(load="imfile")
input(type="imfile"
File="/foo/bar/abcdefghij/test_file_name1.txt"
Tag="test.aayush.http abcdefghij test_file_name1.txt"
Severity="info")
input(type="imfile"
File="/foo/bar/abcdefghij/test_file_name2.txt"
Tag="test.aayush.http abcdefghij test_file_name2.txt"
Severity="info")
`
template, err := rsyslog.render(taskInfo)
assert.NoError(t, err)
assert.Equal(t, expected, template)
}