test: raise core-package unit coverage to 90% #98

Merged
benvin merged 25 commits from benvin/unit-coverage-90 into master 2026-07-03 14:31:25 +10:00
Owner

Raises statement coverage of the core packages (all of internal/ except the interactive tui/, plus pkg/) from 8.7% to 90.1%.

Approach

  • Pure-go unit tests for all providers, virtual mergers, classifier, config, auth, models, and the API client (httptest).
  • Testcontainers-backed tests (new internal/testsupport helper: Postgres/Redis/MinIO, Ryuk disabled) for database, storage, cache, the proxy engine, the GC, and a full-stack server test that drives the whole HTTP API. These t.Skip when Docker is absent so go test still runs locally without it.

Measuring

go test -coverpkg=./internal/...,./pkg/... -coverprofile=cover.out ./internal/... ./pkg/...
grep -v /internal/tui/ cover.out | go tool cover -func=/dev/stdin | tail -1   # 90.1%

Run with -p 1 (containers are heavy).

Notes

  • The interactive tui/ package and cmd/main are excluded from the target per the agreed scope.
  • Some defensive error branches are covered via fault injection (closed DB pool, killing MinIO mid-upload).
Raises statement coverage of the core packages (all of `internal/` except the interactive `tui/`, plus `pkg/`) from **8.7% to 90.1%**. ## Approach - **Pure-go unit tests** for all providers, virtual mergers, classifier, config, auth, models, and the API client (httptest). - **Testcontainers-backed** tests (new `internal/testsupport` helper: Postgres/Redis/MinIO, Ryuk disabled) for database, storage, cache, the proxy engine, the GC, and a full-stack `server` test that drives the whole HTTP API. These `t.Skip` when Docker is absent so `go test` still runs locally without it. ## Measuring ``` go test -coverpkg=./internal/...,./pkg/... -coverprofile=cover.out ./internal/... ./pkg/... grep -v /internal/tui/ cover.out | go tool cover -func=/dev/stdin | tail -1 # 90.1% ``` Run with `-p 1` (containers are heavy). ## Notes - The interactive `tui/` package and `cmd/main` are excluded from the target per the agreed scope. - Some defensive error branches are covered via fault injection (closed DB pool, killing MinIO mid-upload).
unkinben added 24 commits 2026-07-03 13:57:34 +10:00
First increment toward 90% core-package coverage. Adds Docker-free unit
tests taking these packages to full or near-full coverage:
- provider/npm, provider/alpine, provider/puppet: 100%
- provider/pypi: index generation via a fake FileStore, upload validation,
  name parsing, classification, rewrite
- config: defaults, overrides, DSN, invalid port
- auth: basic header with/without credentials

Infra-backed packages (database, storage, cache, proxy engine, api
handlers, server) still need the testcontainers batch to reach 90%.
rpm 2.7% -> 83.6%, pure-go via a real RPM testdata fixture and fake
BlobReader/MetadataStore/RPMMetadataReader implementations.
virtual mergers (helm/pypi merge, dedup, URL rewriting, registry) and the
API client (all endpoints via httptest, error/decode paths). pkg/client
0->96%, virtual 49->57%.
Add internal/testsupport (Postgres/Redis/MinIO container helpers, Ryuk
disabled) and full database coverage: remotes, artifacts/blobs, local
files, virtuals, stats, rpm metadata, orphan/cold cleanup. database
0->83%.
storage 0->79%, cache 0->92%, via the testsupport container harness.
Drives the whole HTTP API against real Postgres/Redis/MinIO + a mock
upstream: health, remote CRUD, proxy miss/hit, local upload/download,
virtual helm merge, objects, stats, probe. Exercises server + api/v1 +
api/v2 + proxy + virtual engines together.
Cover denied, HEAD (cached/uncached/denied), stale-on-error, circuit-open,
and mutable revalidation (304) paths. proxy ~8->58%.
test: database closed-db error paths + pure goproxy/generic/helm/repotype gaps
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/test Pipeline failed
1009bc7c69
unkinben added 23 commits 2026-07-03 13:57:48 +10:00
rpm 2.7% -> 83.6%, pure-go via a real RPM testdata fixture and fake
BlobReader/MetadataStore/RPMMetadataReader implementations.
virtual mergers (helm/pypi merge, dedup, URL rewriting, registry) and the
API client (all endpoints via httptest, error/decode paths). pkg/client
0->96%, virtual 49->57%.
Add internal/testsupport (Postgres/Redis/MinIO container helpers, Ryuk
disabled) and full database coverage: remotes, artifacts/blobs, local
files, virtuals, stats, rpm metadata, orphan/cold cleanup. database
0->83%.
storage 0->79%, cache 0->92%, via the testsupport container harness.
Drives the whole HTTP API against real Postgres/Redis/MinIO + a mock
upstream: health, remote CRUD, proxy miss/hit, local upload/download,
virtual helm merge, objects, stats, probe. Exercises server + api/v1 +
api/v2 + proxy + virtual engines together.
Cover denied, HEAD (cached/uncached/denied), stale-on-error, circuit-open,
and mutable revalidation (304) paths. proxy ~8->58%.
test: database closed-db error paths + pure goproxy/generic/helm/repotype gaps
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/test Pipeline failed
1009bc7c69
unkinben added 1 commit 2026-07-03 14:25:33 +10:00
test: generate a minimal RPM in pure Go instead of a committed fixture
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/build Pipeline was successful
35719984e6
Removes the committed .rpm binary (gitignored, so it broke clean checkouts)
and the rpmbuild dependency. testsupport.MinimalRPM builds a valid-enough
RPM header in-memory for cavaliergopher/rpm to parse, used by both the rpm
provider test and the full-stack server repodata test.
benvin merged commit a1ba86e76b into master 2026-07-03 14:31:25 +10:00
benvin deleted branch benvin/unit-coverage-90 2026-07-03 14:31:25 +10:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: unkin/artifactapi#98