Classify invalid delivery destinations during preflight
This commit is contained in:
53
delivery_destination_test.go
Normal file
53
delivery_destination_test.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package releasekit_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
releasekit "go.maximumdirect.net/releasekit"
|
||||
)
|
||||
|
||||
func TestInvalidDestinationFailsStandaloneAndAutomaticPreflight(t *testing.T) {
|
||||
repository := newTaggedDeliveryConsumer(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()
|
||||
for _, test := range []struct {
|
||||
name, setting string
|
||||
change func(*releasekit.DeliveryDestination)
|
||||
}{
|
||||
{"URL", "base URL", func(d *releasekit.DeliveryDestination) { d.BaseURL = "ssh://forge.example" }},
|
||||
{"owner", "owner", func(d *releasekit.DeliveryDestination) { d.Owner = "owner/child" }},
|
||||
{"repository", "repository", func(d *releasekit.DeliveryDestination) { d.Repository = "repo/child" }},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
destination := facadeDeliveryDestination(server.URL)
|
||||
test.change(&destination)
|
||||
assertFailure := func(err error) {
|
||||
t.Helper()
|
||||
var preflight *releasekit.DeliveryPreflightError
|
||||
if !errors.As(err, &preflight) || preflight.Kind != releasekit.DeliveryPreflightInvalidDestination || preflight.Err == nil {
|
||||
t.Fatalf("error = %#v, want invalid destination with cause", err)
|
||||
}
|
||||
if !strings.Contains(err.Error(), test.setting) {
|
||||
t.Fatalf("error = %v, want invalid setting %q", err, test.setting)
|
||||
}
|
||||
}
|
||||
assertFailure(releasekit.PreflightDelivery(context.Background(), destination))
|
||||
result, err := releasekit.Deliver(context.Background(), releasekit.DeliveryRequest{
|
||||
RepositoryDir: repository, Product: "Fixture", Version: "v1.2.3", Destination: destination,
|
||||
Build: &releasekit.BuildSpec{MainPackage: "./missing", BinaryName: "fixture", Targets: []releasekit.Target{{OS: "linux", Arch: "amd64"}}},
|
||||
})
|
||||
assertFailure(err)
|
||||
if result.State != releasekit.DeliveryNotAttempted {
|
||||
t.Fatalf("delivery state = %s, want not attempted", result.State)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user