forked from hashicorp/consul-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbrain_test.go
63 lines (49 loc) · 1.18 KB
/
brain_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
package main
import (
"reflect"
"testing"
dep "github.com/hashicorp/consul-template/dependency"
)
func TestNewBrain(t *testing.T) {
b := NewBrain()
if b.data == nil {
t.Errorf("expected data to not be nil")
}
if b.receivedData == nil {
t.Errorf("expected receivedData to not be nil")
}
}
func TestRecall(t *testing.T) {
b := NewBrain()
d := &dep.CatalogNodes{}
nodes := []*dep.Node{&dep.Node{Node: "node", Address: "address"}}
b.Remember(d, nodes)
data, ok := b.Recall(d)
if !ok {
t.Fatal("expected data from brain")
}
result := data.([]*dep.Node)
if !reflect.DeepEqual(result, nodes) {
t.Errorf("expected %#v to be %#v", result, nodes)
}
}
func TestForget(t *testing.T) {
b := NewBrain()
list := map[dep.Dependency]interface{}{
&dep.CatalogNodes{}: []*dep.Node{},
&dep.CatalogServices{}: []*dep.CatalogService{},
&dep.File{}: "",
&dep.HealthServices{}: []*dep.HealthService{},
&dep.StoreKey{}: "",
&dep.StoreKeyPrefix{}: []*dep.KeyPair{},
}
for d, data := range list {
b.Remember(d, data)
}
for d, _ := range list {
b.Forget(d)
if _, ok := b.Recall(d); ok {
t.Errorf("expected %#v to not be forgotten", d)
}
}
}