Skip to content

Commit 773dd61

Browse files
authored
Merge pull request #14026 from lovesegfault/s3-url-tests
test(libstore): additional ParsedS3Url tests
2 parents 07b96c1 + b63d9fb commit 773dd61

File tree

1 file changed

+35
-8
lines changed

1 file changed

+35
-8
lines changed

src/libstore-tests/s3.cc

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
namespace nix {
1010

11+
// =============================================================================
12+
// ParsedS3URL Tests
13+
// =============================================================================
14+
1115
struct ParsedS3URLTestCase
1216
{
1317
std::string url;
@@ -86,18 +90,41 @@ INSTANTIATE_TEST_SUITE_P(
8690
}),
8791
[](const ::testing::TestParamInfo<ParsedS3URLTestCase> & info) { return info.param.description; });
8892

89-
TEST(InvalidParsedS3URLTest, parseS3URLErrors)
93+
// Parameterized test for invalid S3 URLs
94+
struct InvalidS3URLTestCase
9095
{
91-
auto invalidBucketMatcher = ::testing::ThrowsMessage<BadURL>(
92-
testing::HasSubstrIgnoreANSIMatcher("error: URI has a missing or invalid bucket name"));
96+
std::string url;
97+
std::string expectedErrorSubstring;
98+
std::string description;
99+
};
93100

94-
/* Empty bucket (authority) */
95-
ASSERT_THAT([]() { ParsedS3URL::parse(parseURL("s3:///key")); }, invalidBucketMatcher);
96-
/* Invalid bucket name */
97-
ASSERT_THAT([]() { ParsedS3URL::parse(parseURL("s3://127.0.0.1")); }, invalidBucketMatcher);
101+
class InvalidParsedS3URLTest : public ::testing::WithParamInterface<InvalidS3URLTestCase>, public ::testing::Test
102+
{};
103+
104+
TEST_P(InvalidParsedS3URLTest, parseS3URLErrors)
105+
{
106+
const auto & testCase = GetParam();
107+
108+
ASSERT_THAT(
109+
[&testCase]() { ParsedS3URL::parse(parseURL(testCase.url)); },
110+
::testing::ThrowsMessage<BadURL>(testing::HasSubstrIgnoreANSIMatcher(testCase.expectedErrorSubstring)));
98111
}
99112

100-
// Parameterized test for s3ToHttpsUrl conversion
113+
INSTANTIATE_TEST_SUITE_P(
114+
InvalidUrls,
115+
InvalidParsedS3URLTest,
116+
::testing::Values(
117+
InvalidS3URLTestCase{"s3:///key", "error: URI has a missing or invalid bucket name", "empty_bucket"},
118+
InvalidS3URLTestCase{"s3://127.0.0.1", "error: URI has a missing or invalid bucket name", "ip_address_bucket"},
119+
InvalidS3URLTestCase{"s3://bucket with spaces/key", "is not a valid URL", "bucket_with_spaces"},
120+
InvalidS3URLTestCase{"s3://", "error: URI has a missing or invalid bucket name", "completely_empty"},
121+
InvalidS3URLTestCase{"s3://bucket", "error: URI has a missing or invalid key", "missing_key"}),
122+
[](const ::testing::TestParamInfo<InvalidS3URLTestCase> & info) { return info.param.description; });
123+
124+
// =============================================================================
125+
// S3 URL to HTTPS Conversion Tests
126+
// =============================================================================
127+
101128
struct S3ToHttpsConversionTestCase
102129
{
103130
ParsedS3URL input;

0 commit comments

Comments
 (0)