Skip to content

Commit 38e4cd1

Browse files
committed
chore: remove dead code
1 parent 87b990e commit 38e4cd1

2 files changed

Lines changed: 0 additions & 208 deletions

File tree

pkg/deploymentrecord/client.go

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -258,50 +258,6 @@ func (c *Client) PostOne(ctx context.Context, record *Record) error {
258258
}
259259
}
260260

261-
// PostCluster sends a full cluster state of records to GitHub deployment
262-
// records cluster API.
263-
func (c *Client) PostCluster(ctx context.Context, records []*Record, cluster string) ([]byte, error) {
264-
if len(records) == 0 {
265-
slog.Debug("Records is empty, skipping")
266-
return nil, nil
267-
}
268-
269-
clusterURL := fmt.Sprintf("%s/orgs/%s/artifacts/metadata/deployment-record/cluster/%s", c.baseURL, c.org, url.PathEscape(cluster))
270-
271-
body, err := buildClusterRequestBody(records)
272-
if err != nil {
273-
return nil, fmt.Errorf("failed to marshal records: %w", err)
274-
}
275-
276-
respBody, statusCode, lastErr := c.doWithRetry(ctx, http.MethodPost, clusterURL, body)
277-
278-
var clientErr *ClientError
279-
switch {
280-
case errors.As(lastErr, &clientErr):
281-
dtmetrics.PostDeploymentRecordClientError.Inc()
282-
slog.Warn("client error, aborting",
283-
"status_code", statusCode,
284-
"url", clusterURL,
285-
"resp_msg", string(respBody),
286-
)
287-
return nil, fmt.Errorf("client error: %w", lastErr)
288-
case statusCode >= 200 && statusCode < 300:
289-
dtmetrics.PostDeploymentRecordOk.Inc()
290-
return respBody, nil
291-
case statusCode == 404:
292-
dtmetrics.PostDeploymentRecordUnknownArtifact.Inc()
293-
return nil, &ClusterNoRepositoriesError{err: errors.New("no repositories found")}
294-
default:
295-
dtmetrics.PostDeploymentRecordHardFail.Inc()
296-
slog.Error("all retries exhausted",
297-
"count", c.retries,
298-
"error", lastErr,
299-
"cluster", cluster,
300-
)
301-
return nil, fmt.Errorf("all retries exhausted: %w", lastErr)
302-
}
303-
}
304-
305261
// CreateClusterJob submits the full cluster state as an async job.
306262
// Returns the job response (including job ID) and any authorization errors
307263
// for rejected deployments.

pkg/deploymentrecord/client_test.go

Lines changed: 0 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -729,170 +729,6 @@ func TestPostOneRespectsRetryAfterAcrossGoroutines(t *testing.T) {
729729
wg.Wait()
730730
}
731731

732-
func TestPostCluster(t *testing.T) {
733-
tests := []struct {
734-
name string
735-
records []*Record
736-
handler http.HandlerFunc
737-
wantErr bool
738-
errType any
739-
errContain string
740-
wantBody bool
741-
wantOk float64
742-
wantUnknownArtifact float64
743-
wantSoftFail float64
744-
wantHardFail float64
745-
wantClientError float64
746-
}{
747-
{
748-
name: "empty records returns nil",
749-
records: []*Record{},
750-
handler: func(_ http.ResponseWriter, _ *http.Request) {
751-
t.Fatal("server should not be called with empty records")
752-
},
753-
},
754-
{
755-
name: "success on 207 returns body",
756-
records: []*Record{testRecord()},
757-
handler: func(w http.ResponseWriter, _ *http.Request) {
758-
w.WriteHeader(http.StatusMultiStatus)
759-
_, _ = w.Write([]byte(`{"total_count":1,"deployment_records":[],"errors":[]}`))
760-
},
761-
wantBody: true,
762-
wantOk: 1,
763-
},
764-
{
765-
name: "404 returns ClusterNoRepositoriesError",
766-
records: []*Record{testRecord()},
767-
handler: func(w http.ResponseWriter, _ *http.Request) {
768-
w.WriteHeader(http.StatusNotFound)
769-
},
770-
wantErr: true,
771-
errType: &ClusterNoRepositoriesError{},
772-
wantUnknownArtifact: 1,
773-
},
774-
{
775-
name: "400 returns client error",
776-
records: []*Record{testRecord()},
777-
handler: func(w http.ResponseWriter, _ *http.Request) {
778-
w.WriteHeader(http.StatusBadRequest)
779-
_, _ = w.Write([]byte("bad request"))
780-
},
781-
wantErr: true,
782-
errContain: "client error",
783-
wantClientError: 1,
784-
},
785-
{
786-
name: "500 retries exhausted returns error",
787-
records: []*Record{testRecord()},
788-
handler: func(w http.ResponseWriter, _ *http.Request) {
789-
w.WriteHeader(http.StatusInternalServerError)
790-
},
791-
wantErr: true,
792-
errContain: "all retries exhausted",
793-
wantSoftFail: 1,
794-
wantHardFail: 1,
795-
},
796-
}
797-
798-
for _, tt := range tests {
799-
t.Run(tt.name, func(t *testing.T) {
800-
srv := httptest.NewServer(tt.handler)
801-
t.Cleanup(srv.Close)
802-
803-
client, err := NewClient(srv.URL, "test-org", WithRetries(0))
804-
if err != nil {
805-
t.Fatalf("failed to create client: %v", err)
806-
}
807-
808-
counters := allCounters()
809-
snapshots := make([]float64, len(counters))
810-
for i, c := range counters {
811-
snapshots[i] = testutil.ToFloat64(c)
812-
}
813-
814-
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
815-
t.Cleanup(cancel)
816-
817-
respBody, err := client.PostCluster(ctx, tt.records, "test-cluster")
818-
819-
if tt.wantErr {
820-
if err == nil {
821-
t.Fatal("expected error, got nil")
822-
}
823-
if tt.errType != nil {
824-
switch tt.errType.(type) {
825-
case *ClusterNoRepositoriesError:
826-
var e *ClusterNoRepositoriesError
827-
if !errors.As(err, &e) {
828-
t.Errorf("expected ClusterNoRepositoriesError, got %T: %v", err, err)
829-
}
830-
default:
831-
t.Fatalf("unexpected error type in test: %T", tt.errType)
832-
}
833-
}
834-
if tt.errContain != "" && !strings.Contains(err.Error(), tt.errContain) {
835-
t.Errorf("error %q should contain %q", err.Error(), tt.errContain)
836-
}
837-
} else if err != nil {
838-
t.Fatalf("unexpected error: %v", err)
839-
}
840-
841-
if tt.wantBody && respBody == nil {
842-
t.Error("expected non-nil response body")
843-
}
844-
845-
wantDeltas := []float64{
846-
tt.wantOk,
847-
tt.wantUnknownArtifact,
848-
0, // rate limited
849-
tt.wantSoftFail,
850-
tt.wantHardFail,
851-
tt.wantClientError,
852-
}
853-
names := []string{
854-
"PostDeploymentRecordOk",
855-
"PostDeploymentRecordUnknownArtifact",
856-
"PostDeploymentRecordRateLimited",
857-
"PostDeploymentRecordSoftFail",
858-
"PostDeploymentRecordHardFail",
859-
"PostDeploymentRecordClientError",
860-
}
861-
for i, c := range counters {
862-
got := testutil.ToFloat64(c) - snapshots[i]
863-
if got != wantDeltas[i] {
864-
t.Errorf("%s delta = %v, want %v", names[i], got, wantDeltas[i])
865-
}
866-
}
867-
})
868-
}
869-
}
870-
871-
func TestPostCluster_URLEscapesCluster(t *testing.T) {
872-
var rawPath string
873-
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
874-
rawPath = r.URL.RawPath
875-
w.WriteHeader(http.StatusOK)
876-
_, _ = w.Write([]byte(`{"total_count":0,"deployment_records":[]}`))
877-
}))
878-
t.Cleanup(srv.Close)
879-
880-
client, err := NewClient(srv.URL, "test-org", WithRetries(0))
881-
if err != nil {
882-
t.Fatalf("failed to create client: %v", err)
883-
}
884-
885-
_, err = client.PostCluster(context.Background(), []*Record{testRecord()}, "cluster/with spaces")
886-
if err != nil {
887-
t.Fatalf("unexpected error: %v", err)
888-
}
889-
890-
wantSuffix := "/cluster/cluster%2Fwith%20spaces"
891-
if !strings.HasSuffix(rawPath, wantSuffix) {
892-
t.Errorf("raw path %q should end with %q", rawPath, wantSuffix)
893-
}
894-
}
895-
896732
func TestCreateClusterJob(t *testing.T) {
897733
tests := []struct {
898734
name string

0 commit comments

Comments
 (0)