aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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) {