Skip to content

Commit 985f8fb

Browse files
committed
fix: get default vhost if empty string is provided
1 parent f607189 commit 985f8fb

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/client.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,10 @@ export class Client {
700700
}
701701

702702
static async connect(params: ClientParams, logger?: Logger): Promise<Client> {
703-
return new Client(logger ?? new NullLogger(), params).start()
703+
return new Client(logger ?? new NullLogger(), {
704+
...params,
705+
vhost: getVhostOrDefault(params.vhost),
706+
}).start()
704707
}
705708
}
706709

@@ -832,3 +835,5 @@ const extractConsumerId = (extendedConsumerId: string) => {
832835
const extractPublisherId = (extendedPublisherId: string) => {
833836
return parseInt(extendedPublisherId.split("@").shift() ?? "0")
834837
}
838+
839+
const getVhostOrDefault = (vhost: string) => (vhost === "" ? "/" : vhost)

test/e2e/connect.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,23 @@ describe("connect", () => {
4646
}, 5000)
4747
}).timeout(10000)
4848

49+
it("with default vhost as '/' ", async () => {
50+
const [firstNode] = getTestNodesFromEnv()
51+
client = await connect({
52+
hostname: firstNode.host,
53+
port: firstNode.port,
54+
username,
55+
password,
56+
vhost: "",
57+
frameMax: 0,
58+
heartbeat: 0,
59+
})
60+
61+
await eventually(async () => {
62+
expect(await rabbit.getConnections()).lengthOf(1)
63+
}, 5000)
64+
}).timeout(10000)
65+
4966
it("using EXTERNAL auth", async () => {
5067
client = await createTlsClient()
5168

0 commit comments

Comments
 (0)