Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
"""Tests for getCmdLineOpts command argument handling.

Validates that getCmdLineOpts accepts any BSON type as its argument value.
"""

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 FLOAT_INFINITY, 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])

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)
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""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_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["parsed"],
expected=result1["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["argv"],
expected=result1["argv"],
msg="'argv' content should be identical across calls",
raw_res=True,
)
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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)
Loading