-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
25cb251
commit 400ffa3
Showing
3 changed files
with
72 additions
and
102 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import MongoDB | ||
import Testing | ||
|
||
@Suite | ||
struct Collections:Mongo.TestBattery | ||
{ | ||
let database:Mongo.Database = "Collections" | ||
|
||
@Test(arguments: [.single, .replicated] as [any Mongo.TestConfiguration]) | ||
func collections(_ configuration:any Mongo.TestConfiguration) async throws | ||
{ | ||
try await self.run(under: configuration) | ||
} | ||
|
||
func run(with pool:Mongo.SessionPool) async throws | ||
{ | ||
var collections:[Mongo.Collection] = (0 ..< 32).map { .init($0.description) } | ||
let session:Mongo.Session = try await .init(from: pool) | ||
|
||
for collection:Mongo.Collection in collections | ||
{ | ||
try await session.run( | ||
command: Mongo.Create<Mongo.Collection>.init(collection), | ||
against: self.database) | ||
} | ||
|
||
try await session.run( | ||
command: Mongo.ListCollections<Mongo.CollectionBinding>.init(stride: 10), | ||
against: self.database) | ||
{ | ||
var collections:Set<Mongo.Collection> = .init(collections) | ||
for try await batch:[Mongo.CollectionBinding] in $0 | ||
{ | ||
#expect(batch.count <= 10) | ||
for binding:Mongo.CollectionBinding in batch | ||
{ | ||
#expect(collections.remove(binding.collection) != nil) | ||
#expect(binding.type == .collection) | ||
} | ||
} | ||
#expect(collections == []) | ||
} | ||
try await session.run( | ||
command: Mongo.ListCollections<Mongo.CollectionMetadata>.init(stride: 10), | ||
against: self.database) | ||
{ | ||
var collections:Set<Mongo.Collection> = .init(collections) | ||
for try await batch:[Mongo.CollectionMetadata] in $0 | ||
{ | ||
#expect(batch.count <= 10) | ||
for metadata:Mongo.CollectionMetadata in batch | ||
{ | ||
#expect(collections.remove(metadata.collection) != nil) | ||
#expect(metadata.type == .collection) | ||
} | ||
} | ||
#expect(collections == []) | ||
} | ||
|
||
let target:Mongo.Namespaced<Mongo.Collection> = self.database | "Renamed" | ||
try await session.run( | ||
command: Mongo.RenameCollection.init(self.database | collections[0], to: target), | ||
against: .admin) | ||
|
||
collections[0] = target.collection | ||
|
||
for collection:Mongo.Collection in collections | ||
{ | ||
try await session.run(command: Mongo.Drop.init(collection), against: self.database) | ||
} | ||
} | ||
} |