-
Notifications
You must be signed in to change notification settings - Fork 33
Add getLog tests #640
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
PatersonProjects
wants to merge
10
commits into
documentdb:main
Choose a base branch
from
PatersonProjects:getLog_tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add getLog tests #640
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
13de1c2
Base tests
PatersonProjects 467062a
Parametrized tests
PatersonProjects 37c0d29
Reorganized Tests, removed out of scope cases
PatersonProjects bdde7c8
Added log behavior tests and needed checks
PatersonProjects 963555c
Test cleanup, added missing coverage
PatersonProjects e8edf8e
Dropped log formatting test
PatersonProjects da6cac0
Removed comments
PatersonProjects e5ae6a2
Dropped out of scope test
PatersonProjects 168ae13
Added case-sensitive test
PatersonProjects 6b61746
Merge branch 'main' into getLog_tests
PatersonProjects File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
41 changes: 41 additions & 0 deletions
41
.../compatibility/tests/system/diagnostic/commands/getLog/test_getLog_argument_validation.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| """Tests for getLog command argument validation. | ||
|
|
||
| Covers BSON type handling for the ``getLog`` field value. Only a string is | ||
| accepted; every non-string type is rejected with TypeMismatch. | ||
|
|
||
| Invalid string values (e.g. unknown components, the deprecated "rs") and | ||
| unrecognized command fields are covered in test_getLog_errors.py. | ||
| """ | ||
|
|
||
| import pytest | ||
|
|
||
| from documentdb_tests.framework.assertions import assertFailureCode | ||
| from documentdb_tests.framework.bson_type_validator import ( | ||
| BsonTypeTestCase, | ||
| generate_bson_rejection_test_cases, | ||
| ) | ||
| from documentdb_tests.framework.error_codes import MISSING_FIELD_ERROR, TYPE_MISMATCH_ERROR | ||
| from documentdb_tests.framework.executor import execute_admin_command | ||
| from documentdb_tests.framework.test_constants import BsonType | ||
|
|
||
| pytestmark = pytest.mark.admin | ||
|
|
||
| BSON_TYPE_PARAMS = [ | ||
| BsonTypeTestCase( | ||
| id="getLog_value", | ||
| msg="getLog should reject non-string value types", | ||
| keyword="getLog", | ||
| valid_types=[BsonType.STRING], | ||
| default_error_code=TYPE_MISMATCH_ERROR, | ||
| error_code_overrides={BsonType.NULL: MISSING_FIELD_ERROR}, | ||
| ), | ||
| ] | ||
|
|
||
| REJECTION_CASES = generate_bson_rejection_test_cases(BSON_TYPE_PARAMS) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("bson_type,sample_value,spec", REJECTION_CASES) | ||
| def test_getLog_rejects_non_string_value(collection, bson_type, sample_value, spec): | ||
| """Test getLog rejects each non-string BSON type for its value.""" | ||
| result = execute_admin_command(collection, {"getLog": sample_value}) | ||
| assertFailureCode(result, spec.expected_code(bson_type), msg=spec.msg) |
77 changes: 77 additions & 0 deletions
77
documentdb_tests/compatibility/tests/system/diagnostic/commands/getLog/test_getLog_errors.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| """Tests for getLog command error conditions. | ||
|
|
||
| Covers invalid log component names (unknown component, the deprecated "rs" | ||
| value, empty string), unrecognized command fields, and the admin-database | ||
| requirement. | ||
|
|
||
| BSON type rejection/acceptance for the value is covered in | ||
| test_getLog_argument_validation.py. | ||
| """ | ||
|
|
||
| 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, | ||
| OPERATION_FAILED_ERROR, | ||
| UNAUTHORIZED_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( | ||
| "unknown_component", | ||
| command={"getLog": "invalid"}, | ||
| error_code=OPERATION_FAILED_ERROR, | ||
| msg="Unknown log component name should error", | ||
| ), | ||
| DiagnosticTestCase( | ||
| "deprecated_rs", | ||
| command={"getLog": "rs"}, | ||
| error_code=OPERATION_FAILED_ERROR, | ||
| msg="Deprecated 'rs' value should error", | ||
| ), | ||
| DiagnosticTestCase( | ||
| "empty_string", | ||
| command={"getLog": ""}, | ||
| error_code=OPERATION_FAILED_ERROR, | ||
| msg="Empty string component should error", | ||
| ), | ||
| DiagnosticTestCase( | ||
| "unrecognized_field", | ||
| command={"getLog": "global", "unknownField": 1}, | ||
| error_code=UNRECOGNIZED_COMMAND_FIELD_ERROR, | ||
| msg="Unrecognized command field should error", | ||
| ), | ||
| DiagnosticTestCase( | ||
| "non_admin_database", | ||
| command={"getLog": "global"}, | ||
| use_admin=False, | ||
| error_code=UNAUTHORIZED_ERROR, | ||
| msg="getLog should only run on the admin database", | ||
| ), | ||
| DiagnosticTestCase( | ||
| "case_sensitive_command_name", | ||
| command={"GetLog": "global"}, | ||
| error_code=COMMAND_NOT_FOUND_ERROR, | ||
| msg="Command name is case-sensitive; 'GetLog' should not be found", | ||
| ), | ||
| ] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("test", pytest_params(ERROR_TESTS)) | ||
| def test_getLog_error(collection, test): | ||
| """Test getLog returns the expected error code for invalid arguments.""" | ||
| 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) | ||
104 changes: 104 additions & 0 deletions
104
...s/compatibility/tests/system/diagnostic/commands/getLog/test_getLog_response_structure.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| """Tests for getLog command response structure. | ||
|
|
||
| Covers response fields for the "global" filter (totalLinesWritten, log array | ||
| capped at 1024 entries, string log entries, ok), the "startupWarnings" filter | ||
| (totalLinesWritten, log array, ok), and the "*" filter (names array, ok). | ||
| Each test asserts a single response property. | ||
| """ | ||
|
|
||
| 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 ContainsElement, Eq, Gte, IsType, LenLte | ||
|
|
||
| pytestmark = pytest.mark.admin | ||
|
|
||
| MAX_LOG_EVENTS = 1024 | ||
|
|
||
|
|
||
| RESPONSE_TESTS: list[DiagnosticTestCase] = [ | ||
| DiagnosticTestCase( | ||
| "global_totalLinesWritten_number", | ||
| command={"getLog": "global"}, | ||
| checks={"totalLinesWritten": Gte(0)}, | ||
| msg="global should return a non-negative totalLinesWritten", | ||
| ), | ||
| DiagnosticTestCase( | ||
| "global_log_is_array", | ||
| command={"getLog": "global"}, | ||
| checks={"log": IsType("array")}, | ||
| msg="global should return a log array", | ||
| ), | ||
| DiagnosticTestCase( | ||
| "global_log_capped_at_1024", | ||
| command={"getLog": "global"}, | ||
| checks={"log": LenLte(MAX_LOG_EVENTS)}, | ||
| msg="global log array should contain at most 1024 entries", | ||
| ), | ||
| DiagnosticTestCase( | ||
| "global_log_entry_is_string", | ||
| command={"getLog": "global"}, | ||
| checks={"log.0": IsType("string")}, | ||
| msg="global log entries should be JSON-formatted strings", | ||
| ), | ||
| DiagnosticTestCase( | ||
| "global_ok", | ||
| command={"getLog": "global"}, | ||
| checks={"ok": Eq(1.0)}, | ||
| msg="global should return ok:1", | ||
| ), | ||
| DiagnosticTestCase( | ||
| "startupWarnings_log_is_array", | ||
| command={"getLog": "startupWarnings"}, | ||
| checks={"log": IsType("array")}, | ||
| msg="startupWarnings should return a log array", | ||
| ), | ||
| DiagnosticTestCase( | ||
| "startupWarnings_ok", | ||
| command={"getLog": "startupWarnings"}, | ||
| checks={"ok": Eq(1.0)}, | ||
| msg="startupWarnings should return ok:1", | ||
| ), | ||
| DiagnosticTestCase( | ||
| "startupWarnings_totalLinesWritten_number", | ||
| command={"getLog": "startupWarnings"}, | ||
| checks={"totalLinesWritten": Gte(0)}, | ||
| msg="startupWarnings should return a non-negative totalLinesWritten", | ||
| ), | ||
| DiagnosticTestCase( | ||
| "wildcard_names_is_array", | ||
| command={"getLog": "*"}, | ||
| checks={"names": IsType("array")}, | ||
| msg="'*' should return a names array", | ||
| ), | ||
| DiagnosticTestCase( | ||
| "wildcard_names_contains_global", | ||
| command={"getLog": "*"}, | ||
| checks={"names": ContainsElement("global")}, | ||
| msg="'*' names should include 'global'", | ||
| ), | ||
| DiagnosticTestCase( | ||
| "wildcard_names_contains_startupWarnings", | ||
| command={"getLog": "*"}, | ||
| checks={"names": ContainsElement("startupWarnings")}, | ||
| msg="'*' names should include 'startupWarnings'", | ||
| ), | ||
| DiagnosticTestCase( | ||
| "wildcard_ok", | ||
| command={"getLog": "*"}, | ||
| checks={"ok": Eq(1.0)}, | ||
| msg="'*' should return ok:1", | ||
| ), | ||
| ] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("test", pytest_params(RESPONSE_TESTS)) | ||
| def test_getLog_response_properties(collection, test): | ||
| """Verify a getLog response field exists and has the expected type or value.""" | ||
| result = execute_admin_command(collection, test.command) | ||
| assertProperties(result, test.checks, msg=test.msg, raw_res=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.