backend/remote: exit with 1 when a run is canceled
This commit is contained in:
parent
2b9e2b4c2b
commit
01f17fa0ca
|
@ -692,6 +692,11 @@ func (b *Remote) Operation(ctx context.Context, op *backend.Operation) (*backend
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if r == nil && opErr == context.Canceled {
|
||||||
|
runningOp.Result = backend.OperationFailure
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if r != nil {
|
if r != nil {
|
||||||
// Retrieve the run to get its current status.
|
// Retrieve the run to get its current status.
|
||||||
r, err := b.client.Runs.Read(cancelCtx, r.ID)
|
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
|
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) {
|
func TestRemote_applyWithoutPermissions(t *testing.T) {
|
||||||
b, bCleanup := testBackendNoDefault(t)
|
b, bCleanup := testBackendNoDefault(t)
|
||||||
defer bCleanup()
|
defer bCleanup()
|
||||||
|
@ -91,7 +114,7 @@ func TestRemote_applyWithoutPermissions(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("error creating named workspace: %v", err)
|
t.Fatalf("error creating named workspace: %v", err)
|
||||||
}
|
}
|
||||||
w.Permissions.CanUpdate = false
|
w.Permissions.CanQueueApply = false
|
||||||
|
|
||||||
op, configCleanup := testOperationApply(t, "./test-fixtures/apply")
|
op, configCleanup := testOperationApply(t, "./test-fixtures/apply")
|
||||||
defer configCleanup()
|
defer configCleanup()
|
||||||
|
|
|
@ -919,8 +919,8 @@ func (m *mockWorkspaces) Create(ctx context.Context, organization string, option
|
||||||
Name: *options.Name,
|
Name: *options.Name,
|
||||||
Operations: !strings.HasSuffix(*options.Name, "no-operations"),
|
Operations: !strings.HasSuffix(*options.Name, "no-operations"),
|
||||||
Permissions: &tfe.WorkspacePermissions{
|
Permissions: &tfe.WorkspacePermissions{
|
||||||
|
CanQueueApply: true,
|
||||||
CanQueueRun: true,
|
CanQueueRun: true,
|
||||||
CanUpdate: true,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if options.AutoApply != nil {
|
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) {
|
func TestRemote_planLongLine(t *testing.T) {
|
||||||
b, bCleanup := testBackendDefault(t)
|
b, bCleanup := testBackendDefault(t)
|
||||||
defer bCleanup()
|
defer bCleanup()
|
||||||
|
|
Loading…
Reference in New Issue