summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorClément Bénier <clement.benier@iot.bzh>2018-08-16 14:18:28 +0200
committerClément Bénier <clement.benier@iot.bzh>2018-08-21 11:08:36 +0200
commita0a6698dfe333595b4dc2de9c321dbcb0af6c13f (patch)
treeea5b19375ddb7d58842d383186164d1f04031bad /test
parentec12c77af9b30e7ae29c28863dccf7968ab35fb6 (diff)
test target: update -> listen to events
Change-Id: I21026ea34566239a23c3d8bac39b888618169a4b Signed-off-by: Clément Bénier <clement.benier@iot.bzh>
Diffstat (limited to 'test')
-rw-r--r--test/target_test.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/test/target_test.go b/test/target_test.go
index 1cfaa94..77d4bf1 100644
--- a/test/target_test.go
+++ b/test/target_test.go
@@ -40,7 +40,35 @@ func flushChannelTerm(channel chan xsapiv1.TerminalOutMsg, ms time.Duration) {
}
}
+func ConnectTargetEvents(t *testing.T, channel chan xsapiv1.TargetConfig) {
+ sCli.Conn.On(xsapiv1.EVTTargetAdd, func(e xsapiv1.EventMsg) {
+ target, _ := e.DecodeTargetEvent()
+ channel <- target
+ })
+
+ args := xsapiv1.EventRegisterArgs{Name: xsapiv1.EVTTargetAdd}
+ assert.Nil(t, HTTPCli.Post("/events/register", args, nil))
+
+ sCli.Conn.On(xsapiv1.EVTTargetRemove, func(e xsapiv1.EventMsg) {
+ target, _ := e.DecodeTargetEvent()
+ channel <- target
+ })
+
+ args = xsapiv1.EventRegisterArgs{Name: xsapiv1.EVTTargetRemove}
+ assert.Nil(t, HTTPCli.Post("/events/register", args, nil))
+}
+
+func DisconnectTargetEvents(t *testing.T) {
+ args := xsapiv1.EventRegisterArgs{Name: xsapiv1.EVTTargetAdd}
+ assert.Nil(t, HTTPCli.Post("/events/unregister", args, nil))
+ args = xsapiv1.EventRegisterArgs{Name: xsapiv1.EVTTargetRemove}
+ assert.Nil(t, HTTPCli.Post("/events/unregister", args, nil))
+}
+
func TestTarget(t *testing.T) {
+ chTarget := make(chan xsapiv1.TargetConfig)
+ defer close(chTarget)
+ ConnectTargetEvents(t, chTarget)
var targetArray []xsapiv1.TargetConfig
assert.Nil(t, HTTPCli.Get("/targets", &targetArray))
assert.Equal(t, len(targetArray), 0)
@@ -53,7 +81,11 @@ func TestTarget(t *testing.T) {
var targetRes, targetResBis xsapiv1.TargetConfig
assert.Nil(t, HTTPCli.Post("/targets", target, &targetRes))
target.Name = "fakeTargetBis"
+ targetEvt := <-chTarget
+ assert.Equal(t, targetRes.ID, targetEvt.ID)
assert.Nil(t, HTTPCli.Post("/targets", target, &targetResBis))
+ targetEvt = <-chTarget
+ assert.Equal(t, targetResBis.ID, targetEvt.ID)
assert.Equal(t, targetRes.Status, "Enable")
assert.Equal(t, targetResBis.Status, "Enable")
@@ -131,8 +163,11 @@ func TestTarget(t *testing.T) {
}
var tgtRes xsapiv1.TargetConfig
assert.Nil(t, HTTPCli.Delete("/targets/"+targetArray[i].ID, &tgtRes))
+ targetEvt = <-chTarget
+ assert.Equal(t, tgtRes.ID, targetEvt.ID)
assert.Equal(t, targetArray[i].ID, tgtRes.ID)
}
+ DisconnectTargetEvents(t)
}
func TestTargetErrors(t *testing.T) {