2024-03-06 21:00:14 +00:00
|
|
|
// This test ensures correct error handling for the createSearchIndex shell command
|
2024-10-25 17:30:09 -04:00
|
|
|
import {createSearchIndex} from "jstests/libs/search.js";
|
2024-03-06 21:00:14 +00:00
|
|
|
const coll = db[jsTestName()];
|
|
|
|
|
coll.drop();
|
|
|
|
|
|
2025-08-21 10:17:44 -07:00
|
|
|
let error = assert.throws(() =>
|
|
|
|
|
createSearchIndex(
|
|
|
|
|
coll,
|
|
|
|
|
{name: "foo-block", definition: {"mappings": {"dynamic": true}}},
|
|
|
|
|
{blockUntilSearchIndexQueryable: "true"},
|
|
|
|
|
),
|
|
|
|
|
);
|
2024-03-06 21:00:14 +00:00
|
|
|
let expectedMessage = "Error: 'blockUntilSearchIndexQueryable' argument must be a boolean";
|
|
|
|
|
assert.eq(error, expectedMessage);
|
|
|
|
|
|
2025-08-21 10:17:44 -07:00
|
|
|
error = assert.throws(() =>
|
|
|
|
|
createSearchIndex(coll, {name: "foo-block", definition: {"mappings": {"dynamic": true}}}, {arg2: 1}),
|
|
|
|
|
);
|
2024-03-06 21:00:14 +00:00
|
|
|
expectedMessage =
|
2024-05-31 22:37:07 +00:00
|
|
|
"Error: createSearchIndex only accepts index definition object and blockUntilSearchIndexQueryable object";
|
2024-03-06 21:00:14 +00:00
|
|
|
assert.eq(error, expectedMessage);
|
|
|
|
|
|
2025-08-21 10:17:44 -07:00
|
|
|
error = assert.throws(() =>
|
|
|
|
|
createSearchIndex(
|
|
|
|
|
coll,
|
|
|
|
|
{name: "foo-block", definition: {"mappings": {"dynamic": true}}},
|
|
|
|
|
{arg2: 1},
|
|
|
|
|
{arg3: "three"},
|
|
|
|
|
),
|
|
|
|
|
);
|
2024-10-25 17:30:09 -04:00
|
|
|
expectedMessage = "Error: createSearchIndex accepts up to 3 arguments";
|
2024-03-06 21:00:14 +00:00
|
|
|
assert.eq(error, expectedMessage);
|
|
|
|
|
|
2024-10-25 17:30:09 -04:00
|
|
|
error = assert.throws(() => createSearchIndex(coll, {name: "foo-block"}));
|
2024-05-31 22:37:07 +00:00
|
|
|
expectedMessage = "Error: createSearchIndex must have a definition";
|
2025-08-21 10:17:44 -07:00
|
|
|
assert.eq(error, expectedMessage);
|