Testing marshalling of IDs and viceversa
parent
617795da5d
commit
fac113821e
21
id_test.go
21
id_test.go
|
|
@ -2,6 +2,7 @@ package platform
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
|
@ -124,3 +125,23 @@ func TestDecodeFromEmptyString(t *testing.T) {
|
|||
t.Errorf("expecting empty ID to be serialized into empty string")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMarshalling(t *testing.T) {
|
||||
init := "ca55e77eca55e77e"
|
||||
id1, err := IDFromString(init)
|
||||
if err != nil {
|
||||
t.Errorf(err.Error())
|
||||
}
|
||||
|
||||
serialized, err := json.Marshal(id1)
|
||||
if err != nil {
|
||||
t.Errorf(err.Error())
|
||||
}
|
||||
|
||||
var id2 ID
|
||||
json.Unmarshal(serialized, &id2)
|
||||
|
||||
if !bytes.Equal(id1.Encode(), id2.Encode()) {
|
||||
t.Errorf("error marshalling/unmarshalling ID")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue