mirror of
https://github.com/NixOS/nix.git
synced 2025-11-09 03:56:01 +01:00
Merge pull request #14026 from lovesegfault/s3-url-tests
test(libstore): additional ParsedS3Url tests
This commit is contained in:
commit
773dd61d1c
1 changed files with 35 additions and 8 deletions
|
|
@ -8,6 +8,10 @@
|
|||
|
||||
namespace nix {
|
||||
|
||||
// =============================================================================
|
||||
// ParsedS3URL Tests
|
||||
// =============================================================================
|
||||
|
||||
struct ParsedS3URLTestCase
|
||||
{
|
||||
std::string url;
|
||||
|
|
@ -86,18 +90,41 @@ INSTANTIATE_TEST_SUITE_P(
|
|||
}),
|
||||
[](const ::testing::TestParamInfo<ParsedS3URLTestCase> & info) { return info.param.description; });
|
||||
|
||||
TEST(InvalidParsedS3URLTest, parseS3URLErrors)
|
||||
// Parameterized test for invalid S3 URLs
|
||||
struct InvalidS3URLTestCase
|
||||
{
|
||||
auto invalidBucketMatcher = ::testing::ThrowsMessage<BadURL>(
|
||||
testing::HasSubstrIgnoreANSIMatcher("error: URI has a missing or invalid bucket name"));
|
||||
std::string url;
|
||||
std::string expectedErrorSubstring;
|
||||
std::string description;
|
||||
};
|
||||
|
||||
/* Empty bucket (authority) */
|
||||
ASSERT_THAT([]() { ParsedS3URL::parse(parseURL("s3:///key")); }, invalidBucketMatcher);
|
||||
/* Invalid bucket name */
|
||||
ASSERT_THAT([]() { ParsedS3URL::parse(parseURL("s3://127.0.0.1")); }, invalidBucketMatcher);
|
||||
class InvalidParsedS3URLTest : public ::testing::WithParamInterface<InvalidS3URLTestCase>, public ::testing::Test
|
||||
{};
|
||||
|
||||
TEST_P(InvalidParsedS3URLTest, parseS3URLErrors)
|
||||
{
|
||||
const auto & testCase = GetParam();
|
||||
|
||||
ASSERT_THAT(
|
||||
[&testCase]() { ParsedS3URL::parse(parseURL(testCase.url)); },
|
||||
::testing::ThrowsMessage<BadURL>(testing::HasSubstrIgnoreANSIMatcher(testCase.expectedErrorSubstring)));
|
||||
}
|
||||
|
||||
// Parameterized test for s3ToHttpsUrl conversion
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
InvalidUrls,
|
||||
InvalidParsedS3URLTest,
|
||||
::testing::Values(
|
||||
InvalidS3URLTestCase{"s3:///key", "error: URI has a missing or invalid bucket name", "empty_bucket"},
|
||||
InvalidS3URLTestCase{"s3://127.0.0.1", "error: URI has a missing or invalid bucket name", "ip_address_bucket"},
|
||||
InvalidS3URLTestCase{"s3://bucket with spaces/key", "is not a valid URL", "bucket_with_spaces"},
|
||||
InvalidS3URLTestCase{"s3://", "error: URI has a missing or invalid bucket name", "completely_empty"},
|
||||
InvalidS3URLTestCase{"s3://bucket", "error: URI has a missing or invalid key", "missing_key"}),
|
||||
[](const ::testing::TestParamInfo<InvalidS3URLTestCase> & info) { return info.param.description; });
|
||||
|
||||
// =============================================================================
|
||||
// S3 URL to HTTPS Conversion Tests
|
||||
// =============================================================================
|
||||
|
||||
struct S3ToHttpsConversionTestCase
|
||||
{
|
||||
ParsedS3URL input;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue