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

This commit is contained in:
2026-07-03 13:55:30 +10:00
parent 2ae12d9aef
commit 1009bc7c69
5 changed files with 134 additions and 1 deletions
@@ -0,0 +1,13 @@
package generic
import (
"testing"
"git.unkin.net/unkin/artifactapi/pkg/models"
)
func TestGenericRewriteResponse(t *testing.T) {
if out, err := (&Provider{}).RewriteResponse([]byte("x"), models.Remote{}, "http://p"); out != nil || err != nil {
t.Error("generic never rewrites")
}
}
@@ -0,0 +1,27 @@
package goproxy
import (
"context"
"testing"
"git.unkin.net/unkin/artifactapi/pkg/models"
)
func TestGoProxyURLAuthRewrite(t *testing.T) {
p := &Provider{}
if got := p.UpstreamURL(models.Remote{BaseURL: "https://proxy.golang.org/"}, "/mod/@v/list"); got != "https://proxy.golang.org/mod/@v/list" {
t.Errorf("upstream url %q", got)
}
if out, err := p.RewriteResponse([]byte("x"), models.Remote{}, "http://p"); out != nil || err != nil {
t.Error("goproxy never rewrites")
}
if h, _ := p.AuthHeaders(context.Background(), models.Remote{Username: "u", Password: "p"}); h.Get("Authorization") == "" {
t.Error("expected basic auth header")
}
if got := p.ContentType("mod/@v/v1.0.0.info"); got != "application/json" {
t.Errorf("info content type %q", got)
}
if got := p.ContentType("mod/@v/v1.0.0.mod"); got != "text/plain" {
t.Errorf("mod content type %q", got)
}
}
+18
View File
@@ -0,0 +1,18 @@
package helm
import "testing"
func TestHelmContentTypeBranches(t *testing.T) {
p := &Provider{}
for path, want := range map[string]string{
"charts/x-1.0.0.tgz": "application/gzip",
"x.tar.gz": "application/gzip",
"index.yaml": "text/yaml",
"x.yml": "text/yaml",
"other": "application/octet-stream",
} {
if got := p.ContentType(path); got != want {
t.Errorf("ContentType(%q)=%q want %q", path, got, want)
}
}
}