Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate collection names #844

Merged
merged 32 commits into from
Jul 7, 2022
Merged
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
wip
  • Loading branch information
seeforschauer committed Jul 5, 2022
commit e84083bad7a9cfc254d6e054a5b6cc65c2399954
31 changes: 15 additions & 16 deletions integration/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,31 +143,27 @@ func TestCollectionName(t *testing.T) {
"_for_ferretdb_it_fails_because_it_is_more_than_119_characters__for_mongo_it_fails_because_it_is_more_than_255_charachters_" +
"long_that_excludes_non_latin_letters_spaces_dots_dollars_dashes",
Err: &mongo.CommandError{
Name: "InvalidNamespace",
Code: 73,
Message: "Fully qualified namespace is too long. Namespace: testcollectionname.very_long_collection_name_that_fails_both_in_mongo_" +
"and_in_ferretdb_databases_for_ferretdb_it_fails_because_it_is_more_than_119_characters__for_mongo_it_fails_because_it_is_more_than_" +
"255_charachters_long_that_excludes_non_latin_letters_spaces_dots_dollars_dashes Max: 255",
},
Alt: "Fully qualified namespace is too long",
},
"WithADash": {
Collection: "collection_name_with_a-dash",
Err: &mongo.CommandError{
Code: 73,
Message: "Invalid collection name: collection_name_with_a-$",
},
Alt: `Namespace must not contain non-latin letters, spaces, dots, dollars, dashes.`,
},
"WithADollarSign": {
Collection: "collection_name_with_a-$",
Err: &mongo.CommandError{
Name: "InvalidNamespace",
Code: 73,
Message: `Namespace must not contain non-latin letters, spaces, dots, dollars, dashes.`,
Message: `Invalid collection name: collection_name_with_a-$`,
},
Alt: `Namespace must not contain non-latin letters, spaces, dots, dollars, dashes.`,
},
"Empty": {
Collection: "",
Err: &mongo.CommandError{
Name: "InvalidNamespace",
Code: 73,
Message: "Invalid namespace specified 'testcollectionname.'",
},
Expand All @@ -181,13 +177,16 @@ func TestCollectionName(t *testing.T) {
},
}

for _, tc := range cases {
err := collection.Database().CreateCollection(ctx, tc.Collection)
if tc.Err == nil {
require.NoError(t, err)
continue
}
AssertEqualAltError(t, *tc.Err, tc.Alt, err)
for name, tc := range cases {
name, tc := name, tc
t.Run(name, func(t *testing.T) {
err := collection.Database().CreateCollection(ctx, tc.Collection)
if tc.Err == nil {
require.NoError(t, err)
return
}
AssertEqualAltError(t, *tc.Err, tc.Alt, err)
})
}

names, err := collection.Database().ListCollectionNames(ctx, bson.D{})
Expand Down