-
Notifications
You must be signed in to change notification settings - Fork 44
/
json_test.go
64 lines (53 loc) · 1.56 KB
/
json_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
54
55
56
57
58
59
60
61
62
63
64
package omise_test
import (
"encoding/json"
"os"
"reflect"
"testing"
. "github.com/omise/omise-go"
"github.com/omise/omise-go/internal/testutil"
r "github.com/stretchr/testify/require"
)
var JSONRoundtripTests = []JSONRoundtripTest{
{"account_object.json", &Account{}},
{"balance_object.json", &Balance{}},
{"bank_account_object.json", &BankAccount{}},
{"card_object.json", &Card{}},
{"charge_object.json", &Charge{}},
{"customer_object.json", &Customer{}},
{"dispute_object.json", &Dispute{}},
{"document_object.json", &Document{}},
{"event_object.json", &Event{}},
{"recipient_object.json", &Recipient{}},
{"refund_object.json", &Refund{}},
{"schedule_object.json", &Schedule{}},
{"token_object.json", &Token{}},
{"transaction_object.json", &Transaction{}},
{"transfer_object.json", &Transfer{}},
}
type JSONRoundtripTest struct {
srcFile string
value interface{}
}
func (test JSONRoundtripTest) Test(t *testing.T) {
t.Log(reflect.ValueOf(test.value).Elem().Type().Name())
inbytes, err := os.ReadFile("testdata/objects/" + test.srcFile)
r.NoError(t, err)
err = json.Unmarshal(inbytes, test.value)
r.NoError(t, err)
outbytes, err := json.Marshal(test.value)
r.NoError(t, err)
err = json.Unmarshal(outbytes, test.value)
r.NoError(t, err)
m1, m2 := map[string]interface{}{}, map[string]interface{}{}
err = json.Unmarshal(inbytes, &m1)
r.NoError(t, err)
err = json.Unmarshal(outbytes, &m2)
r.NoError(t, err)
testutil.AssertJSONEquals(t, m1, m2)
}
func TestJSONRoundtrip(t *testing.T) {
for _, test := range JSONRoundtripTests {
test.Test(t)
}
}