Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

52 lines
966B

  1. package main
  2. import (
  3. "biukop/sfm/loan"
  4. "encoding/gob"
  5. "github.com/stretchr/testify/assert"
  6. "testing"
  7. )
  8. type ABC struct {
  9. TEST string
  10. ABC int
  11. AB []byte
  12. }
  13. func TestSession_SaveOtherType(t *testing.T) {
  14. gob.Register(ABC{})
  15. se := loan.Session{}
  16. se.FakeNew()
  17. e := se.Write()
  18. assert.Equal(t, e, nil, "dbWrite should be ok")
  19. se1 := loan.Session{}
  20. e = se1.Read(se.Id)
  21. assert.Equal(t, e, nil, "dbRead should success")
  22. assert.Equal(t, se, se1, "two structure should be equal")
  23. //random struct
  24. p := ABC{}
  25. p.TEST = "this is TEST"
  26. p.ABC = 123
  27. p.AB = []byte("000111222333444555666777888999")
  28. //save to db
  29. se.Add("people", p)
  30. e = se.Write()
  31. assert.Equal(t, e, nil, "dbWrite Bin struct")
  32. //read it back
  33. e = se1.Read(se.Id)
  34. assert.Equal(t, e, nil, "dbRead read Bin")
  35. //unpack Bin
  36. p1 := se1.Get("people")
  37. assert.Equal(t, e, nil, "UnMarshal bin")
  38. //the Bin should be the same
  39. assert.Equal(t, p, p1, "two structure should be the same")
  40. }