forked from kyallanum/athena
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
75 lines (57 loc) · 2.14 KB
/
main_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
package main
import (
"os"
"testing"
config "github.com/kyallanum/athena/v1.0.0/models/config"
logs "github.com/kyallanum/athena/v1.0.0/models/logs"
)
func TestResolveFile(t *testing.T) {
os.Stdout, _ = os.Open(os.DevNull)
defer os.Stdout.Close()
logFile, _ := logs.LoadLogFile("./examples/apt-term.log")
configuration, _ := config.CreateConfiguration("./examples/apt-term-config.json")
_, err := resolveLogFile(logFile, configuration)
if err != nil {
t.Errorf("An error occurred while resolving log file: %s", err)
}
}
func TestResolveLogFileBadLog(t *testing.T) {
os.Stdout, _ = os.Open(os.DevNull)
defer os.Stdout.Close()
logFile, _ := logs.LoadLogFile("./examples/apt-term-bad.log")
configuration, _ := config.CreateConfiguration("./examples/apt-term-config.json")
_, err := resolveLogFile(logFile, configuration)
if err.Error() != "log file contains no contents" {
t.Errorf("Error was not properly returned when checking log file contents")
}
}
func TestResolveLogFileBadConfig(t *testing.T) {
os.Stdout, _ = os.Open(os.DevNull)
defer os.Stdout.Close()
logFile, _ := logs.LoadLogFile("./examples/apt-term.log")
configuration, _ := config.CreateConfiguration("./examples/apt-term-config-bad.json")
_, err := resolveLogFile(logFile, configuration)
if err.Error() != "configuration file has no contents" {
t.Errorf("Error was not properly returned when checking configuration contents")
}
}
func TestResolveLogFileNoConfigName(t *testing.T) {
logFile, _ := logs.LoadLogFile("./examples/apt-term.log")
configuration := &config.Configuration{
Rules: make([]config.Rule, 1),
}
_, err := resolveLogFile(logFile, configuration)
if err.Error() != "configuration file contains no log name" {
t.Errorf("Error was not properly returned when checking configuration name")
}
}
func TestResolveLogFileNoConfigRules(t *testing.T) {
logFile, _ := logs.LoadLogFile("./examples/apt-term.log")
configuration := &config.Configuration{
Name: "test",
}
_, err := resolveLogFile(logFile, configuration)
if err.Error() != "configuration does not have any rules" {
t.Errorf("Error was not properly returned when checking configuration rules")
}
}