-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgob_test.go
48 lines (39 loc) · 1.1 KB
/
gob_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
package gotils_test
import (
"net/http"
"os"
"testing"
. "github.com/onsi/gomega"
gotils "github.com/korovkin/gotils"
)
type MyObject struct {
ErrorStr string `json:"err_str"`
HttpStatusCode int `json:"err_http_status_code"`
ClientErrCode int `json:"err_client_code"`
M map[string]string `json:"m"`
A []string `json:"a"`
}
func TestGOB(t *testing.T) {
RegisterTestingT(t)
t.Run("gob", func(_ *testing.T) {
e := &MyObject{
ErrorStr: os.ErrNotExist.Error(),
HttpStatusCode: http.StatusNotFound,
ClientErrCode: 0,
M: map[string]string{
"a": "aa",
},
A: []string{
"a", "aa", "aaa",
},
}
eCopy := &MyObject{}
gotils.FromGOB(gotils.ToGOB(e), eCopy)
Expect(eCopy).NotTo(BeNil())
// log.Println("=> e:", gotils.ToJSONString(e))
// log.Println("=> eCopy:", gotils.ToJSONString(eCopy))
Expect(eCopy.ErrorStr).To(BeEquivalentTo(e.ErrorStr))
Expect(eCopy.HttpStatusCode).To(BeEquivalentTo(e.HttpStatusCode))
Expect(eCopy.ClientErrCode).To(BeEquivalentTo(e.ClientErrCode))
})
}