Distinguish asset read failures from unknown writes
This commit is contained in:
@@ -423,18 +423,19 @@ func writeDeliveryReceipt(t *testing.T, repository string, settings cli.BuildSet
|
||||
}
|
||||
|
||||
type deliveryServerState struct {
|
||||
malformedCreate bool
|
||||
failAssetListing bool
|
||||
commit string
|
||||
product string
|
||||
remoteCommit string
|
||||
apiRequests int
|
||||
pageExists bool
|
||||
releaseCreates int
|
||||
assetUploads int
|
||||
assetListReads int
|
||||
noteBody string
|
||||
assets map[string][]byte
|
||||
malformedCreate bool
|
||||
failAssetListing bool
|
||||
failAssetDownloads bool
|
||||
commit string
|
||||
product string
|
||||
remoteCommit string
|
||||
apiRequests int
|
||||
pageExists bool
|
||||
releaseCreates int
|
||||
assetUploads int
|
||||
assetListReads int
|
||||
noteBody string
|
||||
assets map[string][]byte
|
||||
}
|
||||
|
||||
func newDeliveryServer(t *testing.T, state *deliveryServerState) *httptest.Server {
|
||||
@@ -530,6 +531,10 @@ func newDeliveryServer(t *testing.T, state *deliveryServerState) *httptest.Serve
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{"id": state.assetUploads, "name": name, "size": len(content)})
|
||||
default:
|
||||
if strings.HasPrefix(r.URL.Path, "/files/") {
|
||||
if state.failAssetDownloads {
|
||||
http.Error(w, "unavailable", 503)
|
||||
return
|
||||
}
|
||||
name := strings.TrimPrefix(r.URL.Path, "/files/")
|
||||
content, ok := state.assets[name]
|
||||
if !ok {
|
||||
@@ -704,3 +709,31 @@ func TestRecoveredPageCreatePreservesPartialDeliveryOnInspectionFailure(t *testi
|
||||
t.Fatalf("status=%d state=%#v %s", status, state, stderr.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnreadableAssetsDoNotClaimAnUnknownWrite(t *testing.T) {
|
||||
for _, existingPage := range []bool{false, true} {
|
||||
t.Run(fmt.Sprintf("existing-page-%t", existingPage), func(t *testing.T) {
|
||||
repository := newCLIRepository(t)
|
||||
state := &deliveryServerState{pageExists: existingPage, noteBody: "# Example Product v1.2.3\n\nRelease note.\n", failAssetDownloads: true, assets: map[string][]byte{"helper-v1.2.3-linux-amd64": []byte("fixture artifact")}}
|
||||
server := newDeliveryServer(t, state)
|
||||
defer server.Close()
|
||||
build := cli.BuildSettings{MainPackage: ".", BinaryName: "helper", Targets: []string{"linux/amd64"}}
|
||||
writeDeliveryProfile(t, repository, cli.Settings{Product: "Example Product", Build: &build, Delivery: &cli.DeliverySettings{BaseURL: server.URL, Owner: "owner", Repository: "example"}})
|
||||
state.commit = cliGitOutput(t, repository, "rev-parse", "HEAD")
|
||||
cliGitRun(t, repository, "tag", "v1.2.3")
|
||||
assets, _ := writeDeliveryReceipt(t, repository, build)
|
||||
t.Setenv("RELEASEKIT_GITEA_TOKEN", "fixture-token")
|
||||
var stdout, stderr bytes.Buffer
|
||||
status := run(context.Background(), []string{"deliver", "--repo", repository, "--assets", assets, "v1.2.3"}, &stdout, &stderr)
|
||||
expectedState := "partial"
|
||||
expectedCreates := 1
|
||||
if existingPage {
|
||||
expectedState = "not_attempted"
|
||||
expectedCreates = 0
|
||||
}
|
||||
if status != 1 || !strings.Contains(stderr.String(), "state="+expectedState) || state.assetUploads != 0 || state.releaseCreates != expectedCreates {
|
||||
t.Fatalf("status=%d creates=%d uploads=%d %s", status, state.releaseCreates, state.assetUploads, stderr.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user