-
Notifications
You must be signed in to change notification settings - Fork 33
Add validate tests
#639
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
alinaliBQ
wants to merge
15
commits into
documentdb:main
Choose a base branch
from
alinaliBQ:validate
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 validate tests
#639
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
f122485
inital generated tests
alinaliBQ e345708
update with style guide
alinaliBQ 01c02a4
remove duplicates and formats
alinaliBQ deba234
change according to review guide
alinaliBQ 7c68964
add setup field
alinaliBQ 7de16e5
split files
alinaliBQ 823bc5b
add missing tests
alinaliBQ ac37999
remove exact duplicates
alinaliBQ ec3203f
rename tests
alinaliBQ 332eb7e
merge identical test functions
alinaliBQ 058d49b
fix PR
alinaliBQ 0604735
put success together
alinaliBQ d2322a8
remove near-identical BSON cases
alinaliBQ 2cd3cf6
add validate_repair and skip on tests that fail on replica_set
alinaliBQ f7e4015
add helper bind_collection
alinaliBQ 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.
168 changes: 168 additions & 0 deletions
168
...patibility/tests/system/diagnostic/commands/validate/test_validate_bool_param_coercion.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,168 @@ | ||
| """Canonical BSON type coercion matrix for validate boolean parameters. | ||
|
|
||
| Uses 'full' as the representative parameter. All boolean parameters | ||
| (full, metadata, checkBSONConformance, repair, fixMultikey) share the | ||
| same coercion logic; other per-parameter files contain only wiring tests. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from datetime import datetime, timezone | ||
|
|
||
| import pytest | ||
| from bson import Binary, Code, Decimal128, Int64, MaxKey, MinKey, ObjectId, Regex, Timestamp | ||
|
|
||
| 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_command | ||
| from documentdb_tests.framework.parametrize import pytest_params | ||
| from documentdb_tests.framework.property_checks import Eq | ||
|
|
||
| # Property [Type Coercion]: validate accepts all BSON types for the full parameter via coercion. | ||
| ACCEPTED_TYPE_TESTS: list[DiagnosticTestCase] = [ | ||
| DiagnosticTestCase( | ||
| "bool_true", | ||
| command={"full": True}, | ||
| checks={"ok": Eq(1.0)}, | ||
| msg="full should accept bool true", | ||
| ), | ||
| DiagnosticTestCase( | ||
| "bool_false", | ||
| command={"full": False}, | ||
| checks={"ok": Eq(1.0)}, | ||
| msg="full should accept bool false", | ||
| ), | ||
| DiagnosticTestCase( | ||
| "int32_1", | ||
| command={"full": 1}, | ||
| checks={"ok": Eq(1.0)}, | ||
| msg="full should accept int32 1 (coerces to true)", | ||
| ), | ||
| DiagnosticTestCase( | ||
| "int32_0", | ||
| command={"full": 0}, | ||
| checks={"ok": Eq(1.0)}, | ||
| msg="full should accept int32 0 (coerces to false)", | ||
| ), | ||
| DiagnosticTestCase( | ||
| "double_1", | ||
| command={"full": 1.0}, | ||
| checks={"ok": Eq(1.0)}, | ||
| msg="full should accept double 1.0 (coerces to true)", | ||
| ), | ||
| DiagnosticTestCase( | ||
| "double_0", | ||
| command={"full": 0.0}, | ||
| checks={"ok": Eq(1.0)}, | ||
| msg="full should accept double 0.0 (coerces to false)", | ||
| ), | ||
| DiagnosticTestCase( | ||
| "int64_1", | ||
| command={"full": Int64(1)}, | ||
| checks={"ok": Eq(1.0)}, | ||
| msg="full should accept Int64(1) (coerces to true)", | ||
| ), | ||
| DiagnosticTestCase( | ||
| "int64_0", | ||
| command={"full": Int64(0)}, | ||
| checks={"ok": Eq(1.0)}, | ||
| msg="full should accept Int64(0) (coerces to false)", | ||
| ), | ||
| DiagnosticTestCase( | ||
| "decimal128_1", | ||
| command={"full": Decimal128("1")}, | ||
| checks={"ok": Eq(1.0)}, | ||
| msg="full should accept Decimal128('1') (coerces to true)", | ||
| ), | ||
| DiagnosticTestCase( | ||
| "decimal128_0", | ||
| command={"full": Decimal128("0")}, | ||
| checks={"ok": Eq(1.0)}, | ||
| msg="full should accept Decimal128('0') (coerces to false)", | ||
| ), | ||
| DiagnosticTestCase( | ||
| "null", | ||
| command={"full": None}, | ||
| checks={"ok": Eq(1.0)}, | ||
| msg="full should accept null (treated as omitted/false)", | ||
| ), | ||
| DiagnosticTestCase( | ||
| "string", | ||
| command={"full": "true"}, | ||
| checks={"ok": Eq(1.0)}, | ||
| msg="full should accept string (coerces to truthy)", | ||
| ), | ||
| DiagnosticTestCase( | ||
| "object", | ||
| command={"full": {}}, | ||
| checks={"ok": Eq(1.0)}, | ||
| msg="full should accept object (coerces to truthy)", | ||
| ), | ||
| DiagnosticTestCase( | ||
| "array", | ||
| command={"full": []}, | ||
| checks={"ok": Eq(1.0)}, | ||
| msg="full should accept array (coerces to truthy)", | ||
| ), | ||
| DiagnosticTestCase( | ||
| "binary", | ||
| command={"full": Binary(b"")}, | ||
| checks={"ok": Eq(1.0)}, | ||
| msg="full should accept Binary (coerces to truthy)", | ||
| ), | ||
| DiagnosticTestCase( | ||
| "objectid", | ||
| command={"full": ObjectId()}, | ||
| checks={"ok": Eq(1.0)}, | ||
| msg="full should accept ObjectId (coerces to truthy)", | ||
| ), | ||
| DiagnosticTestCase( | ||
| "datetime", | ||
| command={"full": datetime(2024, 1, 1, tzinfo=timezone.utc)}, | ||
| checks={"ok": Eq(1.0)}, | ||
| msg="full should accept datetime (coerces to truthy)", | ||
| ), | ||
| DiagnosticTestCase( | ||
| "regex", | ||
| command={"full": Regex(".*")}, | ||
| checks={"ok": Eq(1.0)}, | ||
| msg="full should accept Regex (coerces to truthy)", | ||
| ), | ||
| DiagnosticTestCase( | ||
| "timestamp", | ||
| command={"full": Timestamp(0, 0)}, | ||
| checks={"ok": Eq(1.0)}, | ||
| msg="full should accept Timestamp (coerces to truthy)", | ||
| ), | ||
| DiagnosticTestCase( | ||
| "code", | ||
| command={"full": Code("function(){}")}, | ||
| checks={"ok": Eq(1.0)}, | ||
| msg="full should accept JavaScript Code (coerces to truthy)", | ||
| ), | ||
| DiagnosticTestCase( | ||
| "minkey", | ||
| command={"full": MinKey()}, | ||
| checks={"ok": Eq(1.0)}, | ||
| msg="full should accept MinKey (coerces to truthy)", | ||
| ), | ||
| DiagnosticTestCase( | ||
| "maxkey", | ||
| command={"full": MaxKey()}, | ||
| checks={"ok": Eq(1.0)}, | ||
| msg="full should accept MaxKey (coerces to truthy)", | ||
| ), | ||
| ] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("test", pytest_params(ACCEPTED_TYPE_TESTS)) | ||
| def test_validate_full_accepted_types(collection, test): | ||
| """Test that validate accepts all BSON types for the full parameter.""" | ||
| collection.insert_one({"_id": 1}) | ||
| result = execute_command( | ||
| collection, | ||
| {"validate": collection.name, **test.command}, | ||
| ) | ||
| assertProperties(result, test.checks, msg=test.msg, raw_res=True) | ||
50 changes: 50 additions & 0 deletions
50
...lity/tests/system/diagnostic/commands/validate/test_validate_checkBSONConformance_type.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,50 @@ | ||
| """Wiring tests for validate command 'checkBSONConformance' parameter type coercion. | ||
|
|
||
| Confirms checkBSONConformance uses the same boolean coercion as other params. | ||
| The full BSON type matrix is in test_validate_bool_param_coercion.py. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| 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_command | ||
| from documentdb_tests.framework.parametrize import pytest_params | ||
| from documentdb_tests.framework.property_checks import Eq | ||
|
|
||
| # Property [Type Coercion Wiring]: checkBSONConformance delegates to shared boolean coercion. | ||
| WIRING_TESTS: list[DiagnosticTestCase] = [ | ||
| DiagnosticTestCase( | ||
| "bool_true", | ||
| command={"checkBSONConformance": True}, | ||
| checks={"ok": Eq(1.0)}, | ||
| msg="checkBSONConformance should accept bool true", | ||
| ), | ||
| DiagnosticTestCase( | ||
| "int32_0", | ||
| command={"checkBSONConformance": 0}, | ||
| checks={"ok": Eq(1.0)}, | ||
| msg="checkBSONConformance should accept int32 0 (coerces to false)", | ||
| ), | ||
| DiagnosticTestCase( | ||
| "string", | ||
| command={"checkBSONConformance": "true"}, | ||
| checks={"ok": Eq(1.0)}, | ||
| msg="checkBSONConformance should accept string (coerces to truthy)", | ||
| ), | ||
| ] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("test", pytest_params(WIRING_TESTS)) | ||
| def test_validate_checkBSONConformance_accepted_types(collection, test): | ||
| """Test that checkBSONConformance uses shared boolean coercion.""" | ||
| collection.insert_one({"_id": 1}) | ||
| result = execute_command( | ||
| collection, | ||
| {"validate": collection.name, **test.command}, | ||
| ) | ||
| assertProperties(result, test.checks, msg=test.msg, raw_res=True) |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟠 [Major] The per-parameter coercion files are enormous and partly redundant against §20's canonical matrix. Five files (full, metadata, checkBSONConformance, repair, fixMultikey) each test the same ~21-type coercion matrix (~105 near-identical cases). Per TEST_COVERAGE.md §20, boolean-param coercion should mirror the canonical matrix (bypassDocumentValidation), but it
doesn't require re-testing all 21 BSON types five times for one command — the coercion logic is shared across these boolean params. Consider collapsing to one representative coercion matrix plus per-param confirmation that each is wired to it (a few cases each). As written this is a lot of duplicated surface for one behavior; TEST_FORMAT.md "don't ask for exhaustive
BSON matrix on simple shared params" cuts toward trimming.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed the exhaustive tests