Repository navigation
Expand file tree
/
Copy pathconfig_test.go
More file actions
85 lines (69 loc) · 2.28 KB
/
Copy pathconfig_test.go
File metadata and controls
85 lines (69 loc) · 2.28 KB
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
package main
import (
"github.com/NETWAYS/go-check"
"testing"
)
func TestConfig_Bind(t *testing.T) {
plugin := check.NewConfig()
config := &Config{}
config.BindArguments(plugin.FlagSet)
plugin.ParseArguments()
if !plugin.FlagSet.Parsed() {
t.Fatalf("expected CLI be parsed, got %v", plugin.FlagSet.Parsed())
}
}
func TestConfig_Validate(t *testing.T) {
c := &Config{
gateway: "brevisone.local",
username: "admin",
password: "admin",
target: "+491710000",
targetType: "number",
checkState: "DOWN",
hostName: "HOST",
notificationType: "PROBLEM",
}
err := c.Validate()
if err != nil {
t.Fatalf("expected no error, got %v", err)
}
}
func TestConfig_FormatMessage(t *testing.T) {
c := &Config{
checkState: "DOWN",
checkOutput: "Stuff is broken!",
author: "",
hostName: "HOST",
//date: "2014-01-03 11:23:08 +0000",
notificationType: "PROBLEM",
}
// Host Problem Notification
expected := "PROBLEM: HOST - DOWN\r\nStuff is broken!"
if expected != c.FormatMessage() {
t.Fatalf("expected %v, got %v", expected, c.FormatMessage())
}
// Service Problem Notification
c.checkState = "CRITICAL"
c.serviceName = "SERVICE"
expected = "PROBLEM: SERVICE @ HOST - CRITICAL\r\nStuff is broken!"
if expected != c.FormatMessage() {
t.Fatalf("expected %v, got %v", expected, c.FormatMessage())
}
// With comment
c.notificationType = "CUSTOM"
c.author = "icingaadmin"
c.comment = "ok for now"
expected = "CUSTOM: SERVICE @ HOST - CRITICAL\r\n\"ok for now\" by icingaadmin\r\nStuff is broken!"
if expected != c.FormatMessage() {
t.Fatalf("expected %v, got %v", expected, c.FormatMessage())
}
// With a long message cut off
c.checkOutput = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been" +
"the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and" +
"scrambled it to make a type specimen book."
expected = "CUSTOM: SERVICE @ HOST - CRITICAL\r\n\"ok for now\" by icingaadmin\r\n" +
"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has b..."
if expected != c.FormatMessage() {
t.Fatalf("expected %v, got %v", expected, c.FormatMessage())
}
}