From e64a6b19e5dd2b2481dc01b13b52a3ab97a01f43 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Sun, 15 Dec 2024 23:19:31 +0100 Subject: [PATCH] add continue on error test case --- cli/pipeline/purge_test.go | 37 +++++++++++++++++++++++++++++-------- web/package.json | 3 ++- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/cli/pipeline/purge_test.go b/cli/pipeline/purge_test.go index 12356dd0b..728a947d4 100644 --- a/cli/pipeline/purge_test.go +++ b/cli/pipeline/purge_test.go @@ -16,13 +16,14 @@ import ( func TestPipelinePurge(t *testing.T) { tests := []struct { - name string - repoID int64 - args []string - pipelinesKeep []*woodpecker.Pipeline - pipelines []*woodpecker.Pipeline - wantDelete int - wantErr error + name string + repoID int64 + args []string + pipelinesKeep []*woodpecker.Pipeline + pipelines []*woodpecker.Pipeline + mockDeleteError error + wantDelete int + wantErr error }{ { name: "success with no pipelines to purge", @@ -53,6 +54,24 @@ func TestPipelinePurge(t *testing.T) { args: []string{"purge", "--older-than", "invalid", "repo/name"}, wantErr: errors.New("time: invalid duration \"invalid\""), }, + { + name: "continue on 422 error", + repoID: 1, + args: []string{"purge", "--older-than", "1h", "repo/name"}, + pipelinesKeep: []*woodpecker.Pipeline{ + {Number: 1}, + }, + pipelines: []*woodpecker.Pipeline{ + {Number: 1}, + {Number: 2}, + {Number: 3}, + }, + wantDelete: 2, + mockDeleteError: &woodpecker.ClientError{ + StatusCode: 422, + Message: "test error", + }, + }, } for _, tt := range tests { @@ -80,7 +99,9 @@ func TestPipelinePurge(t *testing.T) { return []*woodpecker.Pipeline{}, nil }).Maybe() - if tt.wantDelete > 0 { + if tt.mockDeleteError != nil { + mockClient.On("PipelineDelete", tt.repoID, mock.Anything).Return(tt.mockDeleteError) + } else if tt.wantDelete > 0 { mockClient.On("PipelineDelete", tt.repoID, mock.Anything).Return(nil).Times(tt.wantDelete) } diff --git a/web/package.json b/web/package.json index 874f81d49..0279d9472 100644 --- a/web/package.json +++ b/web/package.json @@ -70,5 +70,6 @@ "overrides": { "semver@<7.5.2": ">=7.5.2" } - } + }, + "packageManager": "pnpm@9.15.0+sha512.76e2379760a4328ec4415815bcd6628dee727af3779aaa4c914e3944156c4299921a89f976381ee107d41f12cfa4b66681ca9c718f0668fa0831ed4c6d8ba56c" }