From bf8c70655916080f39970047531154a6c761159a Mon Sep 17 00:00:00 2001 From: Elad Gildnur <6321801+shleikes@users.noreply.github.com> Date: Tue, 26 Nov 2024 18:36:25 +0200 Subject: [PATCH] Add test case for new generic parser (#1803) --- protocol/parser/parser_test.go | 47 ++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/protocol/parser/parser_test.go b/protocol/parser/parser_test.go index 82d78c261f..e0e57371ff 100644 --- a/protocol/parser/parser_test.go +++ b/protocol/parser/parser_test.go @@ -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", @@ -718,6 +719,47 @@ 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 { @@ -725,6 +767,11 @@ func TestParseBlockFromReply(t *testing.T) { 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()) }) }