-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathedge_map_test.go
43 lines (33 loc) · 1.05 KB
/
edge_map_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
package main
import (
"testing"
)
func TestInitializeEdgeMap(t *testing.T) {
edgeMap := make(map[string][]string)
namespacePodMap := make(map[string][]string)
namespacePodMap["default"] = []string{"alice", "eve", "bob"}
initializeEdgeMap(&edgeMap, &namespacePodMap)
expected := 2
if len(edgeMap["alice"]) != expected || len(edgeMap["eve"]) != expected || len(edgeMap["bob"]) != expected {
t.Errorf("Each pod must have two egress connections: got %v", edgeMap)
}
}
func TestDeduplicateEdgeMap(t *testing.T) {
edgeMap := make(map[string][]string)
edgeMap["default"] = []string{"alice", "bob", "eve", "eve"}
deduplicateEdgeMap(&edgeMap)
expected := 3
count := len(edgeMap["default"])
if count != expected {
t.Errorf("Deduplicated slice must have %d elements: got %d", expected, count)
}
}
func TestUnique(t *testing.T) {
slice := []string{"alice", "bob", "eve", "eve"}
deduplicated := unique(slice)
expected := 3
count := len(deduplicated)
if count != expected {
t.Errorf("Deduplicated slice must have %d elements: got %d", expected, count)
}
}