forked from papertrail/remote_syslog2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremote_syslog_test.go
44 lines (35 loc) · 1.08 KB
/
remote_syslog_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
package main
import (
"regexp"
"testing"
)
func TestGetHostnameFromConfig(t *testing.T) {
cm := ConfigManager{}
cm.Flags.ConfigFile = "test/config_with_host.yaml"
cm.loadConfigFile()
expectedHostname := "test-host-from-config"
if cm.Hostname() != expectedHostname {
t.Errorf("Bad hostname, expected %s but got %s", expectedHostname, cm.Hostname())
}
}
func TestGetHostnameFromCommandline(t *testing.T) {
cm := ConfigManager{}
cm.Flags.ConfigFile = "test/config_with_host.yaml"
cm.loadConfigFile()
cm.Flags.Hostname = "test-host-from-commandline"
if cm.Hostname() != cm.Flags.Hostname {
t.Errorf("Bad hostname, expected %s but got %s", cm.Flags.Hostname, cm.Hostname())
}
}
func TestFilters(t *testing.T) {
expressions := []*regexp.Regexp{}
expressions = append(expressions, regexp.MustCompile("\\d+"))
message := "test message"
if matchExps(message, expressions) {
t.Errorf("Did not expect \"%s\" to match \"%s\"", message, expressions[0])
}
message = "0000"
if !matchExps(message, expressions) {
t.Errorf("Expected \"%s\" to match \"%s\"", message, expressions[0])
}
}