Skip to content

Added index tests for $listIndexes#150

Open
vic-tsang wants to merge 1 commit intodocumentdb:mainfrom
vic-tsang:indexes/listIndexes/tests
Open

Added index tests for $listIndexes#150
vic-tsang wants to merge 1 commit intodocumentdb:mainfrom
vic-tsang:indexes/listIndexes/tests

Conversation

@vic-tsang
Copy link
Copy Markdown
Collaborator

This PR contains

  • index tests for $listIndexes

Ref:

Signed-off-by: Victor Tsang <vitsangp@amazon.com>
@vic-tsang vic-tsang requested a review from a team as a code owner April 29, 2026 23:51
@documentdb-triage-tool documentdb-triage-tool Bot added compatibility test Compatibility test related enhancement New feature or request labels Apr 30, 2026
@documentdb-triage-tool
Copy link
Copy Markdown

🤖 Auto-triaged by documentdb-triage-tool.

Applied: compatibility test, enhancement
Project fields suggested: Component test-coverage · Priority P2 · Effort L · Status Needs Review
Confidence: 0.85 (mixed)

Reasoning

component from path globs (test-coverage, test-framework); effort from diff stats (1917+3 LOC, 10 files); LLM: Adds new index tests for $listIndexes command, expanding test coverage for an existing feature tracked in issue #27.

If a label is wrong, remove it manually and ping @patty-chow so the rules can be tuned. The bot will not re-label items that already have component labels.

database_client.drop_collection(coll_name)


def test_listIndexes_timeseries_with_secondary(database_client):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

listIndexes ordering is NOT guaranteed by spec. Use assertSuccessPartial or sort both sides — otherwise flaky.

Comment on lines +211 to +234
def test_listIndexes_system_profile(database_client):
"""Test listIndexes on system.profile collection returns empty firstBatch."""
db = database_client
db.command({"profile": 2})
try:
result = execute_command(db["system.profile"], {"listIndexes": "system.profile"})
assertSuccess(result, [])
finally:
db.command({"profile": 0})


def test_listIndexes_system_views(database_client):
"""Test listIndexes on system.views collection returns _id index."""
src_name = "test_sys_views_src"
database_client[src_name].insert_one({"_id": 1})
database_client.create_collection("test_view_for_sys", viewOn=src_name, pipeline=[])

try:
result = execute_command(database_client["system.views"], {"listIndexes": "system.views"})
assertSuccess(result, [{"v": 2, "key": {"_id": 1}, "name": "_id_"}])
finally:
database_client.drop_collection("test_view_for_sys")
database_client.drop_collection(src_name)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does clean up need db.system.profile.drop() this?

Comment on lines +93 to +106
def test_listIndexes_omit_cursor_returns_all(collection_with_3_indexes):
"""Test listIndexes without cursor field returns all indexes."""
result = execute_command(
collection_with_3_indexes, {"listIndexes": collection_with_3_indexes.name}
)

assertSuccess(
result,
[
{"v": 2, "key": {"_id": 1}, "name": "_id_"},
{"v": 2, "key": {"a": 1}, "name": "a_1"},
{"v": 2, "key": {"b": 1}, "name": "b_1"},
],
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seem redundant. can we remove it

{"v": 2, "key": {"_id": 1}, "name": "_id_"},
{"v": 2, "key": {"$**": 1}, "name": "wildcard"},
],
msg="Wildcard index should appear in listIndexes output",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing wildcardProjection cases

test> db.test.createIndex({"$**":1},{"wildcardProjection":{a:1}})
$**_1
test> db.test.getIndexes()
[
  { v: 2, key: { _id: 1 }, name: '_id_' },
  {
    v: 2,
    key: { '$**': 1 },
    name: '$**_1',
    wildcardProjection: { a: 1 }
  }
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compatibility test Compatibility test related enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants