mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
Merge pull request #20481 from hashicorp/svh/b-exit-code
backend/remote: exit with 1 when a run is canceled
This commit is contained in:
commit
63e2dcef8a
@ -692,6 +692,11 @@ func (b *Remote) Operation(ctx context.Context, op *backend.Operation) (*backend
|
||||
return
|
||||
}
|
||||
|
||||
if r == nil && opErr == context.Canceled {
|
||||
runningOp.Result = backend.OperationFailure
|
||||
return
|
||||
}
|
||||
|
||||
if r != nil {
|
||||
// Retrieve the run to get its current status.
|
||||
r, err := b.client.Runs.Read(cancelCtx, r.ID)
|
||||
@ -710,7 +715,7 @@ func (b *Remote) Operation(ctx context.Context, op *backend.Operation) (*backend
|
||||
}
|
||||
}
|
||||
|
||||
if r.Status == tfe.RunErrored {
|
||||
if r.Status == tfe.RunCanceled || r.Status == tfe.RunErrored {
|
||||
runningOp.Result = backend.OperationFailure
|
||||
}
|
||||
}
|
||||
|
@ -76,6 +76,29 @@ func TestRemote_applyBasic(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemote_applyCanceled(t *testing.T) {
|
||||
b, bCleanup := testBackendDefault(t)
|
||||
defer bCleanup()
|
||||
|
||||
op, configCleanup := testOperationApply(t, "./test-fixtures/apply")
|
||||
defer configCleanup()
|
||||
|
||||
op.Workspace = backend.DefaultStateName
|
||||
|
||||
run, err := b.Operation(context.Background(), op)
|
||||
if err != nil {
|
||||
t.Fatalf("error starting operation: %v", err)
|
||||
}
|
||||
|
||||
// Stop the run to simulate a Ctrl-C.
|
||||
run.Stop()
|
||||
|
||||
<-run.Done()
|
||||
if run.Result == backend.OperationSuccess {
|
||||
t.Fatal("expected apply operation to fail")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemote_applyWithoutPermissions(t *testing.T) {
|
||||
b, bCleanup := testBackendNoDefault(t)
|
||||
defer bCleanup()
|
||||
@ -91,7 +114,7 @@ func TestRemote_applyWithoutPermissions(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("error creating named workspace: %v", err)
|
||||
}
|
||||
w.Permissions.CanUpdate = false
|
||||
w.Permissions.CanQueueApply = false
|
||||
|
||||
op, configCleanup := testOperationApply(t, "./test-fixtures/apply")
|
||||
defer configCleanup()
|
||||
|
@ -919,8 +919,8 @@ func (m *mockWorkspaces) Create(ctx context.Context, organization string, option
|
||||
Name: *options.Name,
|
||||
Operations: !strings.HasSuffix(*options.Name, "no-operations"),
|
||||
Permissions: &tfe.WorkspacePermissions{
|
||||
CanQueueRun: true,
|
||||
CanUpdate: true,
|
||||
CanQueueApply: true,
|
||||
CanQueueRun: true,
|
||||
},
|
||||
}
|
||||
if options.AutoApply != nil {
|
||||
|
@ -63,6 +63,29 @@ func TestRemote_planBasic(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemote_planCanceled(t *testing.T) {
|
||||
b, bCleanup := testBackendDefault(t)
|
||||
defer bCleanup()
|
||||
|
||||
op, configCleanup := testOperationPlan(t, "./test-fixtures/plan")
|
||||
defer configCleanup()
|
||||
|
||||
op.Workspace = backend.DefaultStateName
|
||||
|
||||
run, err := b.Operation(context.Background(), op)
|
||||
if err != nil {
|
||||
t.Fatalf("error starting operation: %v", err)
|
||||
}
|
||||
|
||||
// Stop the run to simulate a Ctrl-C.
|
||||
run.Stop()
|
||||
|
||||
<-run.Done()
|
||||
if run.Result == backend.OperationSuccess {
|
||||
t.Fatal("expected plan operation to fail")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemote_planLongLine(t *testing.T) {
|
||||
b, bCleanup := testBackendDefault(t)
|
||||
defer bCleanup()
|
||||
|
Loading…
Reference in New Issue
Block a user