github.com/yunabe/lgo@v0.0.0-20190709125917-42c42d410fdf/cmd/runner/sessid_test.go (about) 1 package runner 2 3 import ( 4 "encoding/json" 5 "testing" 6 ) 7 8 func TestSessID_marshalJSON(t *testing.T) { 9 id := SessionID{ 10 Time: 1234, 11 } 12 b, err := json.Marshal(&id) 13 if err != nil { 14 t.Error(err) 15 return 16 } 17 expected := "{\"time\":1234}" 18 if string(b) != expected { 19 t.Errorf("Expected %s but got %s", expected, b) 20 } 21 } 22 23 func TestSessID_marshal(t *testing.T) { 24 id := SessionID{ 25 Time: 12345, 26 } 27 expS := "sess7b2274696d65223a31323334357d" 28 s := id.Marshal() 29 if s != expS { 30 t.Errorf("Expected %q but got %q", expS, s) 31 } 32 33 var newID SessionID 34 if err := newID.Unmarshal(s); err != nil { 35 t.Error(err) 36 } 37 var expTime int64 = 12345 38 if newID.Time != expTime { 39 t.Errorf("Expected %d but got %d", expTime, newID.Time) 40 } 41 }