From 5848fc3dad2df651c4430ee5e3ec47169ecf23e9 Mon Sep 17 00:00:00 2001 From: Brian Quinlan Date: Thu, 14 Sep 2023 17:16:55 -0700 Subject: [PATCH] Fix it up --- .../lib/src/response_status_line_tests.dart | 88 +++++++++++-------- 1 file changed, 49 insertions(+), 39 deletions(-) diff --git a/pkgs/http_client_conformance_tests/lib/src/response_status_line_tests.dart b/pkgs/http_client_conformance_tests/lib/src/response_status_line_tests.dart index c23de7c7a1..d2ff88c6eb 100644 --- a/pkgs/http_client_conformance_tests/lib/src/response_status_line_tests.dart +++ b/pkgs/http_client_conformance_tests/lib/src/response_status_line_tests.dart @@ -10,7 +10,8 @@ import 'package:test/test.dart'; import 'response_status_line_server_vm.dart' if (dart.library.html) 'response_status_line_server_web.dart'; -/// Tests that the [Client] correctly processes the response status line. +/// Tests that the [Client] correctly processes the response status line (e.g. +/// 'HTTP/1.1 200 OK\r\n'). /// /// If [reasonableInvalidStatusLineHandling] is `false` the tests related to /// invalid `Status-Line`s are skipped. @@ -27,44 +28,53 @@ void testResponseStatusLine(Client client, host = 'localhost:${await httpServerQueue.next}'; }); - test( - 'without HTTP version', - () async { - httpServerChannel.sink.add('201 Created'); - await expectLater( - client.get(Uri.http(host, '')), - throwsA(isA()), - ); - }, - ); + test('valid', () async { + httpServerChannel.sink.add('HTTP/1.1 201 Created'); + final response = await client.get(Uri.http(host, ''); + expect(response.statusCode, 201); + expect(response.reasonPhrase, 'Created'); + }); + + group('invalid', () { + test( + 'without HTTP version', + () async { + httpServerChannel.sink.add('201 Created'); + await expectLater( + client.get(Uri.http(host, '')), + throwsA(isA()), + ); + }, + ); - test( - 'without status code', - () async { - httpServerChannel.sink.add('HTTP/1.1 OK'); - await expectLater( - client.get(Uri.http(host, '')), - throwsA(isA()), - ); - }, - ); + test( + 'without status code', + () async { + httpServerChannel.sink.add('HTTP/1.1 OK'); + await expectLater( + client.get(Uri.http(host, '')), + throwsA(isA()), + ); + }, + ); - test( - 'without reason phrase', - () async { - httpServerChannel.sink.add('HTTP/1.1 201'); - try { - final response = await client.get(Uri.http(host, '')); - expect(response.statusCode, 201); - // All of these responses seem reasonable. - expect(response.reasonPhrase, anyOf(isNull, '', 'Created')); - } on ClientException { - // A Reason-Phrase is required according to RFC-2616 - } - }, - ); - }, - skip: reasonableInvalidStatusLineHandling - ? false - : 'does handle invalid request lines in a sensible way'); + test( + 'without reason phrase', + () async { + httpServerChannel.sink.add('HTTP/1.1 201'); + try { + final response = await client.get(Uri.http(host, '')); + expect(response.statusCode, 201); + // All of these responses seem reasonable. + expect(response.reasonPhrase, anyOf(isNull, '', 'Created')); + } on ClientException { + // A Reason-Phrase is required according to RFC-2616 + } + }, + ); + }, + skip: reasonableInvalidStatusLineHandling + ? false + : 'does handle invalid request lines in a sensible way'); + }); }