-
Notifications
You must be signed in to change notification settings - Fork 4
/
handler_test.go
78 lines (64 loc) · 1.53 KB
/
handler_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
74
75
76
77
78
package main
import (
"encoding/json"
"io/ioutil"
"sync"
"testing"
"gopkg.in/go-playground/assert.v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)
type events struct {
Items []*v1.Event `json:"items"`
}
func TestMakeL9Event(t *testing.T) {
var wg sync.WaitGroup
e := &events{}
ch := make(chan interface{})
mCache, err := newCache()
if err != nil {
t.Fatal(err)
}
key := "814a4994-e977-4e07-be69-6a464b2169c9"
t.Run("Wait till you get the key", func(t *testing.T) {
if err := mCache.ExpireSet(
objectCacheTable, key,
&unstructured.Unstructured{}, objectCacheExpiry,
); err != nil {
t.Fatal(err)
}
})
t.Run("Make Last9 Event", func(t *testing.T) {
b, err := ioutil.ReadFile("testdata/events.log")
if err != nil {
t.Fatal(err)
}
if err := json.Unmarshal(b, e); err != nil {
t.Fatal(err)
}
c, _ := newCache()
ev, err := makeL9EventDetails(
c, e.Items[0], nil, []string{"127.0.0.1"},
)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, ev.ID, "19b4506f-95f4-4dd0-8d2d-bf7647997877")
assert.Equal(t, ev.Address[0], "127.0.0.1")
t.Run("Version value in event matches binary version", func(t *testing.T) {
assert.Equal(t, ev.Version, VERSION)
})
})
t.Run("Receive event over Handler", func(t *testing.T) {
go func() {
defer wg.Done()
msg := <-ch
x := msg.(*L9Event)
assert.Equal(t, "Scheduled", x.Reason)
}()
wg.Add(1)
h := &Handler{&kubernetesClient{}, ch, mCache, &L9K8streamConfig{}}
h.OnAdd(e.Items[0])
wg.Wait()
})
}