-
Notifications
You must be signed in to change notification settings - Fork 1
/
config_test.go
53 lines (50 loc) · 1.34 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
package main
import (
"bytes"
"encoding/json"
"reflect"
"testing"
)
func TestConfig(t *testing.T) {
c := Config{
[]Prober{{"http", "http://localhost:4040", 5}},
[]Notificator{{"pushover", "userdestination", ""},
{"smtp", "[email protected]", "[email protected]"}},
}
b, err := json.MarshalIndent(c, "", " ")
if err != nil {
t.Fatal(err)
}
// fmt.Println("TestConfig got")
// fmt.Println(string(b))
dec := json.NewDecoder(bytes.NewReader(b))
var c2 Config
if err := dec.Decode(&c2); err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(c, c2) {
t.Fatalf("Config parsing wanted %v, got %v", c, c2)
}
}
func TestSMTPAuthParse(t *testing.T) {
tests := []struct {
input string
user string
serverport string
}{{"nictuku", "nictuku", ""},
{"nictuku@server", "nictuku", "server"},
{"nictuku@server:port", "nictuku", "server:port"},
{"nictuku:password", "nictuku", ""},
{"nictuku:password@server", "nictuku", "server"},
{"nictuku:password@server:port", "nictuku", "server:port"},
}
for _, test := range tests {
user, serverport := parseSMTPAuth(test.input)
if user != test.user {
t.Errorf("parseSMTPAuth(%v), user = %v; wanted %v", test.input, user, test.user)
}
if serverport != test.serverport {
t.Errorf("parseSMTPAuth(%v), serverport = %v; wanted %v", test.input, serverport, test.serverport)
}
}
}