Skip to content

Commit e3dee07

Browse files
authored
SWIFT-429 Implement auth spec tests (#333)
1 parent 75d884b commit e3dee07

File tree

7 files changed

+343
-33
lines changed

7 files changed

+343
-33
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ dist: trusty
44

55
env:
66
global:
7-
- MONGODB_VERSION=3.6.5
7+
- MONGODB_VERSION=3.6.14
88
- LIBMONGOC_VERSION=r1.15
99
- LIBMONGOC_CACHE_DIR=${HOME}/libmongoc-${LIBMONGOC_VERSION}
1010

Sources/MongoSwift/ConnectionString.swift

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,45 +5,33 @@ internal class ConnectionString {
55
/// Pointer to the underlying `mongoc_uri_t`.
66
internal let _uri: OpaquePointer
77

8-
/// Initializes a new `ConnectionString` with the provided options. Updates `options` to correctly reflect the
9-
/// final options set on the `ConnectionString`.
10-
internal init(_ connectionString: String, options: inout ClientOptions) throws {
8+
/// Initializes a new `ConnectionString` with the provided options.
9+
internal init(_ connectionString: String, options: ClientOptions? = nil) throws {
1110
var error = bson_error_t()
1211
guard let uri = mongoc_uri_new_with_error(connectionString, &error) else {
1312
throw extractMongoError(error: error)
1413
}
1514
self._uri = uri
1615

17-
if let rc = options.readConcern {
16+
if let rc = options?.readConcern {
1817
self.readConcern = rc
1918
}
20-
options.readConcern = self.readConcern
2119

22-
if let wc = options.writeConcern {
20+
if let wc = options?.writeConcern {
2321
self.writeConcern = wc
2422
}
25-
options.writeConcern = self.writeConcern
2623

27-
if let rp = options.readPreference {
24+
if let rp = options?.readPreference {
2825
self.readPreference = rp
2926
}
30-
options.readPreference = self.readPreference
3127

32-
if let rw = options.retryWrites {
28+
if let rw = options?.retryWrites {
3329
mongoc_uri_set_option_as_bool(self._uri, MONGOC_URI_RETRYWRITES, rw)
3430
}
35-
if let rr = options.retryReads {
36-
mongoc_uri_set_option_as_bool(self._uri, MONGOC_URI_RETRYREADS, rr)
37-
}
3831

39-
// we can't get values for retryReads and retryWrites individually, so we will read
40-
// them out from the full doc here instead.
41-
guard let opts = mongoc_uri_get_options(self._uri) else {
42-
return
32+
if let rr = options?.retryReads {
33+
mongoc_uri_set_option_as_bool(self._uri, MONGOC_URI_RETRYREADS, rr)
4334
}
44-
let optsDoc = Document(copying: opts)
45-
options.retryReads = optsDoc["retryreads"] as? Bool
46-
options.retryWrites = optsDoc["retrywrites"] as? Bool
4735
}
4836

4937
/// Cleans up the underlying `mongoc_uri_t`.

Sources/MongoSwift/MongoClient.swift

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -217,29 +217,30 @@ public class SyncMongoClient {
217217
// Initialize mongoc. Repeated calls have no effect so this is safe to do every time.
218218
initializeMongoc()
219219

220-
var options = options ?? ClientOptions()
221-
let connString = try ConnectionString(connectionString, options: &options)
222-
self.connectionPool = try ConnectionPool(from: connString, options: options.tlsOptions)
220+
let connString = try ConnectionString(connectionString, options: options)
221+
self.connectionPool = try ConnectionPool(from: connString, options: options?.tlsOptions)
223222

224-
if let rc = options.readConcern, !rc.isDefault {
223+
let rc = connString.readConcern
224+
if !rc.isDefault {
225225
self.readConcern = rc
226226
} else {
227227
self.readConcern = nil
228228
}
229229

230-
if let wc = options.writeConcern, !wc.isDefault {
230+
let wc = connString.writeConcern
231+
if !wc.isDefault {
231232
self.writeConcern = wc
232233
} else {
233234
self.writeConcern = nil
234235
}
235236

236-
self.readPreference = options.readPreference ?? ReadPreference()
237+
self.readPreference = connString.readPreference
237238
self.encoder = BSONEncoder(options: options)
238239
self.decoder = BSONDecoder(options: options)
239-
self.notificationCenter = options.notificationCenter ?? NotificationCenter.default
240+
self.notificationCenter = options?.notificationCenter ?? NotificationCenter.default
240241

241-
self.connectionPool.initializeMonitoring(commandMonitoring: options.commandMonitoring,
242-
serverMonitoring: options.serverMonitoring,
242+
self.connectionPool.initializeMonitoring(commandMonitoring: options?.commandMonitoring ?? false,
243+
serverMonitoring: options?.serverMonitoring ?? false,
243244
client: self)
244245
}
245246

Tests/LinuxMain.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
@testable import MongoSwiftTests
66
import XCTest
77

8+
extension AuthTests {
9+
static var allTests = [
10+
("testAuthConnectionStrings", testAuthConnectionStrings),
11+
("testAuthProseTests", testAuthProseTests),
12+
]
13+
}
14+
815
extension BSONValueTests {
916
static var allTests = [
1017
("testInvalidDecimal128", testInvalidDecimal128),
@@ -283,6 +290,7 @@ extension SDAMTests {
283290
}
284291

285292
XCTMain([
293+
testCase(AuthTests.allTests),
286294
testCase(BSONValueTests.allTests),
287295
testCase(ChangeStreamSpecTests.allTests),
288296
testCase(ChangeStreamTests.allTests),

0 commit comments

Comments
 (0)