Skip to content

Commit

Permalink
Add test case for new generic parser (#1803)
Browse files Browse the repository at this point in the history
  • Loading branch information
shleikes authored Nov 26, 2024
1 parent c15d99c commit bf8c706
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions protocol/parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,7 @@ func TestParseBlockFromReply(t *testing.T) {
blockParser spectypes.BlockParser
genericParsers []spectypes.GenericParser
expected int64
expectedError string
}{
{
name: "generic_parser_happy_flow_default_value",
Expand Down Expand Up @@ -718,13 +719,59 @@ func TestParseBlockFromReply(t *testing.T) {
},
expected: spectypes.LATEST_BLOCK,
},
{
name: "generic_parser_parse_from_result_happy_flow",
rpcInput: &RPCInputTest{
Result: []byte(`
{
"foo": {
"bar": 123
}
}
`),
},
genericParsers: []spectypes.GenericParser{
{
ParsePath: ".result.foo.bar",
Value: "123",
ParseType: spectypes.PARSER_TYPE_RESULT,
},
},
expected: 123,
},
{
name: "generic_parser_parse_from_result_error",
rpcInput: &RPCInputTest{
Result: []byte(`
{
"foo": {
"bar": 123
}
}
`),
},
genericParsers: []spectypes.GenericParser{
{
ParsePath: ".result.foo.bar",
Value: "321",
ParseType: spectypes.PARSER_TYPE_RESULT,
},
},
expected: 123,
expectedError: "expected 321, received 123",
},
}

for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()
parsedInput := ParseBlockFromReply(test.rpcInput, test.blockParser, test.genericParsers)
if test.expectedError != "" {
require.Equal(t, test.expectedError, parsedInput.GetParserError())
} else {
require.Empty(t, parsedInput.GetParserError())
}
require.Equal(t, test.expected, parsedInput.GetBlock())
})
}
Expand Down

0 comments on commit bf8c706

Please sign in to comment.