Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: mongodb connectionURL parse options (#7560)
- Loading branch information
Showing
3 changed files
with
68 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import "reflect-metadata"; | ||
import { DriverUtils } from "../../../src/driver/DriverUtils" | ||
import { expect } from "chai"; | ||
|
||
describe("github issues > #7401 MongoDB replica set connection string not support with method \"parseConnectionUrl\" & \"buildConnectionUrl\"", () => { | ||
|
||
it("should parse replicaSet and host list in ConnectionUrl", () => { | ||
|
||
var options = DriverUtils.buildMongoDBDriverOptions({url: "mongodb://testuser:testpwd@test-primary.example.com:27017,test-secondary-1.example.com:27017,test-secondary-2.example.com:27017/testdb?replicaSet=testreplicaset"}) | ||
|
||
expect((options.hostReplicaSet ? options.hostReplicaSet as string : '')).to.equal('test-primary.example.com:27017,test-secondary-1.example.com:27017,test-secondary-2.example.com:27017'); | ||
expect((options.username ? options.username as string : '')).to.equal('testuser'); | ||
expect((options.password ? options.password as string : '')).to.equal('testpwd'); | ||
expect((options.database ? options.database as string : '')).to.equal('testdb'); | ||
expect((options.replicaSet ? options.replicaSet as string : '')).to.equal('testreplicaset'); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import "reflect-metadata"; | ||
import { DriverUtils } from "../../../src/driver/DriverUtils" | ||
import { expect } from "chai"; | ||
|
||
describe("github issues > #7437 MongoDB options never parse in connectionUrl and after my fix was parse incorrect", () => { | ||
|
||
it("should parse options in ConnectionUrl", () => { | ||
|
||
var options = DriverUtils.buildMongoDBDriverOptions({url: "mongodb://testuser:testpwd@test-primary.example.com:27017/testdb?retryWrites=true&w=majority&useUnifiedTopology=true"}) | ||
|
||
expect((options.host ? options.host as string : '')).to.equal('test-primary.example.com'); | ||
expect((options.username ? options.username as string : '')).to.equal('testuser'); | ||
expect((options.password ? options.password as string : '')).to.equal('testpwd'); | ||
expect((options.port ? options.port as number : 0)).to.equal(27017); | ||
expect((options.database ? options.database as string : '')).to.equal('testdb'); | ||
|
||
expect((options.retryWrites ? options.retryWrites as string : '')).to.equal('true'); | ||
expect((options.w ? options.w as string : '')).to.equal('majority'); | ||
expect((options.useUnifiedTopology ? options.useUnifiedTopology as string : '')).to.equal('true'); | ||
}); | ||
|
||
}); |