-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjsonsideload_test.go
56 lines (48 loc) · 957 Bytes
/
jsonsideload_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
package jsonsideload
import (
"encoding/json"
"fmt"
"io/ioutil"
"testing"
"github.com/stretchr/testify/assert"
)
func prepareTestData() ([]byte, error) {
return ioutil.ReadFile("test.json")
}
func TestUnmarshal(t *testing.T) {
data, err := prepareTestData()
if err != nil {
fmt.Println("File error", err)
return
}
personResp := new(PersonResponse)
err = Unmarshal(data, personResp)
if err != nil {
fmt.Println(err)
return
}
assert.Nil(t, err)
resp, err := json.Marshal(personResp)
if err != nil {
fmt.Println("Json marshal error", err)
return
}
fmt.Println(string(resp))
}
// Benchmark Tests
var personResp PersonResponse
func BenchmarkUnmarshal(b *testing.B) {
data, err := prepareTestData()
personResp := new(PersonResponse)
if err != nil {
return
}
for i := 0; i < b.N; i++ {
Unmarshal(data, personResp)
}
}
func BenchmarkMarshal(b *testing.B) {
for i := 0; i < b.N; i++ {
json.Marshal(personResp)
}
}