test(analytics-api): unit tests for pure-logic modules (threshold/query/metric/config)#1333
test(analytics-api): unit tests for pure-logic modules (threshold/query/metric/config)#1333SharedQA wants to merge 8 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughAdds ChangesAnalytics API Unit Test Coverage
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…e logic threshold.rs (0%): operator matching incl. negative/unknown-operator cases. query.rs: OData $-param mapping + defaults + batch flatten + lowercase status tag. metric.rs: triple-state PATCH deserializer (absent/null/value) + summary never leaks SQL. config.rs: figment defaults + required-field-missing error. Expected values derived from documented intent (OData semantics, the PATCH-state comment, default fns) — not from running the code — except threshold eq, whose f64::EPSILON behaviour is characterised + flagged separately as semantically suspect (magnitude-dependent equality). 19 tests; analytics-api 257 pass; clippy clean. Signed-off-by: Kenan Salim <kenan.salim@rolos.com>
a85b3d9 to
7c4b483
Compare
…values Addresses review (cyberantonz): the serialization tests built a struct and then asserted the value just set was present in the JSON — that tests serde, not our code. Replaced with tests that each guard a real, non-obvious invariant: - none_description_is_omitted_not_null: skip_serializing_if omits None (the FE distinguishes absent from null — the other half of the triple-state contract). - metric_summary_never_serializes_query_ref: security — the list/summary shape must never carry raw SQL; fires if anyone adds the field. - create_request_requires_name_and_query_ref: required-field contract — a payload missing either is rejected at deserialization, not silently defaulted. update_description_is_triple_state (the Option<Option> PATCH test) kept as-is. Verified: cargo test -p analytics-api passes; clippy -D warnings clean. Signed-off-by: Kenan Salim <ks@constructor.tech>
…gic ones Addresses cyberantonz's review across the module: tests must be able to fail for a reason about OUR code, not serde / a constant / an absent field. Removed (tested the framework, not us): - metric.rs: the serialize-and-find-the-value tests, the 'summary has no query_ref' test (the struct has no such field), the required-field test (serde behavior). Kept update_description_is_triple_state — it exercises our custom deserialize_optional_nullable (absent/null/value), which serde can't express. - query.rs: default_top_is_25 (asserting a fn returns its own literal). The default stays covered by applies_defaults_when_empty, which proves the field is wired to default_top() through real deserialization. - config.rs: default_helpers + applies_defaults_for_optional_fields (asserting defaults equal their literals). Kept explicit_values_override_defaults (layering precedence) and missing_required_field_errors (fail-fast on misconfig). Kept in query.rs: the OData $top/$filter rename mapping, serde(flatten) batch shape, and lowercase status tag — these guard the external wire contract the FE depends on (a rename silently breaks it), not 'serde works'. Verified: cargo test -p analytics-api passes; clippy -D warnings clean. Signed-off-by: Kenan Salim <ks@constructor.tech>
|
Already covered with unit tests coverage |
Raises analytics-api unit coverage on the pure-logic modules (the part that doesn't need a DB/runtime).
Measured (cargo-llvm-cov, instrumented)
threshold.rs0% → covered;query.rs/metric.rs/config.rsraised.clippy --all-targetsclean (no unwrap/expect in tests).Test validity
Expected values are derived from documented intent — OData semantics, the in-code PATCH triple-state comment, the
default_*fns — not from running the code. Negative/boundary cases included (unknown operator, missing required config, null-vs-absent PATCH, empty/oversized inputs).One unit was found semantically suspect during review and flagged rather than locked in:
threshold_matches'sequsesf64::EPSILON(magnitude-dependent equality) — see #1332. The test characterises current behaviour; the issue asks for the intended rule.Coverage ceiling
Further unit gains are limited: the remaining uncovered analytics-api/oidc/clickhouse code is runtime/IO (
validate_tokenneeds JWKS, DB clients need ClickHouse/MariaDB,main/module wiring need the modkit runtime). Reaching ~80% requires the instrumented e2e profile (the rig running instrumented binaries — milestone 2.15), not more unit tests.Related correctness findings from this pass: #1330 (duplicate/unstable data), #1331 (time formats), #1332 (threshold eq).
Summary by CodeRabbit