port-sdk 0.1.0

Rust SDK for Port APIs.
Documentation
# Testing Strategy

Reliable HTTP clients demand layered testing. Use this guide to shape the test suite as the SDK matures.

## Unit Tests

Scope: individual functions or small modules.

- Mock `reqwest::Client` interactions with tools like [`wiremock-rs`]https://crates.io/crates/wiremock or by injecting a trait-based HTTP adapter.
- Validate serialization/deserialization using sample JSON payloads from the Swagger spec.
- Cover error conversion logic (e.g., ensure non-2xx responses become `PortError::Api`).

## Integration Tests

Scope: multiple modules working together.

- Spin up a local mock server that mimics Port endpoints; fixture responses should live under `tests/fixtures/`.
- Verify high-level workflows (e.g., create entity, fetch entity, delete entity) using real request/response shapes.
- Guard these tests behind a feature flag (e.g., `--features integration-tests`) if they rely on external resources.
- Set `PORT_RUN_CONTRACT_TESTS=1` to opt into live contract checks defined in `tests/contract_tests.rs`.

## Contract / Smoke Tests

Scope: optional tests hitting the real Port API (if credentials are available).

- Run only in CI environments with secure secret management.
- Use read-only tokens where possible.
- Keep them out of the default test suite to avoid failures for contributors without credentials.

## Property-Based Tests

- For reusable utilities (pagination builders, query parameter encoders), use `proptest` to exercise edge cases.

## Security Tests

- Add regression tests for any discovered security bugs (e.g., headers being logged, tokens leaked).
- Consider fuzzing input parsers to catch malformed payload handling issues.
- Use the built-in `ResourceTracker` to record create/update/delete flows in integration tests and ensure teardown logic leaves no dangling data.

## Coverage Tracking

- Collect coverage with `cargo tarpaulin` or `grcov` to ensure critical paths stay exercised.
- Aim for high coverage on error handling paths, not just happy flows.
- Use `scripts/coverage.sh` for a repeatable tarpaulin invocation.

## Continuous Integration

Recommended CI steps:

1. `cargo fmt --all -- --check`
2. `cargo clippy --all-targets --all-features -- -D warnings`
3. `cargo test --all-features`
4. Optional: integration tests behind `INCLUDE_INTEGRATION_TESTS=1`.
5. `cargo doc --no-deps`
6. `cargo audit`

Keep CI fast by caching dependencies and reusing the compiled target directory.