From 77c2914bdd2491d806f605fa6b926bf78b9a9f6e Mon Sep 17 00:00:00 2001 From: PatersonProjects Date: Mon, 22 Jun 2026 11:33:11 -0700 Subject: [PATCH 1/2] Base tests, with parametrization and duplicates cut Signed-off-by: PatersonProjects --- .../test_getCmdLineOpts_argument_handling.py | 36 +++++++++++ .../test_getCmdLineOpts_consistency.py | 42 +++++++++++++ .../test_getCmdLineOpts_error_conditions.py | 63 +++++++++++++++++++ .../test_getCmdLineOpts_response_structure.py | 47 ++++++++++++++ 4 files changed, 188 insertions(+) create mode 100644 documentdb_tests/compatibility/tests/system/diagnostic/commands/getCmdLineOpts/test_getCmdLineOpts_argument_handling.py create mode 100644 documentdb_tests/compatibility/tests/system/diagnostic/commands/getCmdLineOpts/test_getCmdLineOpts_consistency.py create mode 100644 documentdb_tests/compatibility/tests/system/diagnostic/commands/getCmdLineOpts/test_getCmdLineOpts_error_conditions.py create mode 100644 documentdb_tests/compatibility/tests/system/diagnostic/commands/getCmdLineOpts/test_getCmdLineOpts_response_structure.py diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/getCmdLineOpts/test_getCmdLineOpts_argument_handling.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/getCmdLineOpts/test_getCmdLineOpts_argument_handling.py new file mode 100644 index 000000000..c1a9f8ca3 --- /dev/null +++ b/documentdb_tests/compatibility/tests/system/diagnostic/commands/getCmdLineOpts/test_getCmdLineOpts_argument_handling.py @@ -0,0 +1,36 @@ +"""Tests for getCmdLineOpts command argument handling. + +Validates that getCmdLineOpts accepts any BSON type as its argument value. +The command ignores the value supplied for the ``getCmdLineOpts`` field and +always returns the command-line options, so every type should yield ok:1. +""" + +import pytest + +from documentdb_tests.framework.assertions import assertProperties +from documentdb_tests.framework.bson_type_validator import ( + BsonTypeTestCase, + generate_bson_acceptance_test_cases, +) +from documentdb_tests.framework.executor import execute_admin_command +from documentdb_tests.framework.property_checks import Eq +from documentdb_tests.framework.test_constants import BsonType + +pytestmark = pytest.mark.admin + + +BSON_TYPE_SPEC = BsonTypeTestCase( + id="getCmdLineOpts_arg", + msg="getCmdLineOpts should accept any BSON type as argument value", + keyword="getCmdLineOpts", + valid_types=list(BsonType), +) + +ACCEPTANCE_CASES = generate_bson_acceptance_test_cases([BSON_TYPE_SPEC]) + + +@pytest.mark.parametrize("bson_type,sample_value,spec", ACCEPTANCE_CASES) +def test_getCmdLineOpts_argument_types(collection, bson_type, sample_value, spec): + """Test that getCmdLineOpts accepts various BSON types as argument value.""" + result = execute_admin_command(collection, {spec.keyword: sample_value}) + assertProperties(result, {"ok": Eq(1.0)}, msg=spec.msg, raw_res=True) diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/getCmdLineOpts/test_getCmdLineOpts_consistency.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/getCmdLineOpts/test_getCmdLineOpts_consistency.py new file mode 100644 index 000000000..5ba8e019b --- /dev/null +++ b/documentdb_tests/compatibility/tests/system/diagnostic/commands/getCmdLineOpts/test_getCmdLineOpts_consistency.py @@ -0,0 +1,42 @@ +"""Tests for getCmdLineOpts command output stability. + +Validates that getCmdLineOpts returns consistent results across repeated calls. +""" + +import pytest + +from documentdb_tests.framework.assertions import assertSuccess +from documentdb_tests.framework.executor import execute_admin_command + +pytestmark = pytest.mark.admin + + +def test_getCmdLineOpts_idempotent(collection): + """Test calling getCmdLineOpts multiple times returns identical results.""" + result1 = execute_admin_command(collection, {"getCmdLineOpts": 1}) + result2 = execute_admin_command(collection, {"getCmdLineOpts": 1}) + assertSuccess(result2, expected=result1, msg="Should return identical results", raw_res=True) + + +def test_getCmdLineOpts_parsed_stable(collection): + """Test the 'parsed' content is identical across consecutive calls.""" + result1 = execute_admin_command(collection, {"getCmdLineOpts": 1}) + result2 = execute_admin_command(collection, {"getCmdLineOpts": 1}) + assertSuccess( + result2.get("parsed"), + expected=result1.get("parsed"), + msg="'parsed' content should be identical across calls", + raw_res=True, + ) + + +def test_getCmdLineOpts_argv_stable(collection): + """Test the 'argv' content is identical across consecutive calls.""" + result1 = execute_admin_command(collection, {"getCmdLineOpts": 1}) + result2 = execute_admin_command(collection, {"getCmdLineOpts": 1}) + assertSuccess( + result2.get("argv"), + expected=result1.get("argv"), + msg="'argv' content should be identical across calls", + raw_res=True, + ) diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/getCmdLineOpts/test_getCmdLineOpts_error_conditions.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/getCmdLineOpts/test_getCmdLineOpts_error_conditions.py new file mode 100644 index 000000000..2c0fed6af --- /dev/null +++ b/documentdb_tests/compatibility/tests/system/diagnostic/commands/getCmdLineOpts/test_getCmdLineOpts_error_conditions.py @@ -0,0 +1,63 @@ +"""Tests for getCmdLineOpts command error conditions. + +Validates that invalid usages of getCmdLineOpts produce appropriate errors. +""" + +import pytest + +from documentdb_tests.compatibility.tests.system.diagnostic.utils.diagnostic_test_case import ( + DiagnosticTestCase, +) +from documentdb_tests.framework.assertions import assertFailureCode +from documentdb_tests.framework.error_codes import ( + COMMAND_NOT_FOUND_ERROR, + UNAUTHORIZED_ERROR, + UNKNOWN_PIPELINE_STAGE_ERROR, + UNRECOGNIZED_COMMAND_FIELD_ERROR, +) +from documentdb_tests.framework.executor import execute_admin_command, execute_command +from documentdb_tests.framework.parametrize import pytest_params + +pytestmark = pytest.mark.admin + + +ERROR_TESTS: list[DiagnosticTestCase] = [ + DiagnosticTestCase( + id="non_admin_database", + command={"getCmdLineOpts": 1}, + use_admin=False, + error_code=UNAUTHORIZED_ERROR, + msg="getCmdLineOpts may only be run against the admin database", + ), + DiagnosticTestCase( + id="unrecognized_field", + command={"getCmdLineOpts": 1, "unknownField": 1}, + use_admin=True, + error_code=UNRECOGNIZED_COMMAND_FIELD_ERROR, + msg="Should reject unrecognized fields", + ), + DiagnosticTestCase( + id="case_sensitive", + command={"GetCmdLineOpts": 1}, + use_admin=True, + error_code=COMMAND_NOT_FOUND_ERROR, + msg="Case-mismatched command name should fail", + ), + DiagnosticTestCase( + id="as_aggregation_stage", + command={"aggregate": "test", "pipeline": [{"$getCmdLineOpts": {}}], "cursor": {}}, + use_admin=False, + error_code=UNKNOWN_PIPELINE_STAGE_ERROR, + msg="$getCmdLineOpts is not a valid aggregation stage", + ), +] + + +@pytest.mark.parametrize("test", pytest_params(ERROR_TESTS)) +def test_getCmdLineOpts_error_conditions(collection, test): + """Verifies getCmdLineOpts rejects invalid usages with appropriate error codes.""" + if test.use_admin: + result = execute_admin_command(collection, test.command) + else: + result = execute_command(collection, test.command) + assertFailureCode(result, test.error_code, msg=test.msg) diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/getCmdLineOpts/test_getCmdLineOpts_response_structure.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/getCmdLineOpts/test_getCmdLineOpts_response_structure.py new file mode 100644 index 000000000..2bf73dd6a --- /dev/null +++ b/documentdb_tests/compatibility/tests/system/diagnostic/commands/getCmdLineOpts/test_getCmdLineOpts_response_structure.py @@ -0,0 +1,47 @@ +"""Tests for getCmdLineOpts command response structure. + +Validates presence, types, and values of response fields. +""" + +import pytest + +from documentdb_tests.compatibility.tests.system.diagnostic.utils.diagnostic_test_case import ( + DiagnosticTestCase, +) +from documentdb_tests.framework.assertions import assertProperties +from documentdb_tests.framework.executor import execute_admin_command +from documentdb_tests.framework.parametrize import pytest_params +from documentdb_tests.framework.property_checks import Eq, IsType + +pytestmark = pytest.mark.admin + + +PROPERTY_TESTS: list[DiagnosticTestCase] = [ + DiagnosticTestCase( + id="ok_is_1", + checks={"ok": Eq(1.0)}, + msg="'ok' field should be 1.0", + ), + DiagnosticTestCase( + id="argv_is_array", + checks={"argv": IsType("array")}, + msg="'argv' field should be an array", + ), + DiagnosticTestCase( + id="argv_first_is_string", + checks={"argv.0": IsType("string")}, + msg="'argv' first element (binary path) should be a string", + ), + DiagnosticTestCase( + id="parsed_is_object", + checks={"parsed": IsType("object")}, + msg="'parsed' field should be a document", + ), +] + + +@pytest.mark.parametrize("test", pytest_params(PROPERTY_TESTS)) +def test_getCmdLineOpts_response_properties(collection, test): + """Verifies getCmdLineOpts response fields have expected types and values.""" + result = execute_admin_command(collection, {"getCmdLineOpts": 1}) + assertProperties(result, test.checks, msg=test.msg, raw_res=True) From 745d591893ba84b24633980152a428fd9a979f2e Mon Sep 17 00:00:00 2001 From: PatersonProjects Date: Mon, 22 Jun 2026 12:52:09 -0700 Subject: [PATCH 2/2] Added init and a few missing cases Signed-off-by: PatersonProjects --- .../commands/getCmdLineOpts/__init__.py | 0 .../test_getCmdLineOpts_argument_handling.py | 36 +++++++++++++++++-- .../test_getCmdLineOpts_consistency.py | 15 +++----- 3 files changed, 37 insertions(+), 14 deletions(-) create mode 100644 documentdb_tests/compatibility/tests/system/diagnostic/commands/getCmdLineOpts/__init__.py diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/getCmdLineOpts/__init__.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/getCmdLineOpts/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/getCmdLineOpts/test_getCmdLineOpts_argument_handling.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/getCmdLineOpts/test_getCmdLineOpts_argument_handling.py index c1a9f8ca3..cc4db7849 100644 --- a/documentdb_tests/compatibility/tests/system/diagnostic/commands/getCmdLineOpts/test_getCmdLineOpts_argument_handling.py +++ b/documentdb_tests/compatibility/tests/system/diagnostic/commands/getCmdLineOpts/test_getCmdLineOpts_argument_handling.py @@ -1,20 +1,22 @@ """Tests for getCmdLineOpts command argument handling. Validates that getCmdLineOpts accepts any BSON type as its argument value. -The command ignores the value supplied for the ``getCmdLineOpts`` field and -always returns the command-line options, so every type should yield ok:1. """ import pytest +from documentdb_tests.compatibility.tests.system.diagnostic.utils.diagnostic_test_case import ( + DiagnosticTestCase, +) from documentdb_tests.framework.assertions import assertProperties from documentdb_tests.framework.bson_type_validator import ( BsonTypeTestCase, generate_bson_acceptance_test_cases, ) from documentdb_tests.framework.executor import execute_admin_command +from documentdb_tests.framework.parametrize import pytest_params from documentdb_tests.framework.property_checks import Eq -from documentdb_tests.framework.test_constants import BsonType +from documentdb_tests.framework.test_constants import FLOAT_INFINITY, BsonType pytestmark = pytest.mark.admin @@ -28,9 +30,37 @@ ACCEPTANCE_CASES = generate_bson_acceptance_test_cases([BSON_TYPE_SPEC]) +EDGE_CASES: list[DiagnosticTestCase] = [ + DiagnosticTestCase( + "int_0", + command={"getCmdLineOpts": 0}, + checks={"ok": Eq(1.0)}, + msg="Should accept int 0", + ), + DiagnosticTestCase( + "int_neg1", + command={"getCmdLineOpts": -1}, + checks={"ok": Eq(1.0)}, + msg="Should accept int -1", + ), + DiagnosticTestCase( + "infinity", + command={"getCmdLineOpts": FLOAT_INFINITY}, + checks={"ok": Eq(1.0)}, + msg="Should accept infinity", + ), +] + @pytest.mark.parametrize("bson_type,sample_value,spec", ACCEPTANCE_CASES) def test_getCmdLineOpts_argument_types(collection, bson_type, sample_value, spec): """Test that getCmdLineOpts accepts various BSON types as argument value.""" result = execute_admin_command(collection, {spec.keyword: sample_value}) assertProperties(result, {"ok": Eq(1.0)}, msg=spec.msg, raw_res=True) + + +@pytest.mark.parametrize("test", pytest_params(EDGE_CASES)) +def test_getCmdLineOpts_argument_edge_cases(collection, test): + """Test that getCmdLineOpts accepts numeric edge case values.""" + result = execute_admin_command(collection, test.command) + assertProperties(result, test.checks, msg=test.msg, raw_res=True) diff --git a/documentdb_tests/compatibility/tests/system/diagnostic/commands/getCmdLineOpts/test_getCmdLineOpts_consistency.py b/documentdb_tests/compatibility/tests/system/diagnostic/commands/getCmdLineOpts/test_getCmdLineOpts_consistency.py index 5ba8e019b..7da27970c 100644 --- a/documentdb_tests/compatibility/tests/system/diagnostic/commands/getCmdLineOpts/test_getCmdLineOpts_consistency.py +++ b/documentdb_tests/compatibility/tests/system/diagnostic/commands/getCmdLineOpts/test_getCmdLineOpts_consistency.py @@ -11,20 +11,13 @@ pytestmark = pytest.mark.admin -def test_getCmdLineOpts_idempotent(collection): - """Test calling getCmdLineOpts multiple times returns identical results.""" - result1 = execute_admin_command(collection, {"getCmdLineOpts": 1}) - result2 = execute_admin_command(collection, {"getCmdLineOpts": 1}) - assertSuccess(result2, expected=result1, msg="Should return identical results", raw_res=True) - - def test_getCmdLineOpts_parsed_stable(collection): """Test the 'parsed' content is identical across consecutive calls.""" result1 = execute_admin_command(collection, {"getCmdLineOpts": 1}) result2 = execute_admin_command(collection, {"getCmdLineOpts": 1}) assertSuccess( - result2.get("parsed"), - expected=result1.get("parsed"), + result2["parsed"], + expected=result1["parsed"], msg="'parsed' content should be identical across calls", raw_res=True, ) @@ -35,8 +28,8 @@ def test_getCmdLineOpts_argv_stable(collection): result1 = execute_admin_command(collection, {"getCmdLineOpts": 1}) result2 = execute_admin_command(collection, {"getCmdLineOpts": 1}) assertSuccess( - result2.get("argv"), - expected=result1.get("argv"), + result2["argv"], + expected=result1["argv"], msg="'argv' content should be identical across calls", raw_res=True, )