Skip to content

Commit

Permalink
More rework of tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
gmallard committed Jan 23, 2017
1 parent 8f99716 commit 4b35c0a
Show file tree
Hide file tree
Showing 17 changed files with 374 additions and 238 deletions.
33 changes: 18 additions & 15 deletions ack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestAckSameConn(t *testing.T) {
// Subscribe
sc, e = conn.Subscribe(sbh)
if e != nil {
t.Fatalf("SUBSCRIBE expected [nil], got: [%v]\n", e)
t.Fatalf("TestAckSameConn SUBSCRIBE expected [nil], got: [%v]\n", e)
}

//
Expand All @@ -93,21 +93,23 @@ func TestAckSameConn(t *testing.T) {
}
e = conn.Send(sh, ms)
if e != nil {
t.Fatalf("SEND expected [nil], got: [%v]\n", e)
t.Fatalf("TestAckSameConn SEND expected [nil], got: [%v]\n", e)
}
//
// Read MessageData
select {
case md = <-sc:
case md = <-conn.MessageData:
t.Fatalf("read channel error: expected [nil], got: [%v]\n",
t.Fatalf("TestAckSameConn read channel error: expected [nil], got: [%v]\n",
md.Message.Command)
}
if md.Error != nil {
t.Fatalf("read error: expected [nil], got: [%v]\n", md.Error)
t.Fatalf("TestAckSameConn read error: expected [nil], got: [%v]\n",
md.Error)
}
if ms != md.Message.BodyString() {
t.Fatalf("message error: expected: [%v], got: [%v] Message: [%q]\n", ms, md.Message.BodyString(), md.Message)
t.Fatalf("TestAckSameConn message error: expected: [%v], got: [%v] Message: [%q]\n",
ms, md.Message.BodyString(), md.Message)
}
// Ack headers
ah := Headers{}
Expand All @@ -128,15 +130,15 @@ func TestAckSameConn(t *testing.T) {
// Make sure Apollo Jira issue APLO-88 stays fixed.
select {
case md = <-sc:
t.Fatalf("RECEIVE not expected, got: [%v]\n", md)
t.Fatalf("TestAckSameConn RECEIVE not expected, got: [%v]\n", md)
default:
}

// Unsubscribe
uh := wh.Add(HK_ID, id)
e = conn.Unsubscribe(uh)
if e != nil {
t.Fatalf("UNSUBSCRIBE expected [nil], got: [%v]\n", e)
t.Fatalf("TestAckSameConn UNSUBSCRIBE expected [nil], got: [%v]\n", e)
}

//
Expand Down Expand Up @@ -179,7 +181,7 @@ func TestAckDiffConn(t *testing.T) {
}
e = conn.Send(sh, ms)
if e != nil {
t.Fatalf("SEND expected [nil], got: [%v]\n", e)
t.Fatalf("TestAckDiffConn SEND expected [nil], got: [%v]\n", e)
}
//
checkReceived(t, conn)
Expand All @@ -192,7 +194,7 @@ func TestAckDiffConn(t *testing.T) {
ch = headersProtocol(ch, sp)
conn, e = Connect(n, ch) // Reconnect
if e != nil {
t.Fatalf("Second Connect, expected no error, got:<%v>\n", e)
t.Fatalf("TestAckDiffConn Second Connect, expected no error, got:<%v>\n", e)
}
//
// Subscribe Headers
Expand All @@ -202,20 +204,21 @@ func TestAckDiffConn(t *testing.T) {
// Subscribe
sc, e = conn.Subscribe(sbh)
if e != nil {
t.Fatalf("SUBSCRIBE expected [nil], got: [%v]\n", e)
t.Fatalf("TestAckDiffConn SUBSCRIBE expected [nil], got: [%v]\n", e)
}
// Read MessageData
select {
case md = <-sc:
case md = <-conn.MessageData:
t.Fatalf("read channel error: expected [nil], got: [%v]\n",
t.Fatalf("TestAckDiffConn read channel error: expected [nil], got: [%v]\n",
md.Message.Command)
}
if md.Error != nil {
t.Fatalf("read error: expected [nil], got: [%v]\n", md.Error)
}
if ms != md.Message.BodyString() {
t.Fatalf("message error: expected: [%v], got: [%v] Message: [%q]\n", ms, md.Message.BodyString(), md.Message)
t.Fatalf("TestAckDiffConn message error: expected: [%v], got: [%v] Message: [%q]\n",
ms, md.Message.BodyString(), md.Message)
}
// Ack headers
ah := Headers{}
Expand All @@ -231,19 +234,19 @@ func TestAckDiffConn(t *testing.T) {
// Ack
e = conn.Ack(ah)
if e != nil {
t.Fatalf("ACK expected [nil], got: [%v]\n", e)
t.Fatalf("TestAckDiffConn ACK expected [nil], got: [%v]\n", e)
}
// Make sure Apollo Jira issue APLO-88 stays fixed.
select {
case md = <-sc:
t.Fatalf("RECEIVE not expected, got: [%v]\n", md)
t.Fatalf("TestAckDiffConn RECEIVE not expected, got: [%v]\n", md)
default:
}
// Unsubscribe
uh := wh.Add(HK_ID, id)
e = conn.Unsubscribe(uh)
if e != nil {
t.Fatalf("UNSUBSCRIBE expected [nil], got: [%v]\n", e)
t.Fatalf("TestAckDiffConn UNSUBSCRIBE expected [nil], got: [%v]\n", e)
}
//
checkReceived(t, conn)
Expand Down
40 changes: 24 additions & 16 deletions codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ func TestCodecEncodeBasic(t *testing.T) {
for _, ede := range tdList {
ev := encode(ede.decoded)
if ede.encoded != ev {
t.Fatalf("ENCODE ERROR: expected: [%v] got: [%v]", ede.encoded, ev)
t.Fatalf("TestCodecEncodeBasic ENCODE ERROR: expected: [%v] got: [%v]",
ede.encoded, ev)
}
}
}
Expand All @@ -41,7 +42,8 @@ func TestCodecDecodeBasic(t *testing.T) {
for _, ede := range tdList {
dv := decode(ede.encoded)
if ede.decoded != dv {
t.Fatalf("DECODE ERROR: expected: [%v] got: [%v]", ede.decoded, dv)
t.Fatalf("TestCodecDecodeBasic DECODE ERROR: expected: [%v] got: [%v]",
ede.decoded, dv)
}
}
}
Expand Down Expand Up @@ -96,52 +98,58 @@ func TestCodecSendRecvCodec(t *testing.T) {
// Send
e = conn.Send(sh, ms)
if e != nil {
t.Fatalf("Send failed: %v protocol:%s\n", e, p)
t.Fatalf("TestCodecSendRecvCodec Send failed: %v protocol:%s\n",
e, p)
}
// Check for ERROR frame
time.Sleep(1e9 / 4) // Wait one quarter
time.Sleep(1e9 / 8) // Wait one eigth
// Poll for adhoc ERROR from server
select {
case vx := <-conn.MessageData:
t.Fatalf("Send Error: [%v] protocol:%s\n", vx, p)
t.Fatalf("TestCodecSendRecvCodec Send Error: [%v] protocol:%s\n",
vx, p)
default:
//
}
// Subscribe
sbh := wh.Add(HK_ID, v.sid)
sc, e = conn.Subscribe(sbh)
if e != nil {
t.Fatalf("Subscribe failed: %v protocol:%s\n", e, p)
t.Fatalf("TestCodecSendRecvCodec Subscribe failed: %v protocol:%s\n",
e, p)
}
if sc == nil {
t.Fatalf("Subscribe sub chan is nil protocol:%s\n", p)
t.Fatalf("TestCodecSendRecvCodec Subscribe sub chan is nil protocol:%s\n",
p)
}
//
md = MessageData{}
checkReceivedMD(t, conn, sc, "codec_test_"+p)
checkReceivedMD(t, conn, sc, "codec_test_"+p) // Receive
// Check body data
b := md.Message.BodyString()
if b != ms {
t.Fatalf("Receive expected: [%v] got: [%v] protocol:%s\n", ms, b, p)
t.Fatalf("TestCodecSendRecvCodec Receive expected: [%v] got: [%v] protocol:%s\n",
ms, b, p)
}
// Unsubscribe
e = conn.Unsubscribe(sbh)
if e != nil {
t.Fatalf("TestCodecSendRecvCodec Unsubscribe failed: %v protocol:%s\n",
e, p)
}
// Check headers
// fmt.Printf("v.rv: %q\nhdrs: %q\n\n\n", v.rv, md.Message.Headers)
for key, value := range v.rv {
hv, ok = md.Message.Headers.Contains(key)
if !ok {
t.Fatalf("Header key expected: [%v] got: [%v] protocol:%s\n",
t.Fatalf("TestCodecSendRecvCodec Header key expected: [%v] got: [%v] protocol:%s\n",
key, ok, p)
}
if value != hv {
t.Fatalf("Header value expected: [%v] got: [%v] protocol:%s\n",
t.Fatalf("TestCodecSendRecvCodec Header value expected: [%v] got: [%v] protocol:%s\n",
value, hv, p)
}
}
// Unsubscribe
e = conn.Unsubscribe(sbh)
if e != nil {
t.Fatalf("Unsubscribe failed: %v protocol:%s\n", e, p)
}
}
//
checkReceived(t, conn)
Expand Down
6 changes: 4 additions & 2 deletions connbv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ func TestConnBadValVer(t *testing.T) {
t.Errorf("TestConnBadValVer Expected error, got nil, proto: %s\n", p)
}
if e != EBADVERCLI {
t.Errorf("Expected <%v>, got <%v>, proto: %s\n", EBADVERCLI, e, p)
t.Errorf("TestConnBadValVer Expected <%v>, got <%v>, proto: %s\n",
EBADVERCLI, e, p)
}
checkReceived(t, conn)
// We are not connected by test design, check nothing around
Expand All @@ -53,7 +54,8 @@ func TestConnBadValHost(t *testing.T) {
t.Errorf("TestConnBadValHost Expected error, got nil, proto: %s\n", p)
}
if e != EREQHOST {
t.Errorf("Expected <%v>, got <%v>, proto: %s\n", EREQHOST, e, p)
t.Errorf("TestConnBadValHost Expected <%v>, got <%v>, proto: %s\n",
EREQHOST, e, p)
}
checkReceived(t, conn)
// We are not connected by test design, check nothing around
Expand Down
14 changes: 10 additions & 4 deletions conndisc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ func TestConnCDDisc(t *testing.T) {
ch := login_headers
ch = headersProtocol(ch, sp)
conn, e = Connect(n, ch)

if e != nil {
t.Fatalf("TestConnCDDisc Expected no connect error, got [%v]\n", e)
}
Expand Down Expand Up @@ -112,6 +111,7 @@ func TestConnCDDiscNoDiscReceipt(t *testing.T) {
if e != nil {
t.Fatalf("TestConnCDDiscNoDiscReceipt Expected no connect error, got [%v]\n", e)
}
// DISCONNECT Here
checkReceived(t, conn)
e = conn.Disconnect(NoDiscReceipt)
checkDisconnectError(t, e)
Expand All @@ -122,6 +122,7 @@ func TestConnCDDiscNoDiscReceipt(t *testing.T) {
t.Fatalf("TestConnCDDiscNoDiscReceipt Expected no disconnect receipt command, got [%v]\n",
conn.DisconnectReceipt.Message.Command)
}
// NO DISCONNECT checks here
_ = closeConn(t, n)
}
}
Expand All @@ -136,13 +137,16 @@ func TestConnCDDiscStompDiscReceipt(t *testing.T) {
ch = headersProtocol(ch, sp)
conn, e = Connect(n, ch)
if e != nil {
t.Fatalf("TestConnCDDiscStompDiscReceipt Expected no connect error, got [%v]\n", e)
t.Fatalf("TestConnCDDiscStompDiscReceipt Expected no connect error, got [%v]\n",
e)
}
// DISCONNECT Here
checkReceived(t, conn)
e = conn.Disconnect(Headers{HK_RECEIPT, rid})
if e != nil {

t.Fatalf("TestConnCDDiscStompDiscReceipt Expected no disconnect error, got [%v]\n", e)
t.Fatalf("TestConnCDDiscStompDiscReceipt Expected no disconnect error, got [%v]\n",
e)
}
if conn.DisconnectReceipt.Error != nil {
t.Fatalf("TestConnCDDiscStompDiscReceipt Expected no receipt error, got [%v]\n",
Expand All @@ -154,8 +158,10 @@ func TestConnCDDiscStompDiscReceipt(t *testing.T) {
t.Fatalf("TestConnCDDiscStompDiscReceipt Expected receipt-id, not received\n")
}
if rid != irid {
t.Fatalf("TestConnCDDiscStompDiscReceipt Expected receipt-id [%q], got [%q]\n", rid, irid)
t.Fatalf("TestConnCDDiscStompDiscReceipt Expected receipt-id [%q], got [%q]\n",
rid, irid)
}
// NO DISCONNECT checks here
_ = closeConn(t, n)
}
}
Expand Down
37 changes: 22 additions & 15 deletions data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@ func TestDataFrameBasic(t *testing.T) {
f := &Frame{Command: cm, Headers: wh, Body: []byte(ms)}
//
if cm != f.Command {
t.Fatalf("Command, expected: [%v], got [%v]\n", cm, f.Command)
t.Fatalf("TestDataFrameBasic Command, expected: [%v], got [%v]\n",
cm, f.Command)
}
if !wh.Compare(f.Headers) {
t.Fatalf("Headers, expected: [true], got [false], for [%v] [%v]\n",
t.Fatalf("TestDataFrameBasic Headers, expected: [true], got [false], for [%v] [%v]\n",
wh, f.Headers)
}
if ms != string(f.Body) {
t.Fatalf("Body string, expected: [%v], got [%v]\n", ms, string(f.Body))
t.Fatalf("TestDataFrameBasic Body string, expected: [%v], got [%v]\n",
ms, string(f.Body))
}
}

Expand All @@ -51,14 +53,16 @@ func TestDataMessageBasic(t *testing.T) {
m := &Message{Command: fc, Headers: wh, Body: []byte(ms)}
//
if fc != m.Command {
t.Fatalf("Command, expected: [%v], got [%v]\n", fc, m.Command)
t.Fatalf("TestDataMessageBasic Command, expected: [%v], got [%v]\n",
fc, m.Command)
}
if !wh.Compare(m.Headers) {
t.Fatalf("Headers, expected: [true], got [false], for [%v] [%v]\n",
t.Fatalf("TestDataMessageBasic Headers, expected: [true], got [false], for [%v] [%v]\n",
wh, m.Headers)
}
if ms != m.BodyString() {
t.Fatalf("Body string, expected: [%v], got [%v]\n", ms, m.BodyString())
t.Fatalf("TestDataMessageBasic Body string, expected: [%v], got [%v]\n",
ms, m.BodyString())
}
}

Expand All @@ -67,26 +71,27 @@ func TestDataMessageBasic(t *testing.T) {
*/
func TestDataprotocols(t *testing.T) {
if !Supported(SPL_10) {
t.Fatalf("Expected: [true], got: [false] for protocol level %v\n",
t.Fatalf("TestDataprotocolsExpected: [true], got: [false] for protocol level %v\n",
SPL_10)
}
if !Supported(SPL_11) {
t.Fatalf("Expected: [true], got: [false] for protocol level %v\n",
t.Fatalf("TestDataprotocols Expected: [true], got: [false] for protocol level %v\n",
SPL_11)
}
if !Supported(SPL_12) {
t.Fatalf("Expected: [true], got: [false] for protocol level %v\n",
t.Fatalf("TestDataprotocols Expected: [true], got: [false] for protocol level %v\n",
SPL_12)
}
if Supported("9.9") {
t.Fatalf("Expected: [false], got: [true] for protocol level %v\n",
t.Fatalf("TestDataprotocols Expected: [false], got: [true] for protocol level %v\n",
"9.9")
}
//
for _, v := range suptests {
b := Supported(v.v)
if b != v.s {
t.Fatalf("Expected: [%v] for protocol level [%v]\n", v.s, v.v)
t.Fatalf("TestDataprotocols Expected: [%v] for protocol level [%v]\n",
v.s, v.v)
}
}
}
Expand All @@ -97,7 +102,8 @@ func TestDataprotocols(t *testing.T) {
func TestDataProtocols(t *testing.T) {
for i, p := range Protocols() {
if supported[i] != p {
t.Fatalf("Expected [%v], got [%v]\n", supported[i], p)
t.Fatalf("TestDataProtocols Expected [%v], got [%v]\n",
supported[i], p)
}
}
}
Expand All @@ -109,7 +115,7 @@ func TestDataError(t *testing.T) {
es := "An error string"
e = Error(es)
if es != e.Error() {
t.Fatalf("Expected [%v], got [%v]\n", es, e.Error())
t.Fatalf("TestDataError Expected [%v], got [%v]\n", es, e.Error())
}
}

Expand All @@ -126,7 +132,8 @@ func TestDataMessageSize(t *testing.T) {
var w int64 = int64(len(CONNECT)) + 1 + wh.Size(b) + 1 + int64(len(ms)) + 1
r := m.Size(b)
if w != r {
t.Fatalf("Message size, expected: [%d], got [%d]\n", w, r)
t.Fatalf("TestDataMessageSize Message size, expected: [%d], got [%d]\n",
w, r)
}
}

Expand All @@ -141,7 +148,7 @@ func TestDataBrokerCmdVal(t *testing.T) {
"JUNK": false}
for k, v := range tData {
if v != validCmds[k] {
t.Fatalf("Command Validity, expected: [%t], got [%t] for key [%s]\n",
t.Fatalf("TestDataBrokerCmdVal Command Validity, expected: [%t], got [%t] for key [%s]\n",
v,
validCmds[k], k)
}
Expand Down
Loading

0 comments on commit 4b35c0a

Please sign in to comment.