aboutsummaryrefslogtreecommitdiffstats
path: root/test/target_test.go
diff options
context:
space:
mode:
authorClément Bénier <clement.benier@iot.bzh>2018-08-16 15:19:17 +0200
committerClément Bénier <clement.benier@iot.bzh>2018-08-21 11:08:36 +0200
commit8c5b8a9a3d6086d08eb52572e899542d74e41fa7 (patch)
treee2efc577e063f01a8b563c1208cc15faf52466e8 /test/target_test.go
parenta0a6698dfe333595b4dc2de9c321dbcb0af6c13f (diff)
test target: listenning events for terms
Change-Id: Idbd8509b946b96b39d76bc0aede921c14a3481eb Signed-off-by: Clément Bénier <clement.benier@iot.bzh>
Diffstat (limited to 'test/target_test.go')
-rw-r--r--test/target_test.go61
1 files changed, 60 insertions, 1 deletions
diff --git a/test/target_test.go b/test/target_test.go
index 77d4bf1..bc0be58 100644
--- a/test/target_test.go
+++ b/test/target_test.go
@@ -65,10 +65,50 @@ func DisconnectTargetEvents(t *testing.T) {
assert.Nil(t, HTTPCli.Post("/events/unregister", args, nil))
}
+func ConnectTermEvents(t *testing.T, channel chan xsapiv1.TerminalConfig) {
+ sCli.Conn.On(xsapiv1.EVTTargetTerminalAdd, func(e xsapiv1.EventMsg) {
+ termEvt, _ := e.DecodeTerminalEvent()
+ channel <- termEvt
+ })
+
+ args := xsapiv1.EventRegisterArgs{Name: xsapiv1.EVTTargetTerminalAdd}
+ assert.Nil(t, HTTPCli.Post("/events/register", args, nil))
+
+ sCli.Conn.On(xsapiv1.EVTTargetTerminalStateChange, func(e xsapiv1.EventMsg) {
+ termEvt, _ := e.DecodeTerminalEvent()
+ channel <- termEvt
+ })
+
+ args = xsapiv1.EventRegisterArgs{Name: xsapiv1.EVTTargetTerminalStateChange}
+ assert.Nil(t, HTTPCli.Post("/events/register", args, nil))
+
+ sCli.Conn.On(xsapiv1.EVTTargetTerminalRemove, func(e xsapiv1.EventMsg) {
+ termEvt, _ := e.DecodeTerminalEvent()
+ channel <- termEvt
+ })
+
+ args = xsapiv1.EventRegisterArgs{Name: xsapiv1.EVTTargetTerminalRemove}
+ assert.Nil(t, HTTPCli.Post("/events/register", args, nil))
+}
+
+func DisconnectTermEvents(t *testing.T) {
+ args := xsapiv1.EventRegisterArgs{Name: xsapiv1.EVTTargetTerminalAdd}
+ assert.Nil(t, HTTPCli.Post("/events/unregister", args, nil))
+ args = xsapiv1.EventRegisterArgs{Name: xsapiv1.EVTTargetTerminalStateChange}
+ assert.Nil(t, HTTPCli.Post("/events/unregister", args, nil))
+ args = xsapiv1.EventRegisterArgs{Name: xsapiv1.EVTTargetTerminalRemove}
+ 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)
+
+ chTermEvt := make(chan xsapiv1.TerminalConfig)
+ defer close(chTermEvt)
+ ConnectTermEvents(t, chTermEvt)
+
var targetArray []xsapiv1.TargetConfig
assert.Nil(t, HTTPCli.Get("/targets", &targetArray))
assert.Equal(t, len(targetArray), 0)
@@ -80,9 +120,9 @@ 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)
+ target.Name = "fakeTargetBis"
assert.Nil(t, HTTPCli.Post("/targets", target, &targetResBis))
targetEvt = <-chTarget
assert.Equal(t, targetResBis.ID, targetEvt.ID)
@@ -95,8 +135,12 @@ func TestTarget(t *testing.T) {
}
var termRes, termResBis xsapiv1.TerminalConfig
assert.Nil(t, HTTPCli.Post("/targets/"+targetRes.ID+"/terminals", term, &termRes))
+ termEvt := <-chTermEvt
+ assert.Equal(t, termRes.ID, termEvt.ID)
term.Name = "terminalBis"
assert.Nil(t, HTTPCli.Post("/targets/"+targetResBis.ID+"/terminals", term, &termResBis))
+ termEvt = <-chTermEvt
+ assert.Equal(t, termResBis.ID, termEvt.ID)
assert.Equal(t, termRes.Status, "Enable")
assert.Equal(t, termResBis.Status, "Enable")
@@ -108,7 +152,13 @@ func TestTarget(t *testing.T) {
})
assert.Nil(t, HTTPCli.Post("/targets/"+targetRes.ID+"/terminals/"+termRes.ID+"/open", termRes, &termRes))
+ termEvt = <-chTermEvt
+ assert.Equal(t, termRes.ID, termEvt.ID)
+ assert.Equal(t, termEvt.Status, "Open")
assert.Nil(t, HTTPCli.Post("/targets/"+targetResBis.ID+"/terminals/"+termResBis.ID+"/open", termResBis, &termResBis))
+ termEvt = <-chTermEvt
+ assert.Equal(t, termResBis.ID, termEvt.ID)
+ assert.Equal(t, termEvt.Status, "Open")
assert.Equal(t, termRes.Status, "Open")
assert.Equal(t, termResBis.Status, "Open")
@@ -148,7 +198,13 @@ func TestTarget(t *testing.T) {
}
assert.Nil(t, HTTPCli.Post("/targets/"+targetRes.ID+"/terminals/"+termRes.ID+"/close", termRes, &termRes))
+ termEvt = <-chTermEvt
+ assert.Equal(t, termRes.ID, termEvt.ID)
+ assert.Equal(t, termEvt.Status, "Close")
assert.Nil(t, HTTPCli.Post("/targets/"+targetResBis.ID+"/terminals/"+termResBis.ID+"/close", termResBis, &termResBis))
+ termEvt = <-chTermEvt
+ assert.Equal(t, termResBis.ID, termEvt.ID)
+ assert.Equal(t, termEvt.Status, "Close")
assert.Equal(t, termRes.Status, "Close")
assert.Equal(t, termResBis.Status, "Close")
@@ -159,6 +215,8 @@ func TestTarget(t *testing.T) {
assert.Nil(t, HTTPCli.Get("/targets/"+targetArray[i].ID+"/terminals", &termArray))
for j := 0; j < len(termArray); j++ {
assert.Nil(t, HTTPCli.Delete("/targets/"+targetArray[i].ID+"/terminals/"+termArray[j].ID, &termRes))
+ termEvt = <-chTermEvt
+ assert.Equal(t, termRes.ID, termEvt.ID)
assert.NotNil(t, HTTPCli.Delete("/targets/"+targetArray[i].ID+"/terminals/"+termArray[j].ID, &termRes))
}
var tgtRes xsapiv1.TargetConfig
@@ -168,6 +226,7 @@ func TestTarget(t *testing.T) {
assert.Equal(t, targetArray[i].ID, tgtRes.ID)
}
DisconnectTargetEvents(t)
+ DisconnectTermEvents(t)
}
func TestTargetErrors(t *testing.T) {