File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed
Tests/MongoSwiftSyncTests Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -18,10 +18,10 @@ public struct IndexModel: Codable {
1818 /// Gets the default name for this index.
1919 internal func getDefaultName( ) throws -> String {
2020 try self . keys. map { k, v in
21- guard let vInt = v. toInt ( ) else {
21+ guard let vString = v. toInt ( ) . map ( { String ( $0 ) } ) ?? v . stringValue else {
2222 throw MongoError . InvalidArgumentError ( message: " Invalid index value for key: \" \( k) \" = \( v) " )
2323 }
24- return " \( k) _ \( vInt ) "
24+ return " \( k) _ \( vString ) "
2525 } . joined ( separator: " _ " )
2626 }
2727
Original file line number Diff line number Diff line change @@ -72,6 +72,15 @@ final class MongoCollection_IndexTests: MongoSwiftTestCase {
7272 expect ( try indexes. next ( ) ? . get ( ) ) . to ( beNil ( ) )
7373 }
7474
75+ func testCreateTextIndexFromModel( ) throws {
76+ let model = IndexModel ( keys: [ " cat " : " text " ] )
77+ expect ( try self . coll. createIndex ( model) ) . to ( equal ( " cat_text " ) )
78+ let indexes = try coll. listIndexes ( )
79+ expect ( try indexes. next ( ) ? . get ( ) . options? . name) . to ( equal ( " _id_ " ) )
80+ expect ( try indexes. next ( ) ? . get ( ) . options? . name) . to ( equal ( " cat_text " ) )
81+ expect ( try indexes. next ( ) ? . get ( ) ) . to ( beNil ( ) )
82+ }
83+
7584 func testIndexOptions( ) throws {
7685 var options = IndexOptions (
7786 background: true ,
You can’t perform that action at this time.
0 commit comments