Merge pull request #32708 from mrinalirao/mr/taskStage-race

Bug Fix where CLI exits if run is not confirmable.
This commit is contained in:
Brandon Croft 2023-02-21 18:17:51 -07:00 committed by GitHub
commit 3d1a58d5b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View File

@ -97,8 +97,14 @@ func (b *Cloud) runTaskStage(ctx *IntegrationContext, output IntegrationOutputWr
case tfe.TaskStagePending:
// Waiting for it to start
return true, nil
case tfe.TaskStageRunning:
if _, e := processSummarizers(ctx, output, stage, summarizers, errs); e != nil {
errs = e
}
// not a terminal status so we continue to poll
return true, nil
// Note: Terminal statuses need to print out one last time just in case
case tfe.TaskStageRunning, tfe.TaskStagePassed:
case tfe.TaskStagePassed:
ok, e := processSummarizers(ctx, output, stage, summarizers, errs)
if e != nil {
errs = e
@ -176,6 +182,8 @@ func (b *Cloud) processStageOverrides(context *IntegrationContext, output Integr
if err != errRunOverridden {
if _, err = b.client.TaskStages.Override(context.StopContext, taskStageID, tfe.TaskStageOverrideOptions{}); err != nil {
return false, generalError(fmt.Sprintf("Failed to override policy check.\n%s", runUrl), err)
} else {
return true, nil
}
} else {
output.Output(fmt.Sprintf("The run needs to be manually overridden or discarded.\n%s\n", runUrl))

View File

@ -220,6 +220,7 @@ func TestTaskStageOverride(t *testing.T) {
isError bool
errMsg string
input *mockInput
cont bool
}{
"override-pass": {
taskStageID: "ts-pass",
@ -228,6 +229,7 @@ func TestTaskStageOverride(t *testing.T) {
"→→ [bold]Override": "override",
}),
errMsg: "",
cont: true,
},
"override-fail": {
taskStageID: "ts-err",
@ -236,6 +238,7 @@ func TestTaskStageOverride(t *testing.T) {
"→→ [bold]Override": "override",
}),
errMsg: "",
cont: false,
},
"skip-override": {
taskStageID: "ts-err",
@ -244,11 +247,12 @@ func TestTaskStageOverride(t *testing.T) {
input: testInput(t, map[string]string{
"→→ [bold]Override": "no",
}),
cont: false,
},
}
for _, c := range cases {
integrationContext.Op.UIIn = c.input
_, err := b.processStageOverrides(integrationContext, writer, c.taskStageID)
cont, err := b.processStageOverrides(integrationContext, writer, c.taskStageID)
if c.isError {
if err == nil {
t.Fatalf("Expected to fail with some error")
@ -264,5 +268,8 @@ func TestTaskStageOverride(t *testing.T) {
t.Fatalf("Expected to pass, got err: %s", err)
}
}
if c.cont != cont {
t.Fatalf("expected polling continue: %t, got: %t", c.cont, cont)
}
}
}