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 {
18
18
/// Gets the default name for this index.
19
19
internal func getDefaultName( ) throws -> String {
20
20
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 {
22
22
throw MongoError . InvalidArgumentError ( message: " Invalid index value for key: \" \( k) \" = \( v) " )
23
23
}
24
- return " \( k) _ \( vInt ) "
24
+ return " \( k) _ \( vString ) "
25
25
} . joined ( separator: " _ " )
26
26
}
27
27
Original file line number Diff line number Diff line change @@ -72,6 +72,15 @@ final class MongoCollection_IndexTests: MongoSwiftTestCase {
72
72
expect ( try indexes. next ( ) ? . get ( ) ) . to ( beNil ( ) )
73
73
}
74
74
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
+
75
84
func testIndexOptions( ) throws {
76
85
var options = IndexOptions (
77
86
background: true ,
You can’t perform that action at this time.
0 commit comments