test: raise coverage on teslasync CLI, backup, schema, chaos-runner - #122
atulmgupta wants to merge 1 commit into
Conversation
Add high-value unit tests for previously thin packages: teslasync drain/healthcheck, local backup storage + restore, schema fingerprint Compute, backupverify VerifyLatest, audit recorder helpers, and chaos-runner recovery probes. Preserve the last concrete recovery failure instead of overwriting it with a later deadline. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 5b104204-65b7-4d04-90a4-e2d5897b8e2e
There was a problem hiding this comment.
🟡 Changes recommended
Several new tests depend on fixed host ports or call t.Fatalf from HTTP handler goroutines, and schema iterator-error paths remain untested.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Adds targeted Go test coverage across CLI, backup, schema, audit, and chaos-runner packages, plus improves recovery-probe error reporting.
Changes:
- Adds storage, restore, verification, schema, audit, and CLI tests.
- Preserves concrete recovery failures when retry deadlines are reached.
- Adds fleet-state and battery recovery-probe tests.
Verification was not run in this review environment.
File summaries
| File | Description |
|---|---|
internal/schemacheck/compute_test.go |
Fingerprint, exclusion, scan, and query-error tests |
internal/backupverify/verify_latest_test.go |
Backup verification success and failure cases |
internal/backup/storage_test.go |
Provider, storage, checksum, gzip, and allowlist tests |
internal/audit/recorder_more_test.go |
Additional recorder and redaction coverage |
cmd/teslasync/main_test.go |
Logger, healthcheck, drain, and subcommand tests |
cmd/chaos-runner/main.go |
Retains concrete recovery failures |
cmd/chaos-runner/main_test.go |
Recovery and fleet/battery probe tests |
Review details
Suppressed comments (1)
cmd/chaos-runner/main_test.go:433
- This path assertion is also executed in the
httptestserver goroutine, sot.Fatalfcan stop only that goroutine instead of the test. Report the mismatch withoutFailNow, or move the assertion after the request returns.
t.Fatalf("path=%s", r.URL.Path)
- Files reviewed: 7/7 changed files
- Comments generated: 4
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| t.Parallel() | ||
| srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| if r.URL.Path != "/api/v1/vehicles/states" { | ||
| t.Fatalf("path=%s", r.URL.Path) |
| t.Setenv("TESLASYNC_PORT", "") | ||
| // Exercise the empty-env branch. A local docker stack may already | ||
| // be serving :8080, so either 0 or 1 is acceptable. | ||
| _ = healthcheck() |
|
|
||
| func TestDrain_DefaultPortWhenUnset(t *testing.T) { | ||
| t.Setenv("TESLASYNC_DRAIN_PORT", "") | ||
| if code := drain(); code != 1 { |
| func TestCompute_ScanAndIterErrors(t *testing.T) { | ||
| t.Parallel() | ||
| if _, err := Compute(context.Background(), &scriptedQuerier{ | ||
| tables: &fakeRows{data: [][]any{{"vehicles"}}, scanErr: errors.New("scan tables")}, | ||
| }, nil); err == nil { | ||
| t.Fatal("want table scan error") | ||
| } | ||
| if _, err := Compute(context.Background(), &scriptedQuerier{ | ||
| tables: &fakeRows{data: [][]any{{"vehicles"}}}, | ||
| columns: &fakeRows{data: [][]any{{"vehicles", "id", "bigint", "NO"}}, scanErr: errors.New("scan cols")}, | ||
| }, nil); err == nil { | ||
| t.Fatal("want column scan error") | ||
| } | ||
| if _, err := Compute(context.Background(), &scriptedQuerier{ | ||
| tables: &fakeRows{data: [][]any{{"vehicles"}}}, | ||
| columns: &fakeRows{data: [][]any{{"vehicles", "id", "bigint", "NO"}}}, | ||
| indexes: &fakeRows{data: [][]any{{"vehicles", "idx", "CREATE INDEX"}}, scanErr: errors.New("scan idx")}, | ||
| }, nil); err == nil { | ||
| t.Fatal("want index scan error") | ||
| } | ||
| } |
|
One or more custom setup steps configured for this repository failed during this Copilot code review run: Setup steps run before each review. If the review above is missing context, or no review was posted at all, the failing step above may be the cause. See the workflow run for failure details, fix your setup steps configuration, and re-request a review. Note You can configure setup steps for Copilot code review separately from Copilot cloud agent with a |
|
Superseded by #130, which consolidated this PR and has now been merged. |
What
Adds high-value unit tests for previously thin Go packages and a chaos-runner recovery-probe fix.
Coverage deltas (package-level, local)
cmd/teslasync: 0% → 50% (drain, healthcheck, logger, subcommands)internal/backup: 1.3% → 39.5% (local storage round-trip, restore/gzip, provider init)internal/schemacheck: 1.5% → 100% (Compute fingerprint + exclude + error paths)internal/backupverify: 20.9% → 100% (VerifyLatest success and invariant failures)internal/audit: extra redactor/category/nil-receiver coveragecmd/chaos-runner: recovery probe keeps last concrete failure (e.g. HTTP 503) instead of overwriting with deadline; fleet/battery recovery testsNot yet 90% repo-wide
CI backend total was ~56.5% with 331 packages below 90%. This PR is the first slice of that work, not the finish line. Remaining gaps are mostly DB-backed handlers/repos and
main()wiring.How to test
go test ./cmd/teslasync ./internal/backup ./internal/schemacheck ./internal/backupverify ./internal/audit ./cmd/chaos-runner -count=1docker compose buildsucceeded.Notes
Local Docker used
WEB_PORT=3119.