golang-lib/websocket/msg_test.go

53 lines
906 B
Go
Raw Normal View History

2017-10-25 18:42:44 +02:00
package websocket
import (
"testing"
2017-10-27 19:40:42 +02:00
"github.com/google/uuid"
2017-10-25 18:42:44 +02:00
"github.com/stretchr/testify/assert"
)
func TestMSGValidate(t *testing.T) {
assert := assert.New(t)
2017-10-27 19:40:42 +02:00
2017-10-25 18:42:44 +02:00
msg := &Message{}
assert.False(msg.Validate())
2017-10-27 19:40:42 +02:00
2017-10-25 18:42:44 +02:00
msg.Subject = "login"
assert.False(msg.Validate())
msg.From = &Client{}
assert.True(msg.Validate())
msg.Subject = ""
assert.False(msg.Validate())
}
2017-10-27 19:40:42 +02:00
func TestMSGAnswer(t *testing.T) {
assert := assert.New(t)
out := make(chan *Message, channelBufSize)
client := &Client{
id: uuid.New(),
out: out,
writeQuit: make(chan bool),
readQuit: make(chan bool),
}
conversationID := uuid.New()
msg := &Message{
From: client,
ID: conversationID,
}
go msg.Answer("hi", nil)
msg = <-out
assert.Equal(conversationID, msg.ID)
assert.Equal(uuid.Nil, msg.Session)
assert.Equal(client, msg.From)
assert.Equal("hi", msg.Subject)
assert.Nil(msg.Body)
}