Skip to content

Commit

Permalink
fix: fix failed test in mongo-4.4 (denodrivers#247)
Browse files Browse the repository at this point in the history
  • Loading branch information
flappyBug committed Sep 8, 2021
1 parent a677765 commit 10b7121
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/collection/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ export class Collection<T> {

listIndexes() {
return new ListIndexesCursor<
{ v: number; key: Document; name: string; ns: string }
{ v: number; key: Document; name: string; ns?: string }
>({
protocol: this.#protocol,
dbName: this.#dbName,
Expand Down
33 changes: 24 additions & 9 deletions tests/cases/04_indexes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { testWithClient } from "../common.ts";
import { assertEquals } from "../test.deps.ts";
import { assertEquals, semver } from "../test.deps.ts";

export default function indexesTests() {
testWithClient("createIndexes", async (client) => {
Expand Down Expand Up @@ -27,12 +27,19 @@ export default function indexesTests() {
const users = db.collection("mongo_test_users");
const cursor = users.listIndexes();
const indexes = await cursor.toArray();
assertEquals(
indexes,
[

const expected = semver.gte(client.buildInfo!.version, "4.4.0")
? [
{ v: 2, key: { _id: 1 }, name: "_id_" },
{ v: 2, key: { name: 1 }, name: "_name" },
]
: [
{ v: 2, key: { _id: 1 }, name: "_id_", ns: "test.mongo_test_users" },
{ v: 2, key: { name: 1 }, name: "_name", ns: "test.mongo_test_users" },
],
];
assertEquals(
indexes,
expected,
);
});

Expand All @@ -52,12 +59,20 @@ export default function indexesTests() {
});

const indexes = await users.listIndexes().toArray();

const expected = semver.gte(client.buildInfo!.version, "4.4.0")
? [
{ v: 2, key: { _id: 1 }, name: "_id_" },
]
: [
{ v: 2, key: { _id: 1 }, name: "_id_", ns: "test.mongo_test_users" },
];
assertEquals(
indexes,
[
{ v: 2, key: { _id: 1 }, name: "_id_", ns: "test.mongo_test_users" },
],
expected,
);
assertEquals(
indexes,
expected,
);
});
}
1 change: 1 addition & 0 deletions tests/test.deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export {
assertThrows,
assertThrowsAsync,
} from "https://deno.land/std@0.105.0/testing/asserts.ts";
export * as semver from "https://deno.land/x/semver@v1.4.0/mod.ts";

0 comments on commit 10b7121

Please sign in to comment.