You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2018/10/24 00:24:35 UTC
[1/3] qpid-proton git commit: PROTON-1910: [go] fix faulty message
test
Repository: qpid-proton
Updated Branches:
refs/heads/master c36a1a711 -> 90dbf46cc
PROTON-1910: [go] fix faulty message test
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/d8cebe49
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/d8cebe49
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/d8cebe49
Branch: refs/heads/master
Commit: d8cebe494cac78ba6959ada4af2b3fc8e958769d
Parents: 674e023
Author: Alan Conway <ac...@redhat.com>
Authored: Fri Oct 12 09:25:38 2018 -0400
Committer: Alan Conway <ac...@redhat.com>
Committed: Tue Oct 23 20:04:07 2018 -0400
----------------------------------------------------------------------
go/src/qpid.apache.org/amqp/message.go | 4 ++--
go/src/qpid.apache.org/amqp/message_test.go | 6 +++---
2 files changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/d8cebe49/go/src/qpid.apache.org/amqp/message.go
----------------------------------------------------------------------
diff --git a/go/src/qpid.apache.org/amqp/message.go b/go/src/qpid.apache.org/amqp/message.go
index e96b331..0589d67 100644
--- a/go/src/qpid.apache.org/amqp/message.go
+++ b/go/src/qpid.apache.org/amqp/message.go
@@ -117,7 +117,7 @@ type Message interface {
ReplyToGroupId() string
SetReplyToGroupId(string)
- // Property map set by the application to be carried with the message.
+ // Properties set by the application to be carried with the message.
// Values must be simple types (not maps, lists or sequences)
ApplicationProperties() map[string]interface{}
SetApplicationProperties(map[string]interface{})
@@ -151,7 +151,7 @@ type Message interface {
// Marshal a Go value into the message body, synonym for SetBody()
Marshal(interface{})
- // Unmarshal the message body into the value pointed to by v. See amqp.Unmarshal()
+ // Unmarshal the message body, using amqp.Unmarshal()
Unmarshal(interface{})
// Encode encodes the message as AMQP data. If buffer is non-nil and is large enough
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/d8cebe49/go/src/qpid.apache.org/amqp/message_test.go
----------------------------------------------------------------------
diff --git a/go/src/qpid.apache.org/amqp/message_test.go b/go/src/qpid.apache.org/amqp/message_test.go
index 321a9a0..9899bd5 100644
--- a/go/src/qpid.apache.org/amqp/message_test.go
+++ b/go/src/qpid.apache.org/amqp/message_test.go
@@ -39,6 +39,9 @@ func roundTrip(m Message) error {
func TestDefaultMessage(t *testing.T) {
m := NewMessage()
+ if err := roundTrip(m); err != nil {
+ t.Error(err)
+ }
mv := reflect.ValueOf(m)
// Check defaults
for _, x := range []struct {
@@ -75,9 +78,6 @@ func TestDefaultMessage(t *testing.T) {
t.Errorf("%s: %s", x.method, err)
}
}
- if err := roundTrip(m); err != nil {
- t.Error(err)
- }
if err := checkEqual("Message{}", m.String()); err != nil {
t.Error(err)
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[2/3] qpid-proton git commit: NO-JIRA: [go] Clean up warnings from
`go vet -shadow`
Posted by ac...@apache.org.
NO-JIRA: [go] Clean up warnings from `go vet -shadow`
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/674e023f
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/674e023f
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/674e023f
Branch: refs/heads/master
Commit: 674e023f087797fd5d0e3e9fa228a7a02f21dd46
Parents: c36a1a7
Author: Alan Conway <ac...@redhat.com>
Authored: Thu Oct 11 18:56:23 2018 -0400
Committer: Alan Conway <ac...@redhat.com>
Committed: Tue Oct 23 20:04:07 2018 -0400
----------------------------------------------------------------------
go/src/qpid.apache.org/amqp/interop_test.go | 11 +++++++----
go/src/qpid.apache.org/amqp/marshal_test.go | 14 +++++++-------
go/src/qpid.apache.org/amqp/message_test.go | 17 +++++++++--------
go/src/qpid.apache.org/electron/benchmark_test.go | 12 ++++++------
go/src/qpid.apache.org/electron/electron_test.go | 4 ++--
go/src/qpid.apache.org/electron/session.go | 12 ++++++------
go/src/qpid.apache.org/proton/message.go | 14 +++++++-------
7 files changed, 44 insertions(+), 40 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/674e023f/go/src/qpid.apache.org/amqp/interop_test.go
----------------------------------------------------------------------
diff --git a/go/src/qpid.apache.org/amqp/interop_test.go b/go/src/qpid.apache.org/amqp/interop_test.go
index 8ec6734..0d9d204 100644
--- a/go/src/qpid.apache.org/amqp/interop_test.go
+++ b/go/src/qpid.apache.org/amqp/interop_test.go
@@ -81,7 +81,8 @@ func checkDecode(d *Decoder, want interface{}, gotPtr interface{}, t *testing.T)
t.Error("Unmarshal failed", err)
return
}
- if err := checkEqual(n, len(bytes)); err != nil {
+ err = checkEqual(n, len(bytes))
+ if err != nil {
t.Error("Bad unmarshal length", err)
return
}
@@ -246,8 +247,10 @@ func TestStrings(t *testing.T) {
if !strings.Contains(err.Error(), "cannot unmarshal") {
t.Error(err)
}
- _, err = Unmarshal([]byte{}, nil)
- if err := checkEqual(err, EndOfData); err != nil {
+ if _, err = Unmarshal([]byte{}, nil); err != nil {
+ t.Error(err)
+ }
+ if err = checkEqual(err, EndOfData); err != nil {
t.Error(err)
}
_, err = Unmarshal([]byte("foobar"), nil)
@@ -365,7 +368,7 @@ func TODO_TestMessage(t *testing.T) {
if err != nil {
t.Fatal(err)
} else {
- if err := checkEqual(m.Body(), "hello"); err != nil {
+ if err = checkEqual(m.Body(), "hello"); err != nil {
t.Error(err)
}
}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/674e023f/go/src/qpid.apache.org/amqp/marshal_test.go
----------------------------------------------------------------------
diff --git a/go/src/qpid.apache.org/amqp/marshal_test.go b/go/src/qpid.apache.org/amqp/marshal_test.go
index b1d1225..c489365 100644
--- a/go/src/qpid.apache.org/amqp/marshal_test.go
+++ b/go/src/qpid.apache.org/amqp/marshal_test.go
@@ -125,7 +125,7 @@ func TestAnyMap(t *testing.T) {
t.Error(err)
}
var out AnyMap
- if _, err := Unmarshal(bytes, &out); err != nil {
+ if _, err = Unmarshal(bytes, &out); err != nil {
t.Error(err)
}
if err = checkEqual(AnyMap(nil), out); err != nil {
@@ -137,7 +137,7 @@ func TestAnyMap(t *testing.T) {
if err != nil {
t.Error(err)
}
- if _, err := Unmarshal(bytes, &out); err != nil {
+ if _, err = Unmarshal(bytes, &out); err != nil {
t.Error(err)
}
if err = checkEqual(AnyMap(nil), out); err != nil {
@@ -150,7 +150,7 @@ func TestAnyMap(t *testing.T) {
if err != nil {
t.Error(err)
}
- if _, err := Unmarshal(bytes, &out); err != nil {
+ if _, err = Unmarshal(bytes, &out); err != nil {
t.Error(err)
}
if err = checkEqual(in, out); err != nil {
@@ -167,7 +167,7 @@ func TestBadMap(t *testing.T) {
}
m := Map{}
// Should fail to unmarshal to a map
- if _, err := Unmarshal(bytes, &m); err != nil {
+ if _, err = Unmarshal(bytes, &m); err != nil {
if !strings.Contains(err.Error(), "key []string{\"x\", \"y\"} is not comparable") {
t.Error(err)
}
@@ -176,14 +176,14 @@ func TestBadMap(t *testing.T) {
}
// Should unmarshal to an AnyMap
var out AnyMap
- if _, err := Unmarshal(bytes, &out); err != nil {
+ if _, err = Unmarshal(bytes, &out); err != nil {
t.Error(err)
} else if err = checkEqual(in, out); err != nil {
t.Error(err)
}
// Should unmarshal to interface{} as AnyMap
var v interface{}
- if _, err := Unmarshal(bytes, &v); err != nil {
+ if _, err = Unmarshal(bytes, &v); err != nil {
t.Error(err)
} else if err = checkEqual(in, v); err != nil {
t.Error(err)
@@ -195,7 +195,7 @@ func TestBadMap(t *testing.T) {
t.Error(err)
}
v = nil
- if _, err := Unmarshal(bytes, &v); err != nil {
+ if _, err = Unmarshal(bytes, &v); err != nil {
t.Error(err)
} else if err = checkEqual(in, v); err != nil {
t.Error(err)
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/674e023f/go/src/qpid.apache.org/amqp/message_test.go
----------------------------------------------------------------------
diff --git a/go/src/qpid.apache.org/amqp/message_test.go b/go/src/qpid.apache.org/amqp/message_test.go
index 668ca49..321a9a0 100644
--- a/go/src/qpid.apache.org/amqp/message_test.go
+++ b/go/src/qpid.apache.org/amqp/message_test.go
@@ -26,13 +26,15 @@ import (
)
func roundTrip(m Message) error {
- var err error
- if buffer, err := m.Encode(nil); err == nil {
- if m2, err := DecodeMessage(buffer); err == nil {
- err = checkEqual(m, m2)
- }
+ buffer, err := m.Encode(nil)
+ if err != nil {
+ return err
}
- return err
+ m2, err := DecodeMessage(buffer)
+ if err != nil {
+ return err
+ }
+ return checkEqual(m, m2)
}
func TestDefaultMessage(t *testing.T) {
@@ -265,10 +267,9 @@ func BenchmarkNewMessageAll(b *testing.B) {
func BenchmarkEncode(b *testing.B) {
m := setMessageProperties(NewMessageWith("hello"))
- var buf []byte
b.ResetTimer()
for n := 0; n < b.N; n++ {
- buf, err := m.Encode(buf)
+ buf, err := m.Encode(nil)
if err != nil {
b.Fatal(err)
}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/674e023f/go/src/qpid.apache.org/electron/benchmark_test.go
----------------------------------------------------------------------
diff --git a/go/src/qpid.apache.org/electron/benchmark_test.go b/go/src/qpid.apache.org/electron/benchmark_test.go
index ae9d47c..0de53d8 100644
--- a/go/src/qpid.apache.org/electron/benchmark_test.go
+++ b/go/src/qpid.apache.org/electron/benchmark_test.go
@@ -42,7 +42,7 @@ type bmCommon struct {
done sync.WaitGroup
}
-func makeBmCommon(p *pair, waitCount int) bmCommon {
+func newBmCommon(p *pair, waitCount int) *bmCommon {
bm := bmCommon{p: p, b: p.t.(*testing.B)}
bm.p.capacity = *capacity
bm.p.prefetch = true
@@ -50,7 +50,7 @@ func makeBmCommon(p *pair, waitCount int) bmCommon {
bm.ack = make(chan Outcome, *capacity)
bm.done.Add(waitCount)
bm.b.ResetTimer()
- return bm
+ return &bm
}
func (bm *bmCommon) receiveAccept() {
@@ -74,7 +74,7 @@ func (bm *bmCommon) outcomes() {
var emptyMsg = amqp.NewMessage()
func BenchmarkSendForget(b *testing.B) {
- bm := makeBmCommon(newPipe(b, nil, nil), 1)
+ bm := newBmCommon(newPipe(b, nil, nil), 1)
defer bm.p.close()
go func() { // Receive, no ack
@@ -93,7 +93,7 @@ func BenchmarkSendForget(b *testing.B) {
}
func BenchmarkSendSync(b *testing.B) {
- bm := makeBmCommon(newPipe(b, nil, nil), 1)
+ bm := newBmCommon(newPipe(b, nil, nil), 1)
defer bm.p.close()
go bm.receiveAccept()
@@ -104,7 +104,7 @@ func BenchmarkSendSync(b *testing.B) {
}
func BenchmarkSendAsync(b *testing.B) {
- bm := makeBmCommon(newPipe(b, nil, nil), 2)
+ bm := newBmCommon(newPipe(b, nil, nil), 2)
defer bm.p.close()
go bm.outcomes() // Handle outcomes
@@ -118,7 +118,7 @@ func BenchmarkSendAsync(b *testing.B) {
// Create a new message for each send, with body and property.
func BenchmarkSendAsyncNewMessage(b *testing.B) {
body := strings.Repeat("x", *bodySize)
- bm := makeBmCommon(newPipe(b, nil, nil), 2)
+ bm := newBmCommon(newPipe(b, nil, nil), 2)
defer bm.p.close()
go bm.outcomes() // Handle outcomes
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/674e023f/go/src/qpid.apache.org/electron/electron_test.go
----------------------------------------------------------------------
diff --git a/go/src/qpid.apache.org/electron/electron_test.go b/go/src/qpid.apache.org/electron/electron_test.go
index a648a18..2517de1 100644
--- a/go/src/qpid.apache.org/electron/electron_test.go
+++ b/go/src/qpid.apache.org/electron/electron_test.go
@@ -70,7 +70,7 @@ func TestClientSender(t *testing.T) {
}
// Server send ack
- if err := rm.Reject(); err != nil {
+ if err = rm.Reject(); err != nil {
t.Error(err)
}
// Client get ack.
@@ -139,7 +139,7 @@ func TestTimeouts(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- if err := rm.Accept(); err != nil {
+ if err = rm.Accept(); err != nil {
t.Fatal(err)
}
// Sender get ack
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/674e023f/go/src/qpid.apache.org/electron/session.go
----------------------------------------------------------------------
diff --git a/go/src/qpid.apache.org/electron/session.go b/go/src/qpid.apache.org/electron/session.go
index 6dae354..7dc6030 100644
--- a/go/src/qpid.apache.org/electron/session.go
+++ b/go/src/qpid.apache.org/electron/session.go
@@ -89,11 +89,11 @@ func (s *session) Sender(setting ...LinkOption) (snd Sender, err error) {
if s.Error() != nil {
return s.Error()
}
- l, err := makeLocalLink(s, true, setting...)
- if err == nil {
+ l, err2 := makeLocalLink(s, true, setting...)
+ if err2 == nil {
snd = newSender(l)
}
- return err
+ return err2
})
return
}
@@ -103,11 +103,11 @@ func (s *session) Receiver(setting ...LinkOption) (rcv Receiver, err error) {
if s.Error() != nil {
return s.Error()
}
- l, err := makeLocalLink(s, false, setting...)
- if err == nil {
+ l, err2 := makeLocalLink(s, false, setting...)
+ if err2 == nil {
rcv = newReceiver(l)
}
- return err
+ return err2
})
return
}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/674e023f/go/src/qpid.apache.org/proton/message.go
----------------------------------------------------------------------
diff --git a/go/src/qpid.apache.org/proton/message.go b/go/src/qpid.apache.org/proton/message.go
index 7c166a5..1f8ebe5 100644
--- a/go/src/qpid.apache.org/proton/message.go
+++ b/go/src/qpid.apache.org/proton/message.go
@@ -44,7 +44,8 @@ func (d Delivery) HasMessage() bool { return !d.IsNil() && d.Readable() && !d.Pa
// Will return an error if message is incomplete or not current.
func (delivery Delivery) Message() (amqp.Message, error) {
var err error
- if bytes, err := delivery.MessageBytes(); err == nil {
+ bytes, err := delivery.MessageBytes()
+ if err == nil {
m := amqp.NewMessage()
err = m.Decode(bytes)
return m, err
@@ -83,13 +84,12 @@ func nextTag() string {
// Send sends a amqp.Message over a Link.
// Returns a Delivery that can be use to determine the outcome of the message.
func (link Link) Send(m amqp.Message) (Delivery, error) {
- var err error
- if bytes, err := m.Encode(nil); err == nil {
- if d, err := link.SendMessageBytes(bytes); err == nil {
- return d, err
- }
+ bytes, err := m.Encode(nil)
+ if err != nil {
+ return Delivery{}, err
}
- return Delivery{}, err
+ d, err := link.SendMessageBytes(bytes)
+ return d, err
}
// SendMessageBytes sends encoded bytes of an amqp.Message over a Link.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[3/3] qpid-proton git commit: NO-JIRA: [go] common internal/test
package for qpid.apache.org
Posted by ac...@apache.org.
NO-JIRA: [go] common internal/test package for qpid.apache.org
Common utilities to simplify test code.
Updated package tests to use the common code.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/90dbf46c
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/90dbf46c
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/90dbf46c
Branch: refs/heads/master
Commit: 90dbf46cc6a41d64faf3c46b4749075996adfdc0
Parents: d8cebe4
Author: Alan Conway <ac...@redhat.com>
Authored: Fri Oct 12 12:02:24 2018 -0400
Committer: Alan Conway <ac...@redhat.com>
Committed: Tue Oct 23 20:21:14 2018 -0400
----------------------------------------------------------------------
go/src/qpid.apache.org/amqp/interop_test.go | 30 ++++----
go/src/qpid.apache.org/amqp/marshal_test.go | 65 +++++++---------
go/src/qpid.apache.org/amqp/message_test.go | 28 +++----
go/src/qpid.apache.org/amqp/types_test.go | 31 ++++----
go/src/qpid.apache.org/electron/auth_test.go | 12 +--
.../qpid.apache.org/electron/benchmark_test.go | 7 +-
go/src/qpid.apache.org/electron/common_test.go | 46 ++----------
.../qpid.apache.org/electron/electron_test.go | 25 ++++---
go/src/qpid.apache.org/electron/link_test.go | 26 ++++---
go/src/qpid.apache.org/internal/test/test.go | 78 ++++++++++++++++++++
go/src/qpid.apache.org/proton/proton_test.go | 38 +++-------
11 files changed, 200 insertions(+), 186 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/90dbf46c/go/src/qpid.apache.org/amqp/interop_test.go
----------------------------------------------------------------------
diff --git a/go/src/qpid.apache.org/amqp/interop_test.go b/go/src/qpid.apache.org/amqp/interop_test.go
index 0d9d204..c3b0906 100644
--- a/go/src/qpid.apache.org/amqp/interop_test.go
+++ b/go/src/qpid.apache.org/amqp/interop_test.go
@@ -30,6 +30,8 @@ import (
"reflect"
"strings"
"testing"
+
+ "qpid.apache.org/internal/test"
)
var skipped = false
@@ -65,7 +67,7 @@ func checkDecode(d *Decoder, want interface{}, gotPtr interface{}, t *testing.T)
return
}
got := reflect.ValueOf(gotPtr).Elem().Interface()
- if err := checkEqual(want, got); err != nil {
+ if err := test.Differ(want, got); err != nil {
t.Error("Decode bad value:", err)
return
}
@@ -81,13 +83,13 @@ func checkDecode(d *Decoder, want interface{}, gotPtr interface{}, t *testing.T)
t.Error("Unmarshal failed", err)
return
}
- err = checkEqual(n, len(bytes))
+ err = test.Differ(n, len(bytes))
if err != nil {
t.Error("Bad unmarshal length", err)
return
}
got = reflect.ValueOf(gotPtr).Elem().Interface()
- if err = checkEqual(want, got); err != nil {
+ if err = test.Differ(want, got); err != nil {
t.Error("Bad unmarshal value", err)
return
}
@@ -165,7 +167,7 @@ func checkDecodeInterface(d *Decoder, want interface{}, t *testing.T) {
t.Error("Decode failed", err)
return
}
- if err := checkEqual(want, got); err != nil {
+ if err := test.Differ(want, got); err != nil {
t.Error(err)
return
}
@@ -180,11 +182,11 @@ func checkDecodeInterface(d *Decoder, want interface{}, t *testing.T) {
t.Error(err)
return
}
- if err := checkEqual(n, len(bytes)); err != nil {
+ if err := test.Differ(n, len(bytes)); err != nil {
t.Error(err)
return
}
- if err := checkEqual(want, got2); err != nil {
+ if err := test.Differ(want, got2); err != nil {
t.Error(err)
return
}
@@ -247,12 +249,8 @@ func TestStrings(t *testing.T) {
if !strings.Contains(err.Error(), "cannot unmarshal") {
t.Error(err)
}
- if _, err = Unmarshal([]byte{}, nil); err != nil {
- t.Error(err)
- }
- if err = checkEqual(err, EndOfData); err != nil {
- t.Error(err)
- }
+ _, err = Unmarshal([]byte{}, nil)
+ test.ErrorIf(t, test.Differ(err, EndOfData))
_, err = Unmarshal([]byte("foobar"), nil)
if !strings.Contains(err.Error(), "invalid-argument") {
t.Error(err)
@@ -313,7 +311,7 @@ func TestEncodeDecode(t *testing.T) {
t.Error(err)
}
- if err := checkEqual(in, out); err != nil {
+ if err := test.Differ(in, out); err != nil {
t.Error(err)
}
}
@@ -344,7 +342,7 @@ func TestMap(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- if err = checkEqual(m, i); err != nil {
+ if err = test.Differ(m, i); err != nil {
t.Fatal(err)
}
}
@@ -368,7 +366,7 @@ func TODO_TestMessage(t *testing.T) {
if err != nil {
t.Fatal(err)
} else {
- if err = checkEqual(m.Body(), "hello"); err != nil {
+ if err = test.Differ(m.Body(), "hello"); err != nil {
t.Error(err)
}
}
@@ -378,7 +376,7 @@ func TODO_TestMessage(t *testing.T) {
if err != nil {
t.Error(err)
} else {
- if err = checkEqual(bytes, bytes2); err != nil {
+ if err = test.Differ(bytes, bytes2); err != nil {
t.Error(err)
}
}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/90dbf46c/go/src/qpid.apache.org/amqp/marshal_test.go
----------------------------------------------------------------------
diff --git a/go/src/qpid.apache.org/amqp/marshal_test.go b/go/src/qpid.apache.org/amqp/marshal_test.go
index c489365..f3c10a3 100644
--- a/go/src/qpid.apache.org/amqp/marshal_test.go
+++ b/go/src/qpid.apache.org/amqp/marshal_test.go
@@ -22,50 +22,35 @@ package amqp
import (
"strings"
"testing"
+
+ "qpid.apache.org/internal/test"
)
func TestSymbolKey(t *testing.T) {
bytes, err := Marshal(AnnotationKeySymbol("foo"), nil)
- if err != nil {
- t.Fatal(err)
- }
+ test.FatalIf(t, err)
var k AnnotationKey
- if _, err := Unmarshal(bytes, &k); err != nil {
- t.Error(err)
- }
- if err := checkEqual("foo", string(k.Get().(Symbol))); err != nil {
- t.Error(err)
- }
+ _, err = Unmarshal(bytes, &k)
+ test.ErrorIf(t, err)
+ test.ErrorIf(t, test.Differ("foo", string(k.Get().(Symbol))))
var sym Symbol
- if _, err := Unmarshal(bytes, &sym); err != nil {
- t.Error(err)
- }
- if err := checkEqual("foo", sym.String()); err != nil {
- t.Error(err)
- }
-
+ _, err = Unmarshal(bytes, &sym)
+ test.ErrorIf(t, err)
+ test.ErrorIf(t, test.Differ("foo", sym.String()))
}
func TestStringKey(t *testing.T) {
bytes, err := Marshal(AnnotationKeyString("foo"), nil)
- if err != nil {
- t.Fatal(err)
- }
+ test.FatalIf(t, err)
var k AnnotationKey
- if _, err := Unmarshal(bytes, &k); err != nil {
- t.Error(err)
- }
- if err := checkEqual("foo", string(k.Get().(Symbol))); err != nil {
- t.Error(err)
- }
- var s string
- if _, err := Unmarshal(bytes, &s); err != nil {
- t.Error(err)
- }
- if err := checkEqual("foo", s); err != nil {
- t.Error(err)
- }
+ _, err = Unmarshal(bytes, &k)
+ test.ErrorIf(t, err)
+ test.ErrorIf(t, test.Differ("foo", string(k.Get().(Symbol))))
+ var s string
+ _, err = Unmarshal(bytes, &s)
+ test.ErrorIf(t, err)
+ test.ErrorIf(t, test.Differ("foo", s))
}
func TestIntKey(t *testing.T) {
@@ -95,7 +80,7 @@ func TestMapToMap(t *testing.T) {
if bytes, err := Marshal(in, nil); err == nil {
var out Map
if _, err := Unmarshal(bytes, &out); err == nil {
- if err = checkEqual(in, out); err != nil {
+ if err = test.Differ(in, out); err != nil {
t.Error(err)
}
} else {
@@ -109,7 +94,7 @@ func TestMapToInterface(t *testing.T) {
if bytes, err := Marshal(in, nil); err == nil {
var out interface{}
if _, err := Unmarshal(bytes, &out); err == nil {
- if err = checkEqual(in, out); err != nil {
+ if err = test.Differ(in, out); err != nil {
t.Error(err)
}
} else {
@@ -128,7 +113,7 @@ func TestAnyMap(t *testing.T) {
if _, err = Unmarshal(bytes, &out); err != nil {
t.Error(err)
}
- if err = checkEqual(AnyMap(nil), out); err != nil {
+ if err = test.Differ(AnyMap(nil), out); err != nil {
t.Error(err)
}
@@ -140,7 +125,7 @@ func TestAnyMap(t *testing.T) {
if _, err = Unmarshal(bytes, &out); err != nil {
t.Error(err)
}
- if err = checkEqual(AnyMap(nil), out); err != nil {
+ if err = test.Differ(AnyMap(nil), out); err != nil {
t.Error(err)
}
@@ -153,7 +138,7 @@ func TestAnyMap(t *testing.T) {
if _, err = Unmarshal(bytes, &out); err != nil {
t.Error(err)
}
- if err = checkEqual(in, out); err != nil {
+ if err = test.Differ(in, out); err != nil {
t.Error(err)
}
}
@@ -178,14 +163,14 @@ func TestBadMap(t *testing.T) {
var out AnyMap
if _, err = Unmarshal(bytes, &out); err != nil {
t.Error(err)
- } else if err = checkEqual(in, out); err != nil {
+ } else if err = test.Differ(in, out); err != nil {
t.Error(err)
}
// Should unmarshal to interface{} as AnyMap
var v interface{}
if _, err = Unmarshal(bytes, &v); err != nil {
t.Error(err)
- } else if err = checkEqual(in, v); err != nil {
+ } else if err = test.Differ(in, v); err != nil {
t.Error(err)
}
// Round trip from interface to interface
@@ -197,7 +182,7 @@ func TestBadMap(t *testing.T) {
v = nil
if _, err = Unmarshal(bytes, &v); err != nil {
t.Error(err)
- } else if err = checkEqual(in, v); err != nil {
+ } else if err = test.Differ(in, v); err != nil {
t.Error(err)
}
}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/90dbf46c/go/src/qpid.apache.org/amqp/message_test.go
----------------------------------------------------------------------
diff --git a/go/src/qpid.apache.org/amqp/message_test.go b/go/src/qpid.apache.org/amqp/message_test.go
index 9899bd5..c396cc8 100644
--- a/go/src/qpid.apache.org/amqp/message_test.go
+++ b/go/src/qpid.apache.org/amqp/message_test.go
@@ -23,6 +23,8 @@ import (
"reflect"
"testing"
"time"
+
+ "qpid.apache.org/internal/test"
)
func roundTrip(m Message) error {
@@ -34,7 +36,7 @@ func roundTrip(m Message) error {
if err != nil {
return err
}
- return checkEqual(m, m2)
+ return test.Differ(m, m2)
}
func TestDefaultMessage(t *testing.T) {
@@ -74,11 +76,11 @@ func TestDefaultMessage(t *testing.T) {
{"Body", nil},
} {
ret := mv.MethodByName(x.method).Call(nil)
- if err := checkEqual(x.want, ret[0].Interface()); err != nil {
+ if err := test.Differ(x.want, ret[0].Interface()); err != nil {
t.Errorf("%s: %s", x.method, err)
}
}
- if err := checkEqual("Message{}", m.String()); err != nil {
+ if err := test.Differ("Message{}", m.String()); err != nil {
t.Error(err)
}
}
@@ -94,7 +96,7 @@ func TestMessageString(t *testing.T) {
t.Error(err)
}
msgstr := "Message{user-id: user, delivery-annotations: map[instructions:foo], message-annotations: map[annotations:bar], application-properties: map[int:32], body: hello}"
- if err := checkEqual(msgstr, m.String()); err != nil {
+ if err := test.Differ(msgstr, m.String()); err != nil {
t.Error(err)
}
}
@@ -135,7 +137,7 @@ func TestMessageRoundTrip(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- if err = checkEqual(m1, m); err != nil {
+ if err = test.Differ(m1, m); err != nil {
t.Error(err)
}
@@ -165,7 +167,7 @@ func TestMessageRoundTrip(t *testing.T) {
{m.Instructions(), map[string]interface{}{"instructions": "foo"}},
{m.Annotations(), map[string]interface{}{"annotations": "bar"}},
} {
- if err := checkEqual(data[0], data[1]); err != nil {
+ if err := test.Differ(data[0], data[1]); err != nil {
t.Error(err)
}
}
@@ -190,7 +192,7 @@ func TestDeprecated(t *testing.T) {
{m.Annotations(), map[string]interface{}{"annotations": "bar"}},
{m.Properties(), map[string]interface{}{"int": int32(32), "bool": true}},
} {
- if err := checkEqual(data[0], data[1]); err != nil {
+ if err := test.Differ(data[0], data[1]); err != nil {
t.Error(err)
}
}
@@ -207,20 +209,20 @@ func TestMessageBodyTypes(t *testing.T) {
m := NewMessageWith(int64(42))
m.Unmarshal(&body)
m.Unmarshal(&i)
- if err := checkEqual(body.(int64), int64(42)); err != nil {
+ if err := test.Differ(body.(int64), int64(42)); err != nil {
t.Error(err)
}
- if err := checkEqual(i, int64(42)); err != nil {
+ if err := test.Differ(i, int64(42)); err != nil {
t.Error(err)
}
m = NewMessageWith("hello")
m.Unmarshal(&s)
m.Unmarshal(&body)
- if err := checkEqual(s, "hello"); err != nil {
+ if err := test.Differ(s, "hello"); err != nil {
t.Error(err)
}
- if err := checkEqual(body.(string), "hello"); err != nil {
+ if err := test.Differ(body.(string), "hello"); err != nil {
t.Error(err)
}
if err := roundTrip(m); err != nil {
@@ -230,10 +232,10 @@ func TestMessageBodyTypes(t *testing.T) {
m = NewMessageWith(Binary("bin"))
m.Unmarshal(&s)
m.Unmarshal(&body)
- if err := checkEqual(body.(Binary), Binary("bin")); err != nil {
+ if err := test.Differ(body.(Binary), Binary("bin")); err != nil {
t.Error(err)
}
- if err := checkEqual(s, "bin"); err != nil {
+ if err := test.Differ(s, "bin"); err != nil {
t.Error(err)
}
if err := roundTrip(m); err != nil {
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/90dbf46c/go/src/qpid.apache.org/amqp/types_test.go
----------------------------------------------------------------------
diff --git a/go/src/qpid.apache.org/amqp/types_test.go b/go/src/qpid.apache.org/amqp/types_test.go
index d7e54f1..0f62225 100644
--- a/go/src/qpid.apache.org/amqp/types_test.go
+++ b/go/src/qpid.apache.org/amqp/types_test.go
@@ -24,14 +24,9 @@ import (
"reflect"
"testing"
"time"
-)
-func checkEqual(want interface{}, got interface{}) error {
- if !reflect.DeepEqual(want, got) {
- return fmt.Errorf("(%T)%#v != (%T)%#v", want, want, got, got)
- }
- return nil
-}
+ "qpid.apache.org/internal/test"
+)
func checkUnmarshal(marshaled []byte, v interface{}) error {
got, err := Unmarshal(marshaled, v)
@@ -130,7 +125,7 @@ func TestTypesRoundTrip(t *testing.T) {
if err := checkUnmarshal(marshalled, &v); err != nil {
t.Error(err)
}
- if err := checkEqual(x, v); err != nil {
+ if err := test.Differ(x, v); err != nil {
t.Error(err)
}
}
@@ -151,7 +146,7 @@ func TestTypesRoundTripAll(t *testing.T) {
t.Error(err)
}
v := vp.Elem().Interface()
- if err := checkEqual(x, v); err != nil {
+ if err := test.Differ(x, v); err != nil {
t.Error(err)
}
}
@@ -175,7 +170,7 @@ func TestDescribed(t *testing.T) {
if err := checkUnmarshal(marshaled, &d); err != nil {
t.Error(err)
}
- if err := checkEqual(want, d); err != nil {
+ if err := test.Differ(want, d); err != nil {
t.Error(err)
}
@@ -187,7 +182,7 @@ func TestDescribed(t *testing.T) {
if _, ok := i.(Described); !ok {
t.Errorf("Expected Described, got %T(%v)", i, i)
}
- if err := checkEqual(want, i); err != nil {
+ if err := test.Differ(want, i); err != nil {
t.Error(err)
}
@@ -196,33 +191,33 @@ func TestDescribed(t *testing.T) {
if err := checkUnmarshal(marshaled, &s); err != nil {
t.Error(err)
}
- if err := checkEqual(want.Value, s); err != nil {
+ if err := test.Differ(want.Value, s); err != nil {
t.Error(err)
}
}
func TestTimeConversion(t *testing.T) {
pt := pnTime(timeValue)
- if err := checkEqual(timeValue, goTime(pt)); err != nil {
+ if err := test.Differ(timeValue, goTime(pt)); err != nil {
t.Error(err)
}
- if err := checkEqual(pt, pnTime(goTime(pt))); err != nil {
+ if err := test.Differ(pt, pnTime(goTime(pt))); err != nil {
t.Error(err)
}
ut := time.Unix(123, 456*1000000)
- if err := checkEqual(123456, int(pnTime(ut))); err != nil {
+ if err := test.Differ(123456, int(pnTime(ut))); err != nil {
t.Error(err)
}
- if err := checkEqual(ut, goTime(123456)); err != nil {
+ if err := test.Differ(ut, goTime(123456)); err != nil {
t.Error(err)
}
// Preserve zero values
var tz time.Time
- if err := checkEqual(0, int(pnTime(tz))); err != nil {
+ if err := test.Differ(0, int(pnTime(tz))); err != nil {
t.Error(err)
}
- if err := checkEqual(tz, goTime(pnTime(tz))); err != nil {
+ if err := test.Differ(tz, goTime(pnTime(tz))); err != nil {
t.Error(err)
}
}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/90dbf46c/go/src/qpid.apache.org/electron/auth_test.go
----------------------------------------------------------------------
diff --git a/go/src/qpid.apache.org/electron/auth_test.go b/go/src/qpid.apache.org/electron/auth_test.go
index 30ef401..9f73830 100644
--- a/go/src/qpid.apache.org/electron/auth_test.go
+++ b/go/src/qpid.apache.org/electron/auth_test.go
@@ -27,15 +27,17 @@ import (
"path/filepath"
"strings"
"testing"
+
+ "qpid.apache.org/internal/test"
)
func TestAuthAnonymous(t *testing.T) {
p := newPipe(t,
[]ConnectionOption{User("fred"), VirtualHost("vhost"), SASLAllowInsecure(true)},
[]ConnectionOption{SASLAllowedMechs("ANONYMOUS"), SASLAllowInsecure(true)})
- fatalIf(t, p.server.Sync())
- errorIf(t, checkEqual("anonymous", p.server.User()))
- errorIf(t, checkEqual("vhost", p.server.VirtualHost()))
+ test.FatalIf(t, p.server.Sync())
+ test.ErrorIf(t, test.Differ("anonymous", p.server.User()))
+ test.ErrorIf(t, test.Differ("vhost", p.server.VirtualHost()))
}
func TestAuthPlain(t *testing.T) {
@@ -43,8 +45,8 @@ func TestAuthPlain(t *testing.T) {
p := newPipe(t,
[]ConnectionOption{SASLAllowInsecure(true), SASLAllowedMechs("PLAIN"), User("fred@proton"), Password([]byte("xxx"))},
[]ConnectionOption{SASLAllowInsecure(true), SASLAllowedMechs("PLAIN")})
- fatalIf(t, p.server.Sync())
- errorIf(t, checkEqual("fred@proton", p.server.User()))
+ test.FatalIf(t, p.server.Sync())
+ test.ErrorIf(t, test.Differ("fred@proton", p.server.User()))
}
func TestAuthBadPass(t *testing.T) {
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/90dbf46c/go/src/qpid.apache.org/electron/benchmark_test.go
----------------------------------------------------------------------
diff --git a/go/src/qpid.apache.org/electron/benchmark_test.go b/go/src/qpid.apache.org/electron/benchmark_test.go
index 0de53d8..9ab2b9a 100644
--- a/go/src/qpid.apache.org/electron/benchmark_test.go
+++ b/go/src/qpid.apache.org/electron/benchmark_test.go
@@ -26,6 +26,7 @@ import (
"testing"
"qpid.apache.org/amqp"
+ "qpid.apache.org/internal/test"
)
// To change capacity use
@@ -59,7 +60,7 @@ func (bm *bmCommon) receiveAccept() {
if rm, err := bm.r.Receive(); err != nil {
bm.b.Fatal(err)
} else {
- fatalIf(bm.b, rm.Accept())
+ test.FatalIf(bm.b, rm.Accept())
}
}
}
@@ -67,7 +68,7 @@ func (bm *bmCommon) receiveAccept() {
func (bm *bmCommon) outcomes() {
defer bm.done.Done()
for n := 0; n < bm.b.N; n++ {
- fatalIf(bm.b, (<-bm.ack).Error)
+ test.FatalIf(bm.b, (<-bm.ack).Error)
}
}
@@ -98,7 +99,7 @@ func BenchmarkSendSync(b *testing.B) {
go bm.receiveAccept()
for n := 0; n < b.N; n++ {
- fatalIf(b, bm.s.SendSync(emptyMsg).Error)
+ test.FatalIf(b, bm.s.SendSync(emptyMsg).Error)
}
bm.done.Wait()
}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/90dbf46c/go/src/qpid.apache.org/electron/common_test.go
----------------------------------------------------------------------
diff --git a/go/src/qpid.apache.org/electron/common_test.go b/go/src/qpid.apache.org/electron/common_test.go
index 0f4f543..56c0e44 100644
--- a/go/src/qpid.apache.org/electron/common_test.go
+++ b/go/src/qpid.apache.org/electron/common_test.go
@@ -20,43 +20,12 @@ under the License.
package electron
import (
- "fmt"
"net"
- "path"
- "reflect"
- "runtime"
"sync"
"testing"
-)
-
-func decorate(err error, callDepth int) string {
- _, file, line, _ := runtime.Caller(callDepth + 1) // annotate with location of caller.
- _, file = path.Split(file)
- return fmt.Sprintf("\n%s:%d: %v", file, line, err)
-}
-func fatalIfN(t testing.TB, err error, callDepth int) {
- if err != nil {
- t.Fatal(decorate(err, callDepth+1))
- }
-}
-
-func fatalIf(t testing.TB, err error) {
- fatalIfN(t, err, 1)
-}
-
-func errorIf(t testing.TB, err error) {
- if err != nil {
- t.Error(decorate(err, 1))
- }
-}
-
-func checkEqual(want interface{}, got interface{}) error {
- if !reflect.DeepEqual(want, got) {
- return fmt.Errorf("(%#v != %#v)", want, got)
- }
- return nil
-}
+ "qpid.apache.org/internal/test"
+)
// AMQP client/server pair
type pair struct {
@@ -113,8 +82,9 @@ func newPipe(t testing.TB, clientOpts, serverOpts []ConnectionOption) *pair {
// AMQP pair linked by TCP socket
func newSocketPair(t testing.TB, clientOpts, serverOpts []ConnectionOption) *pair {
+ t.Helper()
l, err := net.Listen("tcp4", ":0") // For systems with ipv6 disabled
- fatalIfN(t, err, 1)
+ test.FatalIf(t, err)
var srv Connection
var srvErr error
var wg sync.WaitGroup
@@ -125,9 +95,9 @@ func newSocketPair(t testing.TB, clientOpts, serverOpts []ConnectionOption) *pai
}()
addr := l.Addr()
cli, err := NewContainer("client").Dial(addr.Network(), addr.String(), clientOpts...)
- fatalIfN(t, err, 1)
+ test.FatalIf(t, err)
wg.Wait()
- fatalIfN(t, srvErr, 1)
+ test.FatalIf(t, srvErr)
return newPair(t, cli, srv)
}
@@ -136,7 +106,7 @@ func (p *pair) close() { p.client.Connection().Close(nil); p.server.Close(nil) }
// Return a client sender and server receiver
func (p *pair) sender(opts ...LinkOption) (Sender, Receiver) {
snd, err := p.client.Sender(opts...)
- fatalIfN(p.t, err, 2)
+ test.FatalIf(p.t, err)
rcv := <-p.rchan
return snd, rcv
}
@@ -144,7 +114,7 @@ func (p *pair) sender(opts ...LinkOption) (Sender, Receiver) {
// Return a client receiver and server sender
func (p *pair) receiver(opts ...LinkOption) (Receiver, Sender) {
rcv, err := p.client.Receiver(opts...)
- fatalIfN(p.t, err, 2)
+ test.FatalIf(p.t, err)
snd := <-p.schan
return rcv, snd
}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/90dbf46c/go/src/qpid.apache.org/electron/electron_test.go
----------------------------------------------------------------------
diff --git a/go/src/qpid.apache.org/electron/electron_test.go b/go/src/qpid.apache.org/electron/electron_test.go
index 2517de1..352a242 100644
--- a/go/src/qpid.apache.org/electron/electron_test.go
+++ b/go/src/qpid.apache.org/electron/electron_test.go
@@ -25,6 +25,7 @@ import (
"time"
"qpid.apache.org/amqp"
+ "qpid.apache.org/internal/test"
)
// Send a message one way with a client sender and server receiver, verify ack.
@@ -51,12 +52,12 @@ func TestClientSender(t *testing.T) {
m := amqp.NewMessageWith(fmt.Sprintf("foobar%v-%v", i, j))
var err error
s[i].SendAsync(m, ack, "testing")
- fatalIf(t, err)
+ test.FatalIf(t, err)
}()
// Server receive
rm, err := r[i].Receive()
- fatalIf(t, err)
+ test.FatalIf(t, err)
if want, got := interface{}(fmt.Sprintf("foobar%v-%v", i, j)), rm.Message.Body(); want != got {
t.Errorf("%#v != %#v", want, got)
}
@@ -89,14 +90,14 @@ func TestClientReceiver(t *testing.T) {
go func() {
for i := 0; i < nMessages; i++ { // Server sends
out := s.SendSync(amqp.NewMessageWith(int32(i)))
- fatalIf(t, out.Error)
+ test.FatalIf(t, out.Error)
}
}()
for i := 0; i < nMessages; i++ { // Client receives
rm, err := r.Receive()
- fatalIf(t, err)
- errorIf(t, checkEqual(int32(i), rm.Message.Body()))
- errorIf(t, rm.Accept())
+ test.FatalIf(t, err)
+ test.ErrorIf(t, test.Differ(int32(i), rm.Message.Body()))
+ test.ErrorIf(t, rm.Accept())
}
}
@@ -301,20 +302,20 @@ func TestHeartbeat(t *testing.T) {
defer close(unfreeze)
freeze := func() error { return p.server.(*connection).engine.Inject(func() { <-unfreeze }) }
- fatalIf(t, p.client.Sync())
- errorIf(t, checkEqual(101*time.Millisecond, p.client.Connection().Heartbeat()))
- errorIf(t, checkEqual(102*time.Millisecond, p.server.Heartbeat()))
+ test.FatalIf(t, p.client.Sync())
+ test.ErrorIf(t, test.Differ(101*time.Millisecond, p.client.Connection().Heartbeat()))
+ test.ErrorIf(t, test.Differ(102*time.Millisecond, p.server.Heartbeat()))
// Freeze the server for less than a heartbeat
- fatalIf(t, freeze())
+ test.FatalIf(t, freeze())
time.Sleep(5 * time.Millisecond)
unfreeze <- true
// Make sure server is still responding.
s, _ := p.sender()
- errorIf(t, s.Sync())
+ test.ErrorIf(t, s.Sync())
// Freeze the server till the p.client times out the connection
- fatalIf(t, freeze())
+ test.FatalIf(t, freeze())
select {
case <-p.client.Done():
if amqp.ResourceLimitExceeded != p.client.Error().(amqp.Error).Name {
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/90dbf46c/go/src/qpid.apache.org/electron/link_test.go
----------------------------------------------------------------------
diff --git a/go/src/qpid.apache.org/electron/link_test.go b/go/src/qpid.apache.org/electron/link_test.go
index feb1f20..4041d8b 100644
--- a/go/src/qpid.apache.org/electron/link_test.go
+++ b/go/src/qpid.apache.org/electron/link_test.go
@@ -22,10 +22,12 @@ package electron
import (
"net"
- "qpid.apache.org/amqp"
- "qpid.apache.org/proton"
"testing"
"time"
+
+ "qpid.apache.org/amqp"
+ "qpid.apache.org/internal/test"
+ "qpid.apache.org/proton"
)
func TestLinkSettings(t *testing.T) {
@@ -37,27 +39,27 @@ func TestLinkSettings(t *testing.T) {
close(done)
defer sConn.Close()
c, err := NewConnection(sConn, Server())
- fatalIf(t, err)
+ test.FatalIf(t, err)
for in := range c.Incoming() {
ep := in.Accept()
switch ep := ep.(type) {
case Receiver:
- errorIf(t, checkEqual("one.source", ep.Source()))
- errorIf(t, checkEqual(TerminusSettings{}, ep.SourceSettings()))
- errorIf(t, checkEqual("one.target", ep.Target()))
- errorIf(t, checkEqual(settings, ep.TargetSettings()))
+ test.ErrorIf(t, test.Differ("one.source", ep.Source()))
+ test.ErrorIf(t, test.Differ(TerminusSettings{}, ep.SourceSettings()))
+ test.ErrorIf(t, test.Differ("one.target", ep.Target()))
+ test.ErrorIf(t, test.Differ(settings, ep.TargetSettings()))
case Sender:
- errorIf(t, checkEqual("two", ep.LinkName()))
- errorIf(t, checkEqual("two.source", ep.Source()))
- errorIf(t, checkEqual(TerminusSettings{Durability: proton.Deliveries, Expiry: proton.ExpireNever}, ep.SourceSettings()))
- errorIf(t, checkEqual(filterMap, ep.Filter()))
+ test.ErrorIf(t, test.Differ("two", ep.LinkName()))
+ test.ErrorIf(t, test.Differ("two.source", ep.Source()))
+ test.ErrorIf(t, test.Differ(TerminusSettings{Durability: proton.Deliveries, Expiry: proton.ExpireNever}, ep.SourceSettings()))
+ test.ErrorIf(t, test.Differ(filterMap, ep.Filter()))
}
}
}()
// Client
c, err := NewConnection(cConn)
- fatalIf(t, err)
+ test.FatalIf(t, err)
c.Sender(Source("one.source"), Target("one.target"), TargetSettings(settings))
c.Receiver(Source("two.source"), DurableSubscription("two"), Filter(filterMap))
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/90dbf46c/go/src/qpid.apache.org/internal/test/test.go
----------------------------------------------------------------------
diff --git a/go/src/qpid.apache.org/internal/test/test.go b/go/src/qpid.apache.org/internal/test/test.go
new file mode 100644
index 0000000..6429d01
--- /dev/null
+++ b/go/src/qpid.apache.org/internal/test/test.go
@@ -0,0 +1,78 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+*/
+
+// Utilities to supplement the standard Go testing package
+package test
+
+import (
+ "fmt"
+ "path"
+ "reflect"
+ "runtime"
+ "testing"
+)
+
+// The testing.TB.Helper() function does not seem to work
+func decorate(msg string, callDepth int) string {
+ _, file, line, _ := runtime.Caller(callDepth + 1) // annotate with location of caller.
+ _, file = path.Split(file)
+ return fmt.Sprintf("\n%s:%d: %v", file, line, msg)
+}
+
+func message(err error, args ...interface{}) (msg string) {
+ if len(args) > 0 {
+ msg = fmt.Sprintf(args[0].(string), args[1:]...) + ": "
+ }
+ msg = msg + err.Error()
+ return
+}
+
+// ErrorIf calls t.Error() if err != nil, with optional format message
+func ErrorIf(t testing.TB, err error, format ...interface{}) error {
+ t.Helper()
+ if err != nil {
+ t.Error(message(err, format...))
+ }
+ return err
+}
+
+// ErrorIf calls t.Fatal() if err != nil, with optional format message
+func FatalIf(t testing.TB, err error, format ...interface{}) {
+ t.Helper()
+ if err != nil {
+ t.Fatal(message(err, format...))
+ }
+}
+
+// Extend the methods on testing.TB
+type TB struct{ testing.TB }
+
+func (t *TB) ErrorIf(err error, format ...interface{}) error {
+ t.Helper()
+ return ErrorIf(t, err, format...)
+}
+func (t *TB) FatalIf(err error, format ...interface{}) { t.Helper(); FatalIf(t, err, format...) }
+
+// if reflect.DeepEqual(want, got) { return nil } else { return error("want != got" })
+func Differ(want interface{}, got interface{}) error {
+ if !reflect.DeepEqual(want, got) {
+ return fmt.Errorf("(%T)%#v != (%T)%#v)", want, want, got, got)
+ }
+ return nil
+}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/90dbf46c/go/src/qpid.apache.org/proton/proton_test.go
----------------------------------------------------------------------
diff --git a/go/src/qpid.apache.org/proton/proton_test.go b/go/src/qpid.apache.org/proton/proton_test.go
index aad93eb..ac1b468 100644
--- a/go/src/qpid.apache.org/proton/proton_test.go
+++ b/go/src/qpid.apache.org/proton/proton_test.go
@@ -22,31 +22,11 @@ package proton
import (
"fmt"
"net"
- "path"
- "runtime"
"testing"
"time"
-)
-
-func errorIf(t *testing.T, err error) {
- if err != nil {
- _, file, line, ok := runtime.Caller(1) // annotate with location of caller.
- if ok {
- _, file = path.Split(file)
- }
- t.Errorf("(from %s:%d) %v", file, line, err)
- }
-}
-func fatalIf(t *testing.T, err error) {
- if err != nil {
- _, file, line, ok := runtime.Caller(1) // annotate with location of caller.
- if ok {
- _, file = path.Split(file)
- }
- t.Fatalf("(from %s:%d) %v", file, line, err)
- }
-}
+ "qpid.apache.org/internal/test"
+)
type events []EventType
@@ -82,15 +62,15 @@ func (eng *testEngine) expect(events []EventType) error {
func Test(t *testing.T) {
cConn, sConn := net.Pipe()
client, err := newTestEngine(cConn)
- fatalIf(t, err)
+ test.FatalIf(t, err)
server, err := newTestEngine(sConn)
- fatalIf(t, err)
+ test.FatalIf(t, err)
server.Server()
go client.Run()
go server.Run()
- fatalIf(t, server.expect(events{EConnectionInit, EConnectionBound}))
- fatalIf(t, client.expect(events{EConnectionInit, EConnectionBound}))
- fatalIf(t, client.InjectWait(func() error { client.Connection().Open(); return nil }))
- fatalIf(t, client.expect(events{EConnectionLocalOpen}))
- fatalIf(t, server.expect(events{EConnectionRemoteOpen}))
+ test.FatalIf(t, server.expect(events{EConnectionInit, EConnectionBound}))
+ test.FatalIf(t, client.expect(events{EConnectionInit, EConnectionBound}))
+ test.FatalIf(t, client.InjectWait(func() error { client.Connection().Open(); return nil }))
+ test.FatalIf(t, client.expect(events{EConnectionLocalOpen}))
+ test.FatalIf(t, server.expect(events{EConnectionRemoteOpen}))
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org