Skip to content

Commit

Permalink
add unit test for ListIndexes
Browse files Browse the repository at this point in the history
  • Loading branch information
tayloraswift committed Mar 5, 2024
1 parent 0450f77 commit 79845d4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
8 changes: 8 additions & 0 deletions Sources/MongoDB/Commands/Mongo.ListIndexes (ext).swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
extension Mongo.ListIndexes:Mongo.ImplicitSessionCommand
{
}
extension Mongo.ListIndexes:Mongo.IterableCommand
{
@inlinable public
var tailing:Mongo.Tailing? { nil }
}
25 changes: 21 additions & 4 deletions Sources/MongoDBTests/Indexes/Indexes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ struct Indexes<Configuration>:MongoTestBattery where Configuration:MongoTestConf
let response:Mongo.CreateIndexesResponse = try await session.run(
command: Mongo.CreateIndexes.init(collection,
writeConcern: .majority,
indexes:
[
indexes: [
.init
{
$0[.unique] = true
Expand Down Expand Up @@ -98,8 +97,7 @@ struct Indexes<Configuration>:MongoTestBattery where Configuration:MongoTestConf
let response:Mongo.CreateIndexesResponse = try await session.run(
command: Mongo.CreateIndexes.init(collection,
writeConcern: .majority,
indexes:
[
indexes: [
.init
{
$0[.unique] = true
Expand All @@ -117,6 +115,25 @@ struct Indexes<Configuration>:MongoTestBattery where Configuration:MongoTestConf
tests.expect(response ==? expected)
}
}
if let tests:TestGroup = tests / "List"
{
await tests.do
{
let expected:[Mongo.IndexBinding] = [
.init(version: 2, name: "_id_"),
.init(version: 2, name: "item_manufacturer_model"),
.init(version: 2, name: "item_supplier_model"),
]
let returned:[Mongo.IndexBinding] = try await session.run(
command: Mongo.ListIndexes.init(collection),
against: database)
{
try await $0.reduce(into: [], +=)
}

tests.expect(returned **? expected)
}
}
if let tests:TestGroup = tests / "Drop"
{
await tests.do
Expand Down

0 comments on commit 79845d4

Please sign in to comment.