src.dualinventive.com/go/websocketserver/internal/mtiwss/mtiwss_test.go

41 lines
919 B
Go

package mtiwss
import (
"testing"
"github.com/stretchr/testify/assert"
"src.dualinventive.com/go/websocketserver/internal/mtiwss/testutil"
)
// Realtime request routed to mtiwss and terminated at the websocket subscription handler
const mtiWssReqRealtimeRequest = `{
"dinetrpc": 1,
"time":1502356573468,
"req":"realtime:request",
"id":0,
"user:id":1,
"params": {
"devices": [
{ "device:uid":"001fc23154ff65065182565553470187" }
],
"projects":[],
"token":"66d15eaa0ac928346be02a97bfd65df3a534f14c"
}
}`
func TestRealtimeReqRep(t *testing.T) {
fep := testutil.New(Endpoint)
defer fep.Close()
m := New(fep.URL())
// Default is empty response
rep, _ := m.Request([]byte(mtiWssReqRealtimeRequest))
assert.Equal(t, []byte{}, rep)
// Set an dummy response
fep.SetResponse(`Hello world!`)
rep, _ = m.Request([]byte(mtiWssReqRealtimeRequest))
assert.Equal(t, []byte(`Hello world!`), rep)
}