Testing marshalling of IDs and viceversa

pull/10616/head
Leonardo Di Donato 2018-07-24 11:59:47 +02:00 committed by Leonardo Di Donato
parent 617795da5d
commit fac113821e
1 changed files with 21 additions and 0 deletions

View File

@ -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")
}
}