Developer tools dump stack traces, exit codes, and jargon. Figuring out *what to do next* often means searching the same Stack Overflow answers again.
| 1 | """MongoDB rule tests.""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | import pytest |
| 6 | |
| 7 | from why_failed.matcher import analyze |
| 8 | |
| 9 | CASES = [ |
| 10 | ("Error: connect ECONNREFUSED 127.0.0.1:27017", "mongodb.connection_refused"), |
| 11 | ("MongoServerSelectionError: connect ECONNREFUSED", "mongodb.server_selection"), |
| 12 | ("MongoServerError: Authentication failed.", "mongodb.auth_failed"), |
| 13 | ("E11000 duplicate key error collection: db.users index: email_1", "mongodb.duplicate_key"), |
| 14 | ("MongoNetworkTimeoutError: connection timed out", "mongodb.connection_timeout"), |
| 15 | ] |
| 16 | |
| 17 | |
| 18 | @pytest.mark.parametrize("text,rule_id", CASES) |
| 19 | def test_mongodb_rules(text: str, rule_id: str) -> None: |
| 20 | result = analyze(text) |
| 21 | assert result.match is not None |
| 22 | assert result.match.rule_id == rule_id |