forked from docker-archive/classicswarm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
events_test.go
57 lines (45 loc) · 1.01 KB
/
events_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
package api
import (
"fmt"
"testing"
"github.com/docker/swarm/cluster"
"github.com/stretchr/testify/assert"
)
type FakeWriter struct {
Tmp []byte
}
func (fw *FakeWriter) Write(p []byte) (n int, err error) {
fw.Tmp = append(fw.Tmp, p...)
return len(p), nil
}
func TestHandle(t *testing.T) {
eh := newEventsHandler()
assert.Equal(t, eh.Size(), 0)
fw := &FakeWriter{Tmp: []byte{}}
eh.Add("test", fw)
assert.Equal(t, eh.Size(), 1)
event := &cluster.Event{
Engine: &cluster.Engine{
ID: "node_id",
Name: "node_name",
IP: "node_ip",
Addr: "node_addr",
},
}
event.Event.Status = "status"
event.Event.Id = "id"
event.Event.From = "from"
event.Event.Time = 0
assert.NoError(t, eh.Handle(event))
str := fmt.Sprintf("{%q:%q,%q:%q,%q:%q,%q:%d,%q:{%q:%q,%q:%q,%q:%q,%q:%q}}",
"status", "status",
"id", "id",
"from", "from node:node_name",
"time", 0,
"node",
"Name", "node_name",
"Id", "node_id",
"Addr", "node_addr",
"Ip", "node_ip")
assert.Equal(t, str, string(fw.Tmp))
}