test: provider-not-found and missing-blob download error branches
This commit is contained in:
@@ -558,6 +558,52 @@ func TestServerProxyErrors(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestServerLocalMissingBlob(t *testing.T) {
|
||||||
|
requireStack(t)
|
||||||
|
req(t, "POST", "/api/v2/remotes", `{"name":"srv-ghost","package_type":"generic","repo_type":"local"}`)
|
||||||
|
defer req(t, "DELETE", "/api/v2/remotes/srv-ghost", "")
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
// A local file whose blob object is absent from the store.
|
||||||
|
testSrv.db.UpsertBlob(ctx, "sha256:ghost", "blobs/sha256/ghost-missing", 5, "text/plain")
|
||||||
|
if err := testSrv.db.CreateLocalFile(ctx, "srv-ghost", "ghost.bin", "sha256:ghost"); err != nil {
|
||||||
|
t.Fatalf("create local file: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp, _ := req(t, "GET", "/api/v1/local/srv-ghost/ghost.bin", ""); resp.StatusCode != 500 {
|
||||||
|
t.Errorf("v1 download missing blob = %d, want 500", resp.StatusCode)
|
||||||
|
}
|
||||||
|
if resp, _ := req(t, "GET", "/api/v2/remotes/srv-ghost/files/ghost.bin", ""); resp.StatusCode != 500 {
|
||||||
|
t.Errorf("v2 download missing blob = %d, want 500", resp.StatusCode)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestServerBogusProviderType(t *testing.T) {
|
||||||
|
requireStack(t)
|
||||||
|
// Insert a remote with an unregistered package type directly, bypassing
|
||||||
|
// validation, to exercise the provider-not-found branches.
|
||||||
|
_, err := testSrv.db.Pool.Exec(context.Background(),
|
||||||
|
`INSERT INTO remotes (name, package_type, repo_type, base_url) VALUES ($1,'bogus','remote','https://x')`, "srv-bogus")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("insert bogus remote: %v", err)
|
||||||
|
}
|
||||||
|
defer testSrv.db.Pool.Exec(context.Background(), `DELETE FROM remotes WHERE name='srv-bogus'`)
|
||||||
|
|
||||||
|
if resp, _ := req(t, "GET", "/api/v1/remote/srv-bogus/x", ""); resp.StatusCode != 500 {
|
||||||
|
t.Errorf("bogus provider GET = %d, want 500", resp.StatusCode)
|
||||||
|
}
|
||||||
|
rq, _ := http.NewRequest("HEAD", testTS.URL+"/v2/srv-bogus/x", nil)
|
||||||
|
if resp, err := http.DefaultClient.Do(rq); err == nil {
|
||||||
|
resp.Body.Close()
|
||||||
|
if resp.StatusCode != 500 {
|
||||||
|
t.Errorf("bogus provider HEAD = %d, want 500", resp.StatusCode)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if resp, b := req(t, "POST", "/api/v2/probe", `{"remote":"srv-bogus","path":"x"}`); resp.StatusCode != 200 || !strings.Contains(string(b), `"status":500`) {
|
||||||
|
t.Errorf("bogus provider probe: %d %s", resp.StatusCode, b)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestServerNotFound(t *testing.T) {
|
func TestServerNotFound(t *testing.T) {
|
||||||
requireStack(t)
|
requireStack(t)
|
||||||
if resp, _ := req(t, "GET", "/api/v2/remotes/does-not-exist", ""); resp.StatusCode != 404 {
|
if resp, _ := req(t, "GET", "/api/v2/remotes/does-not-exist", ""); resp.StatusCode != 404 {
|
||||||
@@ -566,4 +612,8 @@ func TestServerNotFound(t *testing.T) {
|
|||||||
if resp, _ := req(t, "GET", "/api/v1/remote/nope/x", ""); resp.StatusCode != 404 {
|
if resp, _ := req(t, "GET", "/api/v1/remote/nope/x", ""); resp.StatusCode != 404 {
|
||||||
t.Errorf("expected 404 for unknown remote, got %d", resp.StatusCode)
|
t.Errorf("expected 404 for unknown remote, got %d", resp.StatusCode)
|
||||||
}
|
}
|
||||||
|
// Unknown local repo -> 404 in handleLocal.
|
||||||
|
if resp, _ := req(t, "GET", "/api/v1/local/nope/x", ""); resp.StatusCode != 404 {
|
||||||
|
t.Errorf("expected 404 for unknown local repo, got %d", resp.StatusCode)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user