-
Notifications
You must be signed in to change notification settings - Fork 1
/
producer_test.go
53 lines (44 loc) · 1015 Bytes
/
producer_test.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
// +build unit
package gosqs_test
import (
"testing"
gosqs "github.com/engelmi/go-sqs"
)
func Test_MarshalToJson(t *testing.T) {
type samplePayload struct {
Text string `json:"text"`
Number float64 `json:"number"`
}
type testcase struct {
payload interface{}
wantErr bool
}
zeroValue := 0.0
testcases := map[string]testcase{
"should marshal a valid payload successfully ": {
payload: samplePayload{
Text: "payload with inf value",
Number: 3.0,
},
wantErr: false,
},
"should return error if marshalling of payload fails ": {
payload: samplePayload{
Text: "payload with inf value",
Number: 3.0 / zeroValue,
},
wantErr: true,
},
}
for tcName, tc := range testcases {
t.Run(tcName, func(t *testing.T) {
_, err := gosqs.MarshalToJson(tc.payload)
if tc.wantErr && err == nil {
t.Fatal("Expected error, but got <nil>")
}
if !tc.wantErr && err != nil {
t.Fatalf("Expected no error, but got '%s'", err.Error())
}
})
}
}