-
Notifications
You must be signed in to change notification settings - Fork 10
/
config_test.go
73 lines (67 loc) · 1.46 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
71
72
73
package main
import (
"reflect"
"testing"
)
func getDemoConfig() config {
config := config{
Servers: make(map[string]servers),
Commands: make(map[string]commands),
}
config.Servers["test1"] = []server{
{
Host: "test1",
Name: "test1",
User: "test1",
},
{
Host: "test12",
Name: "test12",
User: "test12",
},
}
config.Commands["test_cmd"] = []command{
command("ls -al #1"),
command("ls -al #2"),
}
return config
}
var demoConfig = getDemoConfig()
func TestSet(t *testing.T) {
cOk := config{}
if cOk.set(configPath("testFiles/demo_config.yml")) != nil {
t.FailNow()
}
cNotOk := config{}
if cNotOk.set(configPath("not_demo_config.yml")) == nil {
t.FailNow()
}
cNotOk1 := config{}
if cNotOk1.set(configPath("main.go")) == nil {
t.FailNow()
}
}
func TestGetServersFromConfig(t *testing.T) {
serversArray, err := demoConfig.getServersFromConfig(serverGroup("test1"))
if err != nil {
t.FailNow()
}
if !reflect.DeepEqual(demoConfig.Servers["test1"], serversArray) {
t.FailNow()
}
if _, err = demoConfig.getServersFromConfig(serverGroup("false_group_name")); err == nil {
t.FailNow()
}
}
func TestGetCommandsFromConfig(t *testing.T) {
cmds, err := demoConfig.getCommandsFromConfig(commandName("test_cmd"))
if err != nil {
t.FailNow()
}
if !reflect.DeepEqual(demoConfig.Commands["test_cmd"], cmds) {
t.FailNow()
}
if _, err := demoConfig.getCommandsFromConfig(commandName("false_command")); err == nil {
t.FailNow()
}
}