コード例 #1
0
ファイル: message_test.go プロジェクト: sech90/go-message-hub
func TestAnswerConversion(t *testing.T) {

	a1 := message.NewAnswerIdentity(testId)
	a2 := message.NewAnswerList(testList)
	a3 := message.NewAnswerRelay(testBody)

	b1 := a1.ToByteArray()
	b2 := a2.ToByteArray()
	b3 := a3.ToByteArray()

	c1 := new(message.Answer)
	c2 := new(message.Answer)
	c3 := new(message.Answer)
	c4 := new(message.Answer)

	e1 := c1.FromByteArray(b1)
	e2 := c2.FromByteArray(b2)
	e3 := c3.FromByteArray(b3)
	e4 := c4.FromByteArray(nil)

	assert.Nil(t, e1, "No error in conversion (1)")
	assert.Nil(t, e2, "No error in conversion (2)")
	assert.Nil(t, e3, "No error in conversion (3)")
	assert.NotNil(t, e4, "Conversion from nil throws an error (4)")

	assert.Nil(t, testutils.CompareAnswer(a1, c1), "Identity answer conversion wrong")
	assert.Nil(t, testutils.CompareAnswer(a2, c2), "List answer conversion wrong")
	assert.Nil(t, testutils.CompareAnswer(a3, c3), "Relay answer conversion wrong")

}
コード例 #2
0
func TestEndpointsServices(t *testing.T) {

	go s1.StartReadService(mexsocket.ModeServer)
	go s1.StartWriteService()

	go s2.StartReadService(mexsocket.ModeClient)
	go s2.StartWriteService()

	go func() { s2.Outgoing() <- tReqBody }()
	req := <-s1.Incoming()
	assert.Nil(t, testutils.CompareRequests(tReqBody, req.(*message.Request)), "request should be received correctly")

	go func() { s1.Outgoing() <- tAnsBody }()
	ans := <-s2.Incoming()
	assert.Nil(t, testutils.CompareAnswer(tAnsBody, ans.(*message.Answer)), "answer should be received correctly")
}