Skip to content

test: cover schema-snapshot and validate-contract subcommands #37

@Pawansingh3889

Description

@Pawansingh3889

PR #35 added two new CLI subcommands and a sql_guard/snapshot.py module for SQLAlchemy introspection. Codecov flagged the patch at 63.95% because the new code is uncovered:

  • sql_guard/snapshot.py — 0% (66 lines). Needs a fixture engine (sqlite in-memory works for the introspection paths) or a mocked SQLAlchemy inspector.
  • sql_guard/cli.py — 0% on the new schema-snapshot and validate-contract handlers. Both can be exercised with typer.testing.CliRunner.

Suggested coverage

  1. tests/test_validate_contract_cli.py — call validate-contract against tests/fixtures/contract_sample.yml and assert exit code 0 plus the printed table/column counts. Then call it against a malformed YAML and assert non-zero exit.
  2. tests/test_snapshot.py — build a small sqlite schema in a tmp DB, run snapshot.introspect(), and assert the dataclass shape matches the contract format.
  3. tests/test_schema_snapshot_cli.py — same sqlite engine, exercised through CliRunner so the --dsn / --output / --schema / --include-table flag plumbing is covered too.

Bumps patch coverage on the contracts area to ~95%+

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions