Skip to content

Commit

Permalink
add test for unmarshal json using proto field names
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Gillis <[email protected]>
  • Loading branch information
gillisandrew committed Nov 21, 2024
1 parent e0f79ad commit a64ec07
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions go/v1/statement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ func TestJsonUnmarshalStatement(t *testing.T) {
assert.True(t, proto.Equal(got, want), "protos do not match")
}

func TestProtoNamesJsonUnmarshalStatementError(t *testing.T) {
// Note the use of proto field names in the JSON (e.g. "type" instead of "_type")
var wantSt = `{"type":"https://in-toto.io/Statement/v1","subject":[{"name":"theSub","digest":{"alg1":"abc123"}}],"predicate_type":"thePredicate","predicate":{"keyObj":{"subKey":"subVal"}}}`
got := &Statement{}
err := json.Unmarshal([]byte(wantSt), got)
assert.Error(t, err, "error is not thrown when proto field names are used in JSON")
}

func TestProtojsonMarshalStatement(t *testing.T) {
var wantSt = `{"_type":"https://in-toto.io/Statement/v1","subject":[{"name":"theSub","digest":{"alg1":"abc123"}}],"predicateType":"thePredicate","predicate":{"keyObj":{"subKey":"subVal"}}}`
want := createTestStatement(t)
Expand Down

0 comments on commit a64ec07

Please sign in to comment.