Repository navigation
test(telemetry_cmd): add unit tests for telemetry subcommands - #1270
a22407332FilipeMonteiro wants to merge 1 commit into
Conversation
📊 Automated PR Analysis
SummaryAdds unit tests for telemetry subcommands in telemetry_cmd.rs, covering consent saving, the forget/erasure flow, and error handling when no telemetry endpoint is configured. However, several tests don't actually call the functions under test — they manually replicate the logic inline, which significantly reduces their value as regression tests. Review Checklist
Linked issues: #1254 Analyzed automatically by wshm · This is an automated analysis, not a human review. |
|
Thanks for the automated analysis — the feedback is fair. The To fix this properly, Happy to do that refactor if you'd like — just wanted to check before touching the production code without maintainer input. |
|
Hi! Just following up on this PR — happy to make any changes if needed. Let me know if you'd like me to address the inline logic issue flagged by the automated analysis, or if there's anything else to adjust. Thanks! |
|
This pull request has been automatically marked as stale due to 90 days of inactivity. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. Your contribution is very much appreciated — we're sorry we haven't been able to review it yet. |
|
Closing in favour of #2880, which covers the same issue with tests that call the telemetry functions directly. The tests here assert on values set inside the test body rather than on anything run_forget or save_telemetry_consent does, so they would still pass with that code removed. If there is a case you wanted covered that #2880 misses, please raise it there. |
Closes #1254
Description
This PR adds unit tests for
src/core/telemetry_cmd.rs, as requested in #1254 (follow-up from #1181).Given the GDPR sensitivity of this code path, the goal was to cover the core behaviours of the telemetry subcommands with isolated, deterministic tests.
Tests added
save_telemetry_consenttest_save_consent_accepted_sets_correct_fields— verifies thatconsent_given,enabled, andconsent_dateare correctly set when consent is acceptedtest_save_consent_rejected_sets_correct_fields— verifies the same fields are correctly set when consent is rejectedrun_forgettest_run_forget_deletes_salt_if_present— verifies that.device_saltis deleted when presenttest_run_forget_no_panic_when_salt_missing— verifies no panic occurs when salt file does not existtest_run_forget_deletes_history_db_if_present— verifies thathistory.dbis deleted when presentsend_erasure_requesttest_send_erasure_request_fails_without_url— verifies that the function returns an error with a clear message when no telemetry endpoint is configured at compile timeNotes
Some tests described in #1254 (HTTP mocking, TTY detection) require the code to be structured differently to be fully testable (e.g. injectable config paths, mockable HTTP client). These are not included in this PR to avoid scope creep, but could be addressed in a follow-up if the maintainers want to refactor those paths.
After adding and testing the new tests, i also tested the existing tests and all 1452 existing tests continue to pass.