Classify invalid delivery destinations during preflight
This commit is contained in:
64
cmd/releasekit/destination_test.go
Normal file
64
cmd/releasekit/destination_test.go
Normal file
@@ -0,0 +1,64 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"go.maximumdirect.net/releasekit/cmd/releasekit/internal/cli"
|
||||
)
|
||||
|
||||
func TestInvalidDeliveryDestinationStopsBeforePreparation(t *testing.T) {
|
||||
for _, command := range []string{"deliver", "ci-deliver"} {
|
||||
for _, setting := range []string{"URL", "owner", "repository"} {
|
||||
t.Run(command+"/"+setting, func(t *testing.T) {
|
||||
repository := newDeliveryBuildRepository(t)
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
t.Errorf("invalid destination made a hosted request: %s", r.URL.Path)
|
||||
http.Error(w, "unexpected request", http.StatusInternalServerError)
|
||||
}))
|
||||
defer server.Close()
|
||||
destination := &cli.DeliverySettings{Forge: "gitea", BaseURL: server.URL, Owner: "owner", Repository: "example", TokenEnv: "RELEASEKIT_TEST_DELIVERY_TOKEN"}
|
||||
switch setting {
|
||||
case "URL":
|
||||
destination.BaseURL = "ssh://forge.example"
|
||||
case "owner":
|
||||
destination.Owner = "owner/child"
|
||||
case "repository":
|
||||
destination.Repository = "repo/child"
|
||||
}
|
||||
writeDeliveryProfile(t, repository, cli.Settings{
|
||||
Product: "Example Product", Delivery: destination,
|
||||
Build: &cli.BuildSettings{MainPackage: ".", BinaryName: "helper", Targets: []string{"linux/amd64"}},
|
||||
})
|
||||
commit := pushTaggedCLIRepository(t, repository)
|
||||
t.Setenv("RELEASEKIT_TEST_DELIVERY_TOKEN", "fixture-token")
|
||||
shimDir := t.TempDir()
|
||||
marker := filepath.Join(shimDir, "go-invoked")
|
||||
if err := os.WriteFile(filepath.Join(shimDir, "go"), []byte("#!/bin/sh\n: > \"$RELEASEKIT_GO_MARKER\"\nexit 99\n"), 0o700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Setenv("RELEASEKIT_GO_MARKER", marker)
|
||||
t.Setenv("PATH", shimDir+string(os.PathListSeparator)+os.Getenv("PATH"))
|
||||
args := []string{command, "--repo", repository}
|
||||
if command == "ci-deliver" {
|
||||
args = append(args, "--prepared", "--commit", commit)
|
||||
}
|
||||
args = append(args, "v1.2.3")
|
||||
var stdout, stderr bytes.Buffer
|
||||
status := run(context.Background(), args, &stdout, &stderr)
|
||||
if status != 2 || !strings.Contains(stderr.String(), "invalid_destination") {
|
||||
t.Fatalf("status=%d stderr=%q, want destination configuration error", status, stderr.String())
|
||||
}
|
||||
if _, err := os.Stat(marker); !os.IsNotExist(err) {
|
||||
t.Fatalf("preparation/build ran for invalid destination: %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -446,7 +446,8 @@ func deliveryPreflightExitStatus(err error) int {
|
||||
return 1
|
||||
}
|
||||
switch preflightErr.Kind {
|
||||
case releasekit.DeliveryPreflightMissingCredential,
|
||||
case releasekit.DeliveryPreflightInvalidDestination,
|
||||
releasekit.DeliveryPreflightMissingCredential,
|
||||
releasekit.DeliveryPreflightInvalidCredential,
|
||||
releasekit.DeliveryPreflightInsufficientPermissions,
|
||||
releasekit.DeliveryPreflightInaccessibleDestination:
|
||||
|
||||
Reference in New Issue
Block a user