Skip to content

Commit e31f631

Browse files
hippi345sbaluja
authored andcommitted
Format the new HttpRequest tests
Put the cases in the repo clang-format style and leave HttpClientTest.cpp unchanged from main.
1 parent 0cb09f9 commit e31f631

2 files changed

Lines changed: 48 additions & 74 deletions

File tree

‎tests/aws-cpp-sdk-core-tests/http/HttpClientTest.cpp‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <aws/core/http/standard/StandardHttpRequest.h>
1212
#include <aws/core/client/ClientConfiguration.h>
1313
#include <aws/core/utils/logging/LogMacros.h>
14-
#include <aws/crt/http/HttpRequestResponse.h>
1514
#include <future>
1615
#include <chrono>
1716

@@ -386,5 +385,4 @@ TEST_F(CURLHttpClientTest, TestHttpRequestWorksFine)
386385
#endif // ENABLE_CURL_CLIENT
387386
#endif // ENABLE_HTTP_CLIENT_TESTING
388387
#endif // NO_HTTP_CLIENT
389-
390388
#endif // DISABLE_DNS_REQUIRED_TESTS

‎tests/aws-cpp-sdk-core-tests/http/HttpRequestTest.cpp‎

Lines changed: 48 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -3,101 +3,77 @@
33
* SPDX-License-Identifier: Apache-2.0.
44
*/
55

6-
#include <aws/testing/AwsCppSdkGTestSuite.h>
76
#include <aws/core/http/URI.h>
87
#include <aws/core/http/standard/StandardHttpRequest.h>
98
#include <aws/crt/http/HttpRequestResponse.h>
9+
#include <aws/testing/AwsCppSdkGTestSuite.h>
1010

1111
using namespace Aws::Http;
1212
using namespace Aws::Http::Standard;
1313

14-
namespace
15-
{
16-
// Resets the process-global path-separator flag when the test leaves, including on assertion failure.
17-
class PreservePathSeparatorsGuard
18-
{
19-
public:
20-
explicit PreservePathSeparatorsGuard(bool preserve)
21-
{
22-
SetPreservePathSeparators(preserve);
23-
}
24-
25-
~PreservePathSeparatorsGuard()
26-
{
27-
SetPreservePathSeparators(false);
28-
}
29-
30-
PreservePathSeparatorsGuard(const PreservePathSeparatorsGuard&) = delete;
31-
PreservePathSeparatorsGuard& operator=(const PreservePathSeparatorsGuard&) = delete;
32-
};
33-
34-
Aws::String CrtRequestPath(const char* uri, HttpMethod method)
35-
{
36-
StandardHttpRequest request(URI(uri), method);
37-
auto crtRequest = request.ToCrtHttpRequest();
38-
if (!crtRequest)
39-
{
40-
ADD_FAILURE() << "ToCrtHttpRequest returned null for " << uri;
41-
return {};
42-
}
43-
44-
auto path = crtRequest->GetPath();
45-
if (!path.has_value())
46-
{
47-
ADD_FAILURE() << "CRT request has no path for " << uri;
48-
return {};
49-
}
50-
51-
return Aws::String(reinterpret_cast<const char*>(path->ptr), path->len);
52-
}
53-
}
14+
namespace {
15+
// Resets the process-global path-separator flag when the test leaves, including on assertion failure.
16+
class PreservePathSeparatorsGuard {
17+
public:
18+
explicit PreservePathSeparatorsGuard(bool preserve) { SetPreservePathSeparators(preserve); }
5419

55-
class HttpRequestConversionTest : public Aws::Testing::AwsCppSdkGTestSuite
56-
{
20+
~PreservePathSeparatorsGuard() { SetPreservePathSeparators(false); }
21+
22+
PreservePathSeparatorsGuard(const PreservePathSeparatorsGuard&) = delete;
23+
PreservePathSeparatorsGuard& operator=(const PreservePathSeparatorsGuard&) = delete;
5724
};
5825

59-
TEST_F(HttpRequestConversionTest, OriginFormNonDefaultPort)
60-
{
61-
EXPECT_EQ("/bucket/key?uploadId=abc&partNumber=1",
62-
CrtRequestPath("http://example.com:9000/bucket/key?uploadId=abc&partNumber=1", HttpMethod::HTTP_PUT));
26+
Aws::String CrtRequestPath(const char* uri, HttpMethod method) {
27+
StandardHttpRequest request(URI(uri), method);
28+
auto crtRequest = request.ToCrtHttpRequest();
29+
if (!crtRequest) {
30+
ADD_FAILURE() << "ToCrtHttpRequest returned null for " << uri;
31+
return {};
32+
}
33+
34+
auto path = crtRequest->GetPath();
35+
if (!path.has_value()) {
36+
ADD_FAILURE() << "CRT request has no path for " << uri;
37+
return {};
38+
}
39+
40+
return Aws::String(reinterpret_cast<const char*>(path->ptr), path->len);
6341
}
42+
} // namespace
43+
44+
class HttpRequestConversionTest : public Aws::Testing::AwsCppSdkGTestSuite {};
6445

65-
TEST_F(HttpRequestConversionTest, OriginFormHttpsPath)
66-
{
67-
EXPECT_EQ("/my-bucket/my-key",
68-
CrtRequestPath("https://s3.amazonaws.com/my-bucket/my-key", HttpMethod::HTTP_GET));
46+
TEST_F(HttpRequestConversionTest, OriginFormNonDefaultPort) {
47+
EXPECT_EQ("/bucket/key?uploadId=abc&partNumber=1",
48+
CrtRequestPath("http://example.com:9000/bucket/key?uploadId=abc&partNumber=1", HttpMethod::HTTP_PUT));
6949
}
7050

71-
TEST_F(HttpRequestConversionTest, OriginFormQueryString)
72-
{
73-
EXPECT_EQ("/path/to/file?query=value&foo=bar",
74-
CrtRequestPath("https://storage.example.com:443/path/to/file?query=value&foo=bar", HttpMethod::HTTP_POST));
51+
TEST_F(HttpRequestConversionTest, OriginFormHttpsPath) {
52+
EXPECT_EQ("/my-bucket/my-key", CrtRequestPath("https://s3.amazonaws.com/my-bucket/my-key", HttpMethod::HTTP_GET));
7553
}
7654

77-
TEST_F(HttpRequestConversionTest, OriginFormRootPath)
78-
{
79-
EXPECT_EQ("/", CrtRequestPath("http://localhost:8080/", HttpMethod::HTTP_HEAD));
55+
TEST_F(HttpRequestConversionTest, OriginFormQueryString) {
56+
EXPECT_EQ("/path/to/file?query=value&foo=bar",
57+
CrtRequestPath("https://storage.example.com:443/path/to/file?query=value&foo=bar", HttpMethod::HTTP_POST));
8058
}
8159

60+
TEST_F(HttpRequestConversionTest, OriginFormRootPath) { EXPECT_EQ("/", CrtRequestPath("http://localhost:8080/", HttpMethod::HTTP_HEAD)); }
61+
8262
// Old absolute-form code dropped a root path and emitted "https://host?list-type=2".
83-
TEST_F(HttpRequestConversionTest, OriginFormRootPathWithQuery)
84-
{
85-
EXPECT_EQ("/?list-type=2", CrtRequestPath("https://host/?list-type=2", HttpMethod::HTTP_GET));
63+
TEST_F(HttpRequestConversionTest, OriginFormRootPathWithQuery) {
64+
EXPECT_EQ("/?list-type=2", CrtRequestPath("https://host/?list-type=2", HttpMethod::HTTP_GET));
8665
}
8766

88-
TEST_F(HttpRequestConversionTest, OriginFormTrailingSlash)
89-
{
90-
EXPECT_EQ("/bucket/prefix/", CrtRequestPath("https://host/bucket/prefix/", HttpMethod::HTTP_GET));
67+
TEST_F(HttpRequestConversionTest, OriginFormTrailingSlash) {
68+
EXPECT_EQ("/bucket/prefix/", CrtRequestPath("https://host/bucket/prefix/", HttpMethod::HTTP_GET));
9169
}
9270

93-
TEST_F(HttpRequestConversionTest, OriginFormEncodesReservedCharacters)
94-
{
95-
EXPECT_EQ("/bucket/a%3Ab%20c%2Bd", CrtRequestPath("https://host/bucket/a:b c+d", HttpMethod::HTTP_PUT));
71+
TEST_F(HttpRequestConversionTest, OriginFormEncodesReservedCharacters) {
72+
EXPECT_EQ("/bucket/a%3Ab%20c%2Bd", CrtRequestPath("https://host/bucket/a:b c+d", HttpMethod::HTTP_PUT));
9673
}
9774

98-
TEST_F(HttpRequestConversionTest, OriginFormPreservesLeadingSlashInKey)
99-
{
100-
PreservePathSeparatorsGuard guard(true);
101-
(void)guard;
102-
EXPECT_EQ("//key", CrtRequestPath("https://host//key", HttpMethod::HTTP_GET));
75+
TEST_F(HttpRequestConversionTest, OriginFormPreservesLeadingSlashInKey) {
76+
PreservePathSeparatorsGuard guard(true);
77+
(void)guard;
78+
EXPECT_EQ("//key", CrtRequestPath("https://host//key", HttpMethod::HTTP_GET));
10379
}

0 commit comments

Comments
 (0)