Support json encode/decode for nil values in S structs

This commit is contained in:
Ethan Frey
2017-02-23 18:11:20 +01:00
parent b6a2c5949f
commit 8c9b889ccf
4 changed files with 27 additions and 3 deletions

View File

@ -84,5 +84,29 @@ func TestKeyEncodings(t *testing.T) {
checkJSON(t, pubKey, &pub3, tc.keyName)
assert.EqualValues(t, pubKey, pub3)
}
}
func toFromJSON(t *testing.T, in interface{}, recvr interface{}) {
js, err := data.ToJSON(in)
require.Nil(t, err, "%+v", err)
err = data.FromJSON(js, recvr)
require.Nil(t, err, "%+v", err)
}
func TestNilEncodings(t *testing.T) {
// make sure sigs are okay with nil
a, b := SignatureS{}, SignatureS{}
toFromJSON(t, a, &b)
assert.EqualValues(t, a, b)
// make sure sigs are okay with nil
c, d := PubKeyS{}, PubKeyS{}
toFromJSON(t, c, &d)
assert.EqualValues(t, c, d)
// make sure sigs are okay with nil
e, f := PrivKeyS{}, PrivKeyS{}
toFromJSON(t, e, &f)
assert.EqualValues(t, e, f)
}