4c321a089d
- serve sparse index and config.json for local cargo repos from a cargo_index table - add Web API publish, yank and unyank under the local repo api root - drop index lines when the crate file is deleted
57 lines
2.2 KiB
Go
57 lines
2.2 KiB
Go
//go:build dockere2e
|
|
|
|
package e2edocker
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/binary"
|
|
"net/http"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// TestLocalCargoRegistry publishes through the cargo Web API, then reads the
|
|
// sparse index, downloads the crate and yanks it.
|
|
func TestLocalCargoRegistry(t *testing.T) {
|
|
createRepo(t, `{"name":"local-cargo","package_type":"cargo","repo_type":"local"}`)
|
|
defer deleteRepo(t, "local-cargo")
|
|
base := api("/api/v1/local/local-cargo")
|
|
|
|
meta := `{"name":"e2e-crate","vers":"0.1.0","deps":[],"features":{}}`
|
|
crate := []byte("e2e crate bytes")
|
|
var body []byte
|
|
body = binary.LittleEndian.AppendUint32(body, uint32(len(meta)))
|
|
body = append(body, meta...)
|
|
body = binary.LittleEndian.AppendUint32(body, uint32(len(crate)))
|
|
body = append(body, crate...)
|
|
|
|
if resp, b := doRequest(t, http.MethodPut, base+"/api/v1/crates/new", body, "application/octet-stream"); resp.StatusCode != http.StatusOK {
|
|
t.Fatalf("publish: status %d: %s", resp.StatusCode, b)
|
|
}
|
|
if resp, _ := doRequest(t, http.MethodPut, base+"/api/v1/crates/new", body, "application/octet-stream"); resp.StatusCode != http.StatusConflict {
|
|
t.Fatalf("republish: status %d, want 409", resp.StatusCode)
|
|
}
|
|
|
|
resp, b := doRequest(t, http.MethodGet, base+"/config.json", nil, "")
|
|
if resp.StatusCode != http.StatusOK || !strings.Contains(string(b), `"api":"`) {
|
|
t.Fatalf("config.json: status %d: %s", resp.StatusCode, b)
|
|
}
|
|
|
|
resp, b = doRequest(t, http.MethodGet, base+"/e2/e-/e2e-crate", nil, "")
|
|
if resp.StatusCode != http.StatusOK || !strings.Contains(string(b), `"cksum":"`) || !strings.Contains(string(b), `"yanked":false`) {
|
|
t.Fatalf("index: status %d: %s", resp.StatusCode, b)
|
|
}
|
|
|
|
resp, b = doRequest(t, http.MethodGet, base+"/crates/e2e-crate/e2e-crate-0.1.0.crate", nil, "")
|
|
if resp.StatusCode != http.StatusOK || !bytes.Equal(b, crate) {
|
|
t.Fatalf("download: status %d", resp.StatusCode)
|
|
}
|
|
|
|
if resp, b := doRequest(t, http.MethodDelete, base+"/api/v1/crates/e2e-crate/0.1.0/yank", nil, ""); resp.StatusCode != http.StatusOK {
|
|
t.Fatalf("yank: status %d: %s", resp.StatusCode, b)
|
|
}
|
|
if _, b := doRequest(t, http.MethodGet, base+"/e2/e-/e2e-crate", nil, ""); !strings.Contains(string(b), `"yanked":true`) {
|
|
t.Fatalf("index after yank: %s", b)
|
|
}
|
|
}
|