Skip to content

Commit

Permalink
migrate Collections tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tayloraswift committed Oct 24, 2024
1 parent 25cb251 commit 400ffa3
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 102 deletions.
100 changes: 0 additions & 100 deletions Sources/MongoDBTests/Collections/Collections.swift

This file was deleted.

2 changes: 0 additions & 2 deletions Sources/MongoDBTests/Main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ enum Main:TestMain
let all:[any TestBattery.Type] =
[
ChangeStreams <ReplicatedConfiguration>.self,
Collections <ReplicatedConfiguration>.self,
Cursors <ReplicatedConfiguration>.self,
Databases <ReplicatedConfiguration>.self,
Fsync <ReplicatedConfiguration>.self,
Expand All @@ -21,7 +20,6 @@ enum Main:TestMain
// Note: these tests generally fail in debug mode because it takes a long time to
// complete cryptographic authentication, and the driver will time out before it
// completes.
Collections <SingleConfiguration>.self,
Cursors <SingleConfiguration>.self,
Databases <SingleConfiguration>.self,
Fsync <SingleConfiguration>.self,
Expand Down
72 changes: 72 additions & 0 deletions Sources/MongoDBTests2/Collections.swift
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)
}
}
}

0 comments on commit 400ffa3

Please sign in to comment.