a1ba86e76b
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). Reviewed-on: #98 Co-authored-by: Ben Vincent <ben@unkin.net> Co-committed-by: Ben Vincent <ben@unkin.net>
61 lines
1.6 KiB
Go
61 lines
1.6 KiB
Go
package alpine
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"git.unkin.net/unkin/artifactapi/internal/provider"
|
|
"git.unkin.net/unkin/artifactapi/pkg/models"
|
|
)
|
|
|
|
func TestType(t *testing.T) {
|
|
if (&Provider{}).Type() != models.PackageAlpine {
|
|
t.Fatal("wrong type")
|
|
}
|
|
}
|
|
|
|
func TestClassify(t *testing.T) {
|
|
p := &Provider{}
|
|
if p.Classify("v3.19/main/x86_64/APKINDEX.tar.gz") != provider.Mutable {
|
|
t.Error("APKINDEX should be mutable")
|
|
}
|
|
if p.Classify("v3.19/main/x86_64/curl-8.0-r0.apk") != provider.Immutable {
|
|
t.Error("apk should be immutable")
|
|
}
|
|
}
|
|
|
|
func TestContentType(t *testing.T) {
|
|
p := &Provider{}
|
|
cases := map[string]string{
|
|
"pkg.apk": "application/vnd.android.package-archive",
|
|
"APKINDEX.tar.gz": "application/gzip",
|
|
"something.random": "application/octet-stream",
|
|
}
|
|
for path, want := range cases {
|
|
if got := p.ContentType(path); got != want {
|
|
t.Errorf("ContentType(%q) = %q, want %q", path, got, want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestUpstreamURL(t *testing.T) {
|
|
p := &Provider{}
|
|
got := p.UpstreamURL(models.Remote{BaseURL: "https://dl-cdn.alpinelinux.org/alpine/"}, "/v3.19/main/x86_64/curl.apk")
|
|
if got != "https://dl-cdn.alpinelinux.org/alpine/v3.19/main/x86_64/curl.apk" {
|
|
t.Errorf("got %q", got)
|
|
}
|
|
}
|
|
|
|
func TestRewriteResponse(t *testing.T) {
|
|
if out, err := (&Provider{}).RewriteResponse([]byte("x"), models.Remote{}, "http://proxy"); out != nil || err != nil {
|
|
t.Error("alpine never rewrites")
|
|
}
|
|
}
|
|
|
|
func TestAuthHeaders(t *testing.T) {
|
|
h, _ := (&Provider{}).AuthHeaders(context.Background(), models.Remote{Username: "u", Password: "p"})
|
|
if h.Get("Authorization") == "" {
|
|
t.Error("expected auth header")
|
|
}
|
|
}
|