|
|
|
|
@ -508,6 +508,73 @@ func TestCloud_applyWithCloudPlan(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestCloud_applyAutoApprove_with_CloudPlan(t *testing.T) {
|
|
|
|
|
b, bCleanup := testBackendWithName(t)
|
|
|
|
|
defer bCleanup()
|
|
|
|
|
|
|
|
|
|
op, configCleanup, done := testOperationApply(t, "./testdata/apply-json")
|
|
|
|
|
defer configCleanup()
|
|
|
|
|
defer done(t)
|
|
|
|
|
|
|
|
|
|
op.AutoApprove = true
|
|
|
|
|
op.UIOut = b.CLI
|
|
|
|
|
op.Workspace = testBackendSingleWorkspaceName
|
|
|
|
|
|
|
|
|
|
mockSROWorkspace(t, b, op.Workspace)
|
|
|
|
|
|
|
|
|
|
ws, err := b.client.Workspaces.Read(context.Background(), b.Organization, b.WorkspaceMapping.Name)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("Couldn't read workspace: %s", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
planRun, err := b.plan(context.Background(), context.Background(), op, ws)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("Couldn't perform plan: %s", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Synthesize a cloud plan file with the plan's run ID
|
|
|
|
|
pf := &cloudplan.SavedPlanBookmark{
|
|
|
|
|
RemotePlanFormat: 1,
|
|
|
|
|
RunID: planRun.ID,
|
|
|
|
|
Hostname: b.Hostname,
|
|
|
|
|
}
|
|
|
|
|
op.PlanFile = planfile.NewWrappedCloud(pf)
|
|
|
|
|
|
|
|
|
|
// Start spying on the apply output (now that the plan's done)
|
|
|
|
|
stream, close := terminal.StreamsForTesting(t)
|
|
|
|
|
|
|
|
|
|
b.renderer = &jsonformat.Renderer{
|
|
|
|
|
Streams: stream,
|
|
|
|
|
Colorize: mockColorize(),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Try apply
|
|
|
|
|
run, err := b.Operation(context.Background(), op)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("error starting operation: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<-run.Done()
|
|
|
|
|
output := close(t)
|
|
|
|
|
if run.Result != backendrun.OperationSuccess {
|
|
|
|
|
t.Fatal("expected apply operation to succeed")
|
|
|
|
|
}
|
|
|
|
|
if run.PlanEmpty {
|
|
|
|
|
t.Fatalf("expected plan to not be empty")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gotOut := output.Stdout()
|
|
|
|
|
if !strings.Contains(gotOut, "1 added, 0 changed, 0 destroyed") {
|
|
|
|
|
t.Fatalf("expected apply summary in output: %s", gotOut)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stateMgr, _ := b.StateMgr(testBackendSingleWorkspaceName)
|
|
|
|
|
// An error suggests that the state was not unlocked after apply
|
|
|
|
|
if _, err := stateMgr.Lock(statemgr.NewLockInfo()); err != nil {
|
|
|
|
|
t.Fatalf("unexpected error locking state after apply: %s", err.Error())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestCloud_applyWithoutRefresh(t *testing.T) {
|
|
|
|
|
b, bCleanup := testBackendWithName(t)
|
|
|
|
|
defer bCleanup()
|
|
|
|
|
|