-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
testing_1_7.go
64 lines (54 loc) · 1.53 KB
/
testing_1_7.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//go:build go1.7
// +build go1.7
package eventstreamtest
import (
"bytes"
"encoding/base64"
"encoding/json"
"fmt"
"testing"
"github.com/aws/aws-sdk-go/private/protocol/eventstream"
)
// AssertMessageEqual compares to event stream messages, and determines if they
// are equal. Will trigger an testing Error if components of the message are
// not equal.
func AssertMessageEqual(t testing.TB, a, b eventstream.Message, msg ...interface{}) {
getHelper(t)()
ah, err := bytesEncodeHeader(a.Headers)
if err != nil {
t.Fatalf("unable to encode a's headers, %v", err)
}
bh, err := bytesEncodeHeader(b.Headers)
if err != nil {
t.Fatalf("unable to encode b's headers, %v", err)
}
if !bytes.Equal(ah, bh) {
aj, err := json.Marshal(ah)
if err != nil {
t.Fatalf("unable to json encode a's headers, %v", err)
}
bj, err := json.Marshal(bh)
if err != nil {
t.Fatalf("unable to json encode b's headers, %v", err)
}
t.Errorf("%s\nexpect headers: %v\n\t%v\nactual headers: %v\n\t%v\n",
fmt.Sprint(msg...),
base64.StdEncoding.EncodeToString(ah), aj,
base64.StdEncoding.EncodeToString(bh), bj,
)
}
if !bytes.Equal(a.Payload, b.Payload) {
t.Errorf("%s\nexpect payload: %v\nactual payload: %v\n",
fmt.Sprint(msg...),
base64.StdEncoding.EncodeToString(a.Payload),
base64.StdEncoding.EncodeToString(b.Payload),
)
}
}
func bytesEncodeHeader(v eventstream.Headers) ([]byte, error) {
var buf bytes.Buffer
if err := eventstream.EncodeHeaders(&buf, v); err != nil {
return nil, err
}
return buf.Bytes(), nil
}