Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): manually delete 1 build from history #3782 #4400

Merged
merged 6 commits into from
Jul 5, 2019
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat(api): manually delete 1 build from history #3782
Signed-off-by: Benjamin Coenen <benjamin.coenen@corp.ovh.com>
bnjjj committed Jun 26, 2019
commit 99a3e4582360fc5511b3c08953e8174b9621683f
49 changes: 9 additions & 40 deletions engine/api/workflow/dao_run_test.go
Original file line number Diff line number Diff line change
@@ -246,18 +246,9 @@ vcs_ssh_key: proj-blabla
errP := workflow.PurgeWorkflowRun(context.Background(), db, *w1, nil)
test.NoError(t, errP)

wruns, _, _, count, errRuns := workflow.LoadRuns(db, proj.Key, w1.Name, 0, 10, nil)
_, _, _, count, errRuns := workflow.LoadRuns(db, proj.Key, w1.Name, 0, 10, nil)
test.NoError(t, errRuns)
test.Equal(t, 5, count, "Number of workflow runs isn't correct")

toDeleteNb := 0
for _, wfRun := range wruns {
if wfRun.ToDelete {
toDeleteNb++
}
}

test.Equal(t, 3, toDeleteNb, "Number of workflow runs to be purged isn't correct")
test.Equal(t, 2, count, "Number of workflow runs isn't correct")
}

func TestPurgeWorkflowRunWithRunningStatus(t *testing.T) {
@@ -535,19 +526,14 @@ vcs_ssh_key: proj-blabla

wruns, _, _, count, errRuns := workflow.LoadRuns(db, proj.Key, w1.Name, 0, 10, nil)
test.NoError(t, errRuns)
test.Equal(t, 6, count, "Number of workflow runs isn't correct")
toDeleteNb := 0
test.Equal(t, 3, count, "Number of workflow runs isn't correct")
wfInSuccess := false
for _, wfRun := range wruns {
if wfRun.ToDelete {
toDeleteNb++
if wfRun.Status == sdk.StatusSuccess.String() {
wfInSuccess = true
}
if wfRun.Status == sdk.StatusSuccess.String() {
wfInSuccess = true
}
}

test.Equal(t, 3, toDeleteNb, "Number of workflow runs to be purged isn't correct")
test.Equal(t, false, wfInSuccess, "The workflow should keep at least one workflow run in success")
}

@@ -714,17 +700,9 @@ vcs_ssh_key: proj-blabla
errP := workflow.PurgeWorkflowRun(context.Background(), db, *w1, nil)
test.NoError(t, errP)

wruns, _, _, count, errRuns := workflow.LoadRuns(db, proj.Key, w1.Name, 0, 10, nil)
_, _, _, count, errRuns := workflow.LoadRuns(db, proj.Key, w1.Name, 0, 10, nil)
test.NoError(t, errRuns)
test.Equal(t, 5, count, "Number of workflow runs isn't correct")
toDeleteNb := 0
for _, wfRun := range wruns {
if wfRun.ToDelete {
toDeleteNb++
}
}

test.Equal(t, 3, toDeleteNb, "Number of workflow runs to be purged isn't correct")
test.Equal(t, 2, count, "Number of workflow runs isn't correct")
}

func TestPurgeWorkflowRunWithoutTags(t *testing.T) {
@@ -806,18 +784,9 @@ func TestPurgeWorkflowRunWithoutTags(t *testing.T) {
errP := workflow.PurgeWorkflowRun(context.Background(), db, *w1, nil)
test.NoError(t, errP)

wruns, _, _, count, errRuns := workflow.LoadRuns(db, proj.Key, w1.Name, 0, 10, nil)
_, _, _, count, errRuns := workflow.LoadRuns(db, proj.Key, w1.Name, 0, 10, nil)
test.NoError(t, errRuns)
test.Equal(t, 10, count, "Number of workflow runs isn't correct")

toDeleteNb := 0
for _, wfRun := range wruns {
if wfRun.ToDelete {
toDeleteNb++
}
}

test.Equal(t, 7, toDeleteNb, "Number of workflow runs to be purged isn't correct (because it should keep at least one in success)")
test.Equal(t, 3, count, "Number of workflow runs isn't correct")
}

func TestPurgeWorkflowRunWithoutTagsBiggerHistoryLength(t *testing.T) {
3 changes: 1 addition & 2 deletions engine/api/workflow_run_test.go
Original file line number Diff line number Diff line change
@@ -1844,6 +1844,5 @@ func Test_deleteWorkflowRunsBranchHandler(t *testing.T) {

var wfRuns []sdk.WorkflowRun
test.NoError(t, json.Unmarshal(rec.Body.Bytes(), &wfRuns))
assert.Equal(t, 1, len(wfRuns))
assert.True(t, wfRuns[0].ToDelete)
assert.Equal(t, 0, len(wfRuns))
}