-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathspotter_test.go
58 lines (46 loc) · 1.52 KB
/
spotter_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
package main
import (
"testing"
"encoding/json"
"os"
)
func TestGetEvents(t *testing.T) {
container := getContainerFromFile("test/container.json")
hookSource := "test_123_hash_xyz:start,restart:pipework:eth0:{{.ID}}:192.168.242.1/24"
hooks := getHooks(hookSource)
events := GetEvents(hooks, &container)
if (events == nil) {
t.Error("Container not found by name", container.Name, "hooks: ", hookSource)
}
hookSource = "LIBVIRT_SERVICE_PORT=16509:start,restart:pipework:eth0:{{.ID}}:192.168.242.1/24"
hooks = getHooks(hookSource)
events = GetEvents(hooks, &container)
if (events == nil) {
t.Error("Container not found by env. Hooks: ", hookSource)
}
container = getContainerFromFile("test/container.json")
hookSource = "teest_123_hash_xyz:start,restart:pipework:eth0:{{.ID}}:192.168.242.1/24"
hooks = getHooks(hookSource)
events = GetEvents(hooks, &container)
if (events != nil) {
t.Error("Container shouldn't be found by name", container.Name, "hooks: ", hookSource)
}
hookSource = "LIBVIRT_SERVICE_PORT=16599:start,restart:pipework:eth0:{{.ID}}:192.168.242.1/24"
hooks = getHooks(hookSource)
events = GetEvents(hooks, &container)
if (events != nil) {
t.Error("Container shouldn't be found by env. Hooks: ", hookSource)
}
}
func getHooks(source string) hookMap {
result := hookMap{}
result.Set(source)
return result
}
func getContainerFromFile(filename string) Container {
result := Container{}
reader, _ := os.Open(filename)
decoder := json.NewDecoder(reader)
decoder.Decode(&result)
return result
}