Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion pkg/deploymentrecord/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (c *Client) PostOne(ctx context.Context, record *DeploymentRecord) error {

url := fmt.Sprintf("%s/orgs/%s/artifacts/metadata/deployment-record", c.baseURL, c.org)

body, err := json.Marshal(record)
body, err := buildRequestBody(record)
if err != nil {
return fmt.Errorf("failed to marshal record: %w", err)
}
Expand Down Expand Up @@ -398,6 +398,18 @@ func parseRateLimitDelay(resp *http.Response) time.Duration {
}
}

// buildRequestBody adds return_records=false to a deployment record request body
// which results in a minimal response payload.
func buildRequestBody(record *DeploymentRecord) ([]byte, error) {
return json.Marshal(struct {
DeploymentRecord
ReturnRecords bool `json:"return_records"`
}{
DeploymentRecord: *record,
ReturnRecords: false,
})
}

func waitForBackoff(ctx context.Context, attempt int) error {
if attempt > 0 {
backoff := time.Duration(math.Pow(2,
Expand Down
9 changes: 9 additions & 0 deletions pkg/deploymentrecord/client_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package deploymentrecord

import (
"bytes"
"context"
"errors"
"io"
"net/http"
"net/http/httptest"
"strconv"
Expand Down Expand Up @@ -593,6 +595,13 @@ func TestPostOneSendsCorrectRequest(t *testing.T) {
if got := r.Header.Get("Authorization"); got != "Bearer test-token" {
t.Errorf("Authorization = %s, want Bearer test-token", got)
}
body, err := io.ReadAll(r.Body)
if err != nil {
t.Fatal("unable to read request body")
}
if !bytes.Contains(body, []byte("\"return_records\":false")) {
t.Error("expected '\"return_records\":false' in the request body")
}
w.WriteHeader(http.StatusOK)
}))
t.Cleanup(srv.Close)
Expand Down
Loading