Version bump.
[stompngo.git] / send_test.go
blob985d529b333da9ca3842e97043c9bcd0940d7910
1 //
2 // Copyright © 2011-2019 Guy M. Allard
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
17 package stompngo
19 import (
20 "testing"
24 Test Send Basic, one message.
26 func TestSendBasic(t *testing.T) {
27 for _, sp := range Protocols() {
28 n, _ = openConn(t)
29 ch := login_headers
30 ch = headersProtocol(ch, sp)
31 conn, e = Connect(n, ch)
32 if e != nil {
33 t.Fatalf("TestSendBasic CONNECT expected no error, got [%v]\n", e)
36 ms := "A message"
37 d := tdest("/queue/send.basiconn.01." + sp)
38 sh := Headers{HK_DESTINATION, d}
39 e = conn.Send(sh, ms)
40 if e != nil {
41 t.Fatalf("TestSendBasic Expected nil error, got [%v]\n", e)
44 e = conn.Send(empty_headers, ms)
45 if e == nil {
46 t.Fatalf("TestSendBasic Expected error, got [nil]\n")
48 if e != EREQDSTSND {
49 t.Fatalf("TestSendBasic Expected [%v], got [%v]\n", EREQDSTSND, e)
51 checkReceived(t, conn, false)
52 e = conn.Disconnect(empty_headers)
53 checkDisconnectError(t, e)
54 _ = closeConn(t, n)
59 Test Send Multiple, multiple messages, 5 to be exact.
61 func TestSendMultiple(t *testing.T) {
62 for _, sp := range Protocols() {
63 n, _ = openConn(t)
64 ch := login_headers
65 ch = headersProtocol(ch, sp)
66 conn, e = Connect(n, ch)
67 if e != nil {
68 t.Fatalf("TestSendMultiple CONNECT expected no error, got [%v]\n", e)
71 smd := multi_send_data{conn: conn,
72 dest: tdest("/queue/sendmultiple.01." + sp + "."),
73 mpref: "sendmultiple.01.message.prefix ",
74 count: 5}
75 e = sendMultiple(smd)
76 if e != nil {
77 t.Fatalf("TestSendMultiple Expected nil error, got [%v]\n", e)
80 checkReceived(t, conn, false)
81 e = conn.Disconnect(empty_headers)
82 checkDisconnectError(t, e)
83 _ = closeConn(t, n)