From f42e3f4ed54a925be11d7c55d1f5675f308ee165 Mon Sep 17 00:00:00 2001 From: shirady <57721533+shirady@users.noreply.github.com> Date: Wed, 5 Feb 2025 12:03:19 +0200 Subject: [PATCH] separate describes for better output Signed-off-by: shirady <57721533+shirady@users.noreply.github.com> --- .../test_chunked_content_decoder.test.js | 119 ++++++++++-------- 1 file changed, 69 insertions(+), 50 deletions(-) diff --git a/src/test/unit_tests/jest_tests/test_chunked_content_decoder.test.js b/src/test/unit_tests/jest_tests/test_chunked_content_decoder.test.js index 9abeefc147..3e22cff489 100644 --- a/src/test/unit_tests/jest_tests/test_chunked_content_decoder.test.js +++ b/src/test/unit_tests/jest_tests/test_chunked_content_decoder.test.js @@ -25,39 +25,52 @@ describe('ChunkedContentDecoder', function() { // 0\r\n // \r\n - test_parse_output({ - name: 'two_chunks', - input: - '3\r\n' + - 'foo\r\n' + - '3\r\n' + - 'bar\r\n' + - '0\r\n' + - '\r\n', - output: 'foobar', - }); + describe('expected to parse the input', function() { + test_parse_output({ + name: 'two_chunks', + input: + '3\r\n' + + 'foo\r\n' + + '3\r\n' + + 'bar\r\n' + + '0\r\n' + + '\r\n', + output: 'foobar', + }); - test_parse_output({ - name: 'three_chunks_with_trailers', - input: - '3\r\n' + - 'foo\r\n' + - '6\r\n' + - 'barbaz\r\n' + - 'ff\r\n' + - 'f'.repeat(255) + '\r\n' + - '0\r\n' + - 'x-trailer-1: value\r\n' + - 'x-trailer-2: value\r\n' + - '\r\n', - output: 'foobarbaz' + 'f'.repeat(255), - check: decoder => { - assert.deepStrictEqual(decoder.trailers, [ - 'x-trailer-1: value', - 'x-trailer-2: value', - ]); - }, - }); + test_parse_output({ + name: 'two_chunks', + input: + '3\r\n' + + 'foo\r\n' + + '3\r\n' + + 'bar\r\n' + + '0\r\n' + + '\r\n', + output: 'foobar', + }); + + test_parse_output({ + name: 'three_chunks_with_trailers', + input: + '3\r\n' + + 'foo\r\n' + + '6\r\n' + + 'barbaz\r\n' + + 'ff\r\n' + + 'f'.repeat(255) + '\r\n' + + '0\r\n' + + 'x-trailer-1: value\r\n' + + 'x-trailer-2: value\r\n' + + '\r\n', + output: 'foobarbaz' + 'f'.repeat(255), + check: decoder => { + assert.deepStrictEqual(decoder.trailers, [ + 'x-trailer-1: value', + 'x-trailer-2: value', + ]); + }, + }); test_parse_output({ name: 'no_chunk_with_trailers', @@ -85,24 +98,6 @@ describe('ChunkedContentDecoder', function() { output: 'EXT', }); - test_parse_error({ - name: 'chunk_size_not_hex', - input: 'invalid\r\n\r\n', - error_pos: 7, // end of header - }); - - test_parse_error({ - name: 'chunk_size_too_big', - input: '10000000001\r\n\r\n', - error_pos: 11, // end of header - }); - - test_parse_error({ - name: 'header_too_long', - input: '0' + ';'.repeat(1024) + '\r\n\r\n', - error_pos: 1025, // end of header - }); - test_parse_output({ name: 'one_chunk_with_ext', input: @@ -113,6 +108,30 @@ describe('ChunkedContentDecoder', function() { output: 'EXT', }); + }); + + describe('expected to have an error on parse', function() { + + test_parse_error({ + name: 'chunk_size_not_hex', + input: 'invalid\r\n\r\n', + error_pos: 7, // end of header + }); + + test_parse_error({ + name: 'chunk_size_too_big', + input: '10000000001\r\n\r\n', + error_pos: 11, // end of header + }); + + test_parse_error({ + name: 'header_too_long', // according to MAX_CHUNK_HEADER_SIZE + input: '0' + ';'.repeat(1024) + '\r\n\r\n', + error_pos: 1025, // end of header + }); + + }); + /** * @param {{ * name: string,