fix(depot): exit 64 on unset DEPOT_DIR, count push transport failures
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,7 @@ package depot
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -30,6 +31,19 @@ func TestRunUsage(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("status --target local without DEPOT_DIR", func(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
writeManifest(t, dir, shaOf("blob-a"), 5)
|
||||
var out, errb bytes.Buffer
|
||||
code := Run([]string{"status", "--manifests", dir, "--target", "local"}, &out, &errb, testGetenv(nil))
|
||||
if code != 64 {
|
||||
t.Fatalf("expected 64, got %d (stderr=%s)", code, errb.String())
|
||||
}
|
||||
if !bytesContains(errb.String(), "DEPOT_DIR") {
|
||||
t.Fatalf("expected stderr to mention DEPOT_DIR, got %s", errb.String())
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("push --target cdn rejected", func(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
var out, errb bytes.Buffer
|
||||
@@ -116,6 +130,43 @@ func TestStatusExitCodes(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestPushTransportErrorCountsFailed(t *testing.T) {
|
||||
// Probes 404 (blob absent), PUTs 500 (transport-level upload failure).
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == http.MethodPut {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
w.WriteHeader(404)
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
sha := shaOf("push-fail-blob")
|
||||
manifestsDir := t.TempDir()
|
||||
writeManifest(t, manifestsDir, sha, 14)
|
||||
sourceDir := t.TempDir()
|
||||
blobPath := filepath.Join(sourceDir, BlobKey(sha))
|
||||
if err := os.MkdirAll(filepath.Dir(blobPath), 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(blobPath, []byte("push-fail-blob"), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var out, errb bytes.Buffer
|
||||
code := Run([]string{"push", "--manifests", manifestsDir, "--source", sourceDir, "--target", "bunny"}, &out, &errb,
|
||||
testGetenv(map[string]string{
|
||||
"BUNNY_STORAGE_HOST": hostPort(srv),
|
||||
"BUNNY_STORAGE_PASSWORD": "writekey",
|
||||
}))
|
||||
if code != 70 {
|
||||
t.Fatalf("expected 70, got %d (stdout=%s stderr=%s)", code, out.String(), errb.String())
|
||||
}
|
||||
if !bytesContains(out.String(), "uploaded=0 failed=1") {
|
||||
t.Fatalf("expected uploaded=0 failed=1, got %s", out.String())
|
||||
}
|
||||
}
|
||||
|
||||
func bytesContains(s, substr string) bool {
|
||||
return bytes.Contains([]byte(s), []byte(substr))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user