|
- package main
-
- import (
- "biukop.com/sfm/loan"
- "encoding/gob"
- "github.com/stretchr/testify/assert"
- "testing"
- )
-
- type ABC struct {
- TEST string
- ABC int
- AB []byte
- }
-
- func TestSession_SaveOtherType(t *testing.T) {
- gob.Register(ABC{})
-
- se := loan.Session{}
- se.FakeNew()
- e := se.Write()
- assert.Equal(t, e, nil, "dbWrite should be ok")
-
- se1 := loan.Session{}
- e = se1.Read(se.Id)
- assert.Equal(t, e, nil, "dbRead should success")
- assert.Equal(t, se, se1, "two structure should be equal")
-
- //random struct
- p := ABC{}
- p.TEST = "this is TEST"
- p.ABC = 123
- p.AB = []byte("000111222333444555666777888999")
-
- //save to db
- se.Add("people", p)
- e = se.Write()
- assert.Equal(t, e, nil, "dbWrite Bin struct")
-
- //read it back
- e = se1.Read(se.Id)
- assert.Equal(t, e, nil, "dbRead read Bin")
-
- //unpack Bin
- p1 := se1.Get("people")
- assert.Equal(t, e, nil, "UnMarshal bin")
-
- //the Bin should be the same
- assert.Equal(t, p, p1, "two structure should be the same")
-
- }
|