Added index tests for $listIndexes#150
Conversation
Signed-off-by: Victor Tsang <vitsangp@amazon.com>
|
🤖 Auto-triaged by documentdb-triage-tool. Applied: Reasoningcomponent 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 |
| database_client.drop_collection(coll_name) | ||
|
|
||
|
|
||
| def test_listIndexes_timeseries_with_secondary(database_client): |
There was a problem hiding this comment.
listIndexes ordering is NOT guaranteed by spec. Use assertSuccessPartial or sort both sides — otherwise flaky.
| 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) | ||
|
|
There was a problem hiding this comment.
does clean up need db.system.profile.drop() this?
| 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"}, | ||
| ], | ||
| ) |
| {"v": 2, "key": {"_id": 1}, "name": "_id_"}, | ||
| {"v": 2, "key": {"$**": 1}, "name": "wildcard"}, | ||
| ], | ||
| msg="Wildcard index should appear in listIndexes output", |
There was a problem hiding this comment.
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 }
}
]
This PR contains
Ref: