-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_test.go
70 lines (57 loc) · 1.91 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 (
"github.com/NETWAYS/go-check"
"github.com/stretchr/testify/assert"
"testing"
)
func TestConfig_Bind(t *testing.T) {
plugin := check.NewConfig()
config := &Config{}
config.BindArguments(plugin.FlagSet)
plugin.ParseArguments()
assert.Equal(t, true, 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",
}
assert.NoError(t, c.Validate())
}
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
assert.Equal(t, "PROBLEM: HOST - DOWN\r\nStuff is broken!", c.FormatMessage())
// Service Problem Notification
c.checkState = "CRITICAL"
c.serviceName = "SERVICE"
assert.Equal(t, "PROBLEM: SERVICE @ HOST - CRITICAL\r\nStuff is broken!", c.FormatMessage())
// With comment
c.notificationType = "CUSTOM"
c.author = "icingaadmin"
c.comment = "ok for now"
assert.Equal(t,
"CUSTOM: SERVICE @ HOST - CRITICAL\r\n\"ok for now\" by icingaadmin\r\nStuff is broken!",
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."
assert.Equal(t,
"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...",
c.FormatMessage())
}