|
|
|
|
@ -22,53 +22,44 @@ import (
|
|
|
|
|
"github.com/hashicorp/terraform/plans/planfile"
|
|
|
|
|
"github.com/hashicorp/terraform/states/statemgr"
|
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
|
"github.com/hashicorp/terraform/tfdiags"
|
|
|
|
|
tfversion "github.com/hashicorp/terraform/version"
|
|
|
|
|
"github.com/mitchellh/cli"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func testOperationApply(t *testing.T, configDir string) (*backend.Operation, func()) {
|
|
|
|
|
func testOperationApply(t *testing.T, configDir string) (*backend.Operation, func(), func(*testing.T) *terminal.TestOutput) {
|
|
|
|
|
t.Helper()
|
|
|
|
|
|
|
|
|
|
return testOperationApplyWithTimeout(t, configDir, 0)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func testOperationApplyWithTimeout(t *testing.T, configDir string, timeout time.Duration) (*backend.Operation, func()) {
|
|
|
|
|
func testOperationApplyWithTimeout(t *testing.T, configDir string, timeout time.Duration) (*backend.Operation, func(), func(*testing.T) *terminal.TestOutput) {
|
|
|
|
|
t.Helper()
|
|
|
|
|
|
|
|
|
|
_, configLoader, configCleanup := initwd.MustLoadConfigForTests(t, configDir)
|
|
|
|
|
|
|
|
|
|
streams, _ := terminal.StreamsForTesting(t)
|
|
|
|
|
view := views.NewStateLocker(arguments.ViewHuman, views.NewView(streams))
|
|
|
|
|
streams, done := terminal.StreamsForTesting(t)
|
|
|
|
|
view := views.NewView(streams)
|
|
|
|
|
stateLockerView := views.NewStateLocker(arguments.ViewHuman, view)
|
|
|
|
|
operationView := views.NewOperation(arguments.ViewHuman, false, view)
|
|
|
|
|
|
|
|
|
|
return &backend.Operation{
|
|
|
|
|
ConfigDir: configDir,
|
|
|
|
|
ConfigLoader: configLoader,
|
|
|
|
|
Parallelism: defaultParallelism,
|
|
|
|
|
PlanRefresh: true,
|
|
|
|
|
ShowDiagnostics: testLogDiagnostics(t),
|
|
|
|
|
StateLocker: clistate.NewLocker(timeout, view),
|
|
|
|
|
Type: backend.OperationTypeApply,
|
|
|
|
|
}, configCleanup
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func testOperationApplyWithDiagnostics(t *testing.T, configDir string) (*backend.Operation, func(), func() tfdiags.Diagnostics) {
|
|
|
|
|
t.Helper()
|
|
|
|
|
|
|
|
|
|
op, cleanup := testOperationApply(t, configDir)
|
|
|
|
|
|
|
|
|
|
record, playback := testRecordDiagnostics(t)
|
|
|
|
|
op.ShowDiagnostics = record
|
|
|
|
|
|
|
|
|
|
return op, cleanup, playback
|
|
|
|
|
ConfigDir: configDir,
|
|
|
|
|
ConfigLoader: configLoader,
|
|
|
|
|
Parallelism: defaultParallelism,
|
|
|
|
|
PlanRefresh: true,
|
|
|
|
|
StateLocker: clistate.NewLocker(timeout, stateLockerView),
|
|
|
|
|
Type: backend.OperationTypeApply,
|
|
|
|
|
View: operationView,
|
|
|
|
|
}, configCleanup, done
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestRemote_applyBasic(t *testing.T) {
|
|
|
|
|
b, bCleanup := testBackendDefault(t)
|
|
|
|
|
defer bCleanup()
|
|
|
|
|
|
|
|
|
|
op, configCleanup := testOperationApply(t, "./testdata/apply")
|
|
|
|
|
op, configCleanup, done := testOperationApply(t, "./testdata/apply")
|
|
|
|
|
defer configCleanup()
|
|
|
|
|
defer done(t)
|
|
|
|
|
|
|
|
|
|
input := testInput(t, map[string]string{
|
|
|
|
|
"approve": "yes",
|
|
|
|
|
@ -117,8 +108,9 @@ func TestRemote_applyCanceled(t *testing.T) {
|
|
|
|
|
b, bCleanup := testBackendDefault(t)
|
|
|
|
|
defer bCleanup()
|
|
|
|
|
|
|
|
|
|
op, configCleanup := testOperationApply(t, "./testdata/apply")
|
|
|
|
|
op, configCleanup, done := testOperationApply(t, "./testdata/apply")
|
|
|
|
|
defer configCleanup()
|
|
|
|
|
defer done(t)
|
|
|
|
|
|
|
|
|
|
op.Workspace = backend.DefaultStateName
|
|
|
|
|
|
|
|
|
|
@ -158,7 +150,7 @@ func TestRemote_applyWithoutPermissions(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
w.Permissions.CanQueueApply = false
|
|
|
|
|
|
|
|
|
|
op, configCleanup, playback := testOperationApplyWithDiagnostics(t, "./testdata/apply")
|
|
|
|
|
op, configCleanup, done := testOperationApply(t, "./testdata/apply")
|
|
|
|
|
defer configCleanup()
|
|
|
|
|
|
|
|
|
|
op.UIOut = b.CLI
|
|
|
|
|
@ -170,11 +162,12 @@ func TestRemote_applyWithoutPermissions(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<-run.Done()
|
|
|
|
|
output := done(t)
|
|
|
|
|
if run.Result == backend.OperationSuccess {
|
|
|
|
|
t.Fatal("expected apply operation to fail")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
errOutput := playback().Err().Error()
|
|
|
|
|
errOutput := output.Stderr()
|
|
|
|
|
if !strings.Contains(errOutput, "Insufficient rights to apply changes") {
|
|
|
|
|
t.Fatalf("expected a permissions error, got: %v", errOutput)
|
|
|
|
|
}
|
|
|
|
|
@ -197,7 +190,7 @@ func TestRemote_applyWithVCS(t *testing.T) {
|
|
|
|
|
t.Fatalf("error creating named workspace: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
op, configCleanup, playback := testOperationApplyWithDiagnostics(t, "./testdata/apply")
|
|
|
|
|
op, configCleanup, done := testOperationApply(t, "./testdata/apply")
|
|
|
|
|
defer configCleanup()
|
|
|
|
|
|
|
|
|
|
op.Workspace = "prod"
|
|
|
|
|
@ -208,6 +201,7 @@ func TestRemote_applyWithVCS(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<-run.Done()
|
|
|
|
|
output := done(t)
|
|
|
|
|
if run.Result == backend.OperationSuccess {
|
|
|
|
|
t.Fatal("expected apply operation to fail")
|
|
|
|
|
}
|
|
|
|
|
@ -215,7 +209,7 @@ func TestRemote_applyWithVCS(t *testing.T) {
|
|
|
|
|
t.Fatalf("expected plan to be empty")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
errOutput := playback().Err().Error()
|
|
|
|
|
errOutput := output.Stderr()
|
|
|
|
|
if !strings.Contains(errOutput, "not allowed for workspaces with a VCS") {
|
|
|
|
|
t.Fatalf("expected a VCS error, got: %v", errOutput)
|
|
|
|
|
}
|
|
|
|
|
@ -225,7 +219,7 @@ func TestRemote_applyWithParallelism(t *testing.T) {
|
|
|
|
|
b, bCleanup := testBackendDefault(t)
|
|
|
|
|
defer bCleanup()
|
|
|
|
|
|
|
|
|
|
op, configCleanup, playback := testOperationApplyWithDiagnostics(t, "./testdata/apply")
|
|
|
|
|
op, configCleanup, done := testOperationApply(t, "./testdata/apply")
|
|
|
|
|
defer configCleanup()
|
|
|
|
|
|
|
|
|
|
op.Parallelism = 3
|
|
|
|
|
@ -237,11 +231,12 @@ func TestRemote_applyWithParallelism(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<-run.Done()
|
|
|
|
|
output := done(t)
|
|
|
|
|
if run.Result == backend.OperationSuccess {
|
|
|
|
|
t.Fatal("expected apply operation to fail")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
errOutput := playback().Err().Error()
|
|
|
|
|
errOutput := output.Stderr()
|
|
|
|
|
if !strings.Contains(errOutput, "parallelism values are currently not supported") {
|
|
|
|
|
t.Fatalf("expected a parallelism error, got: %v", errOutput)
|
|
|
|
|
}
|
|
|
|
|
@ -251,7 +246,7 @@ func TestRemote_applyWithPlan(t *testing.T) {
|
|
|
|
|
b, bCleanup := testBackendDefault(t)
|
|
|
|
|
defer bCleanup()
|
|
|
|
|
|
|
|
|
|
op, configCleanup, playback := testOperationApplyWithDiagnostics(t, "./testdata/apply")
|
|
|
|
|
op, configCleanup, done := testOperationApply(t, "./testdata/apply")
|
|
|
|
|
defer configCleanup()
|
|
|
|
|
|
|
|
|
|
op.PlanFile = &planfile.Reader{}
|
|
|
|
|
@ -263,6 +258,7 @@ func TestRemote_applyWithPlan(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<-run.Done()
|
|
|
|
|
output := done(t)
|
|
|
|
|
if run.Result == backend.OperationSuccess {
|
|
|
|
|
t.Fatal("expected apply operation to fail")
|
|
|
|
|
}
|
|
|
|
|
@ -270,7 +266,7 @@ func TestRemote_applyWithPlan(t *testing.T) {
|
|
|
|
|
t.Fatalf("expected plan to be empty")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
errOutput := playback().Err().Error()
|
|
|
|
|
errOutput := output.Stderr()
|
|
|
|
|
if !strings.Contains(errOutput, "saved plan is currently not supported") {
|
|
|
|
|
t.Fatalf("expected a saved plan error, got: %v", errOutput)
|
|
|
|
|
}
|
|
|
|
|
@ -280,7 +276,7 @@ func TestRemote_applyWithoutRefresh(t *testing.T) {
|
|
|
|
|
b, bCleanup := testBackendDefault(t)
|
|
|
|
|
defer bCleanup()
|
|
|
|
|
|
|
|
|
|
op, configCleanup, playback := testOperationApplyWithDiagnostics(t, "./testdata/apply")
|
|
|
|
|
op, configCleanup, done := testOperationApply(t, "./testdata/apply")
|
|
|
|
|
defer configCleanup()
|
|
|
|
|
|
|
|
|
|
op.PlanRefresh = false
|
|
|
|
|
@ -292,11 +288,12 @@ func TestRemote_applyWithoutRefresh(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<-run.Done()
|
|
|
|
|
output := done(t)
|
|
|
|
|
if run.Result == backend.OperationSuccess {
|
|
|
|
|
t.Fatal("expected apply operation to fail")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
errOutput := playback().Err().Error()
|
|
|
|
|
errOutput := output.Stderr()
|
|
|
|
|
if !strings.Contains(errOutput, "refresh is currently not supported") {
|
|
|
|
|
t.Fatalf("expected a refresh error, got: %v", errOutput)
|
|
|
|
|
}
|
|
|
|
|
@ -306,8 +303,9 @@ func TestRemote_applyWithTarget(t *testing.T) {
|
|
|
|
|
b, bCleanup := testBackendDefault(t)
|
|
|
|
|
defer bCleanup()
|
|
|
|
|
|
|
|
|
|
op, configCleanup := testOperationApply(t, "./testdata/apply")
|
|
|
|
|
op, configCleanup, done := testOperationApply(t, "./testdata/apply")
|
|
|
|
|
defer configCleanup()
|
|
|
|
|
defer done(t)
|
|
|
|
|
|
|
|
|
|
addr, _ := addrs.ParseAbsResourceStr("null_resource.foo")
|
|
|
|
|
|
|
|
|
|
@ -344,7 +342,7 @@ func TestRemote_applyWithTargetIncompatibleAPIVersion(t *testing.T) {
|
|
|
|
|
b, bCleanup := testBackendDefault(t)
|
|
|
|
|
defer bCleanup()
|
|
|
|
|
|
|
|
|
|
op, configCleanup, playback := testOperationPlanWithDiagnostics(t, "./testdata/plan")
|
|
|
|
|
op, configCleanup, done := testOperationApply(t, "./testdata/apply")
|
|
|
|
|
defer configCleanup()
|
|
|
|
|
|
|
|
|
|
// Set the tfe client's RemoteAPIVersion to an empty string, to mimic
|
|
|
|
|
@ -362,6 +360,7 @@ func TestRemote_applyWithTargetIncompatibleAPIVersion(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<-run.Done()
|
|
|
|
|
output := done(t)
|
|
|
|
|
if run.Result == backend.OperationSuccess {
|
|
|
|
|
t.Fatal("expected apply operation to fail")
|
|
|
|
|
}
|
|
|
|
|
@ -369,7 +368,7 @@ func TestRemote_applyWithTargetIncompatibleAPIVersion(t *testing.T) {
|
|
|
|
|
t.Fatalf("expected plan to be empty")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
errOutput := playback().Err().Error()
|
|
|
|
|
errOutput := output.Stderr()
|
|
|
|
|
if !strings.Contains(errOutput, "Resource targeting is not supported") {
|
|
|
|
|
t.Fatalf("expected a targeting error, got: %v", errOutput)
|
|
|
|
|
}
|
|
|
|
|
@ -379,7 +378,7 @@ func TestRemote_applyWithVariables(t *testing.T) {
|
|
|
|
|
b, bCleanup := testBackendDefault(t)
|
|
|
|
|
defer bCleanup()
|
|
|
|
|
|
|
|
|
|
op, configCleanup, playback := testOperationApplyWithDiagnostics(t, "./testdata/apply-variables")
|
|
|
|
|
op, configCleanup, done := testOperationApply(t, "./testdata/apply-variables")
|
|
|
|
|
defer configCleanup()
|
|
|
|
|
|
|
|
|
|
op.Variables = testVariables(terraform.ValueFromNamedFile, "foo", "bar")
|
|
|
|
|
@ -391,11 +390,12 @@ func TestRemote_applyWithVariables(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<-run.Done()
|
|
|
|
|
output := done(t)
|
|
|
|
|
if run.Result == backend.OperationSuccess {
|
|
|
|
|
t.Fatal("expected apply operation to fail")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
errOutput := playback().Err().Error()
|
|
|
|
|
errOutput := output.Stderr()
|
|
|
|
|
if !strings.Contains(errOutput, "variables are currently not supported") {
|
|
|
|
|
t.Fatalf("expected a variables error, got: %v", errOutput)
|
|
|
|
|
}
|
|
|
|
|
@ -405,7 +405,7 @@ func TestRemote_applyNoConfig(t *testing.T) {
|
|
|
|
|
b, bCleanup := testBackendDefault(t)
|
|
|
|
|
defer bCleanup()
|
|
|
|
|
|
|
|
|
|
op, configCleanup, playback := testOperationApplyWithDiagnostics(t, "./testdata/empty")
|
|
|
|
|
op, configCleanup, done := testOperationApply(t, "./testdata/empty")
|
|
|
|
|
defer configCleanup()
|
|
|
|
|
|
|
|
|
|
op.Workspace = backend.DefaultStateName
|
|
|
|
|
@ -416,6 +416,7 @@ func TestRemote_applyNoConfig(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<-run.Done()
|
|
|
|
|
output := done(t)
|
|
|
|
|
if run.Result == backend.OperationSuccess {
|
|
|
|
|
t.Fatal("expected apply operation to fail")
|
|
|
|
|
}
|
|
|
|
|
@ -423,7 +424,7 @@ func TestRemote_applyNoConfig(t *testing.T) {
|
|
|
|
|
t.Fatalf("expected plan to be empty")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
errOutput := playback().Err().Error()
|
|
|
|
|
errOutput := output.Stderr()
|
|
|
|
|
if !strings.Contains(errOutput, "configuration files found") {
|
|
|
|
|
t.Fatalf("expected configuration files error, got: %v", errOutput)
|
|
|
|
|
}
|
|
|
|
|
@ -439,8 +440,9 @@ func TestRemote_applyNoChanges(t *testing.T) {
|
|
|
|
|
b, bCleanup := testBackendDefault(t)
|
|
|
|
|
defer bCleanup()
|
|
|
|
|
|
|
|
|
|
op, configCleanup := testOperationApply(t, "./testdata/apply-no-changes")
|
|
|
|
|
op, configCleanup, done := testOperationApply(t, "./testdata/apply-no-changes")
|
|
|
|
|
defer configCleanup()
|
|
|
|
|
defer done(t)
|
|
|
|
|
|
|
|
|
|
op.Workspace = backend.DefaultStateName
|
|
|
|
|
|
|
|
|
|
@ -470,7 +472,7 @@ func TestRemote_applyNoApprove(t *testing.T) {
|
|
|
|
|
b, bCleanup := testBackendDefault(t)
|
|
|
|
|
defer bCleanup()
|
|
|
|
|
|
|
|
|
|
op, configCleanup, playback := testOperationApplyWithDiagnostics(t, "./testdata/apply")
|
|
|
|
|
op, configCleanup, done := testOperationApply(t, "./testdata/apply")
|
|
|
|
|
defer configCleanup()
|
|
|
|
|
|
|
|
|
|
input := testInput(t, map[string]string{
|
|
|
|
|
@ -487,6 +489,7 @@ func TestRemote_applyNoApprove(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<-run.Done()
|
|
|
|
|
output := done(t)
|
|
|
|
|
if run.Result == backend.OperationSuccess {
|
|
|
|
|
t.Fatal("expected apply operation to fail")
|
|
|
|
|
}
|
|
|
|
|
@ -498,7 +501,7 @@ func TestRemote_applyNoApprove(t *testing.T) {
|
|
|
|
|
t.Fatalf("expected no unused answers, got: %v", input.answers)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
errOutput := playback().Err().Error()
|
|
|
|
|
errOutput := output.Stderr()
|
|
|
|
|
if !strings.Contains(errOutput, "Apply discarded") {
|
|
|
|
|
t.Fatalf("expected an apply discarded error, got: %v", errOutput)
|
|
|
|
|
}
|
|
|
|
|
@ -508,8 +511,9 @@ func TestRemote_applyAutoApprove(t *testing.T) {
|
|
|
|
|
b, bCleanup := testBackendDefault(t)
|
|
|
|
|
defer bCleanup()
|
|
|
|
|
|
|
|
|
|
op, configCleanup := testOperationApply(t, "./testdata/apply")
|
|
|
|
|
op, configCleanup, done := testOperationApply(t, "./testdata/apply")
|
|
|
|
|
defer configCleanup()
|
|
|
|
|
defer done(t)
|
|
|
|
|
|
|
|
|
|
input := testInput(t, map[string]string{
|
|
|
|
|
"approve": "no",
|
|
|
|
|
@ -553,8 +557,9 @@ func TestRemote_applyApprovedExternally(t *testing.T) {
|
|
|
|
|
b, bCleanup := testBackendDefault(t)
|
|
|
|
|
defer bCleanup()
|
|
|
|
|
|
|
|
|
|
op, configCleanup := testOperationApply(t, "./testdata/apply")
|
|
|
|
|
op, configCleanup, done := testOperationApply(t, "./testdata/apply")
|
|
|
|
|
defer configCleanup()
|
|
|
|
|
defer done(t)
|
|
|
|
|
|
|
|
|
|
input := testInput(t, map[string]string{
|
|
|
|
|
"approve": "wait-for-external-update",
|
|
|
|
|
@ -628,8 +633,9 @@ func TestRemote_applyDiscardedExternally(t *testing.T) {
|
|
|
|
|
b, bCleanup := testBackendDefault(t)
|
|
|
|
|
defer bCleanup()
|
|
|
|
|
|
|
|
|
|
op, configCleanup := testOperationApply(t, "./testdata/apply")
|
|
|
|
|
op, configCleanup, done := testOperationApply(t, "./testdata/apply")
|
|
|
|
|
defer configCleanup()
|
|
|
|
|
defer done(t)
|
|
|
|
|
|
|
|
|
|
input := testInput(t, map[string]string{
|
|
|
|
|
"approve": "wait-for-external-update",
|
|
|
|
|
@ -716,8 +722,9 @@ func TestRemote_applyWithAutoApply(t *testing.T) {
|
|
|
|
|
t.Fatalf("error creating named workspace: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
op, configCleanup := testOperationApply(t, "./testdata/apply")
|
|
|
|
|
op, configCleanup, done := testOperationApply(t, "./testdata/apply")
|
|
|
|
|
defer configCleanup()
|
|
|
|
|
defer done(t)
|
|
|
|
|
|
|
|
|
|
input := testInput(t, map[string]string{
|
|
|
|
|
"approve": "yes",
|
|
|
|
|
@ -767,8 +774,9 @@ func TestRemote_applyForceLocal(t *testing.T) {
|
|
|
|
|
b, bCleanup := testBackendDefault(t)
|
|
|
|
|
defer bCleanup()
|
|
|
|
|
|
|
|
|
|
op, configCleanup := testOperationApply(t, "./testdata/apply")
|
|
|
|
|
op, configCleanup, done := testOperationApply(t, "./testdata/apply")
|
|
|
|
|
defer configCleanup()
|
|
|
|
|
defer done(t)
|
|
|
|
|
|
|
|
|
|
input := testInput(t, map[string]string{
|
|
|
|
|
"approve": "yes",
|
|
|
|
|
@ -829,8 +837,9 @@ func TestRemote_applyWorkspaceWithoutOperations(t *testing.T) {
|
|
|
|
|
t.Fatalf("error creating named workspace: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
op, configCleanup := testOperationApply(t, "./testdata/apply")
|
|
|
|
|
op, configCleanup, done := testOperationApply(t, "./testdata/apply")
|
|
|
|
|
defer configCleanup()
|
|
|
|
|
defer done(t)
|
|
|
|
|
|
|
|
|
|
input := testInput(t, map[string]string{
|
|
|
|
|
"approve": "yes",
|
|
|
|
|
@ -900,8 +909,9 @@ func TestRemote_applyLockTimeout(t *testing.T) {
|
|
|
|
|
t.Fatalf("error creating pending run: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
op, configCleanup := testOperationApplyWithTimeout(t, "./testdata/apply", 50*time.Millisecond)
|
|
|
|
|
op, configCleanup, done := testOperationApplyWithTimeout(t, "./testdata/apply", 50*time.Millisecond)
|
|
|
|
|
defer configCleanup()
|
|
|
|
|
defer done(t)
|
|
|
|
|
|
|
|
|
|
input := testInput(t, map[string]string{
|
|
|
|
|
"cancel": "yes",
|
|
|
|
|
@ -950,8 +960,9 @@ func TestRemote_applyDestroy(t *testing.T) {
|
|
|
|
|
b, bCleanup := testBackendDefault(t)
|
|
|
|
|
defer bCleanup()
|
|
|
|
|
|
|
|
|
|
op, configCleanup := testOperationApply(t, "./testdata/apply-destroy")
|
|
|
|
|
op, configCleanup, done := testOperationApply(t, "./testdata/apply-destroy")
|
|
|
|
|
defer configCleanup()
|
|
|
|
|
defer done(t)
|
|
|
|
|
|
|
|
|
|
input := testInput(t, map[string]string{
|
|
|
|
|
"approve": "yes",
|
|
|
|
|
@ -999,8 +1010,9 @@ func TestRemote_applyDestroyNoConfig(t *testing.T) {
|
|
|
|
|
"approve": "yes",
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
op, configCleanup := testOperationApply(t, "./testdata/empty")
|
|
|
|
|
op, configCleanup, done := testOperationApply(t, "./testdata/empty")
|
|
|
|
|
defer configCleanup()
|
|
|
|
|
defer done(t)
|
|
|
|
|
|
|
|
|
|
op.Destroy = true
|
|
|
|
|
op.UIIn = input
|
|
|
|
|
@ -1029,8 +1041,9 @@ func TestRemote_applyPolicyPass(t *testing.T) {
|
|
|
|
|
b, bCleanup := testBackendDefault(t)
|
|
|
|
|
defer bCleanup()
|
|
|
|
|
|
|
|
|
|
op, configCleanup := testOperationApply(t, "./testdata/apply-policy-passed")
|
|
|
|
|
op, configCleanup, done := testOperationApply(t, "./testdata/apply-policy-passed")
|
|
|
|
|
defer configCleanup()
|
|
|
|
|
defer done(t)
|
|
|
|
|
|
|
|
|
|
input := testInput(t, map[string]string{
|
|
|
|
|
"approve": "yes",
|
|
|
|
|
@ -1076,7 +1089,7 @@ func TestRemote_applyPolicyHardFail(t *testing.T) {
|
|
|
|
|
b, bCleanup := testBackendDefault(t)
|
|
|
|
|
defer bCleanup()
|
|
|
|
|
|
|
|
|
|
op, configCleanup, playback := testOperationApplyWithDiagnostics(t, "./testdata/apply-policy-hard-failed")
|
|
|
|
|
op, configCleanup, done := testOperationApply(t, "./testdata/apply-policy-hard-failed")
|
|
|
|
|
defer configCleanup()
|
|
|
|
|
|
|
|
|
|
input := testInput(t, map[string]string{
|
|
|
|
|
@ -1093,6 +1106,7 @@ func TestRemote_applyPolicyHardFail(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<-run.Done()
|
|
|
|
|
viewOutput := done(t)
|
|
|
|
|
if run.Result == backend.OperationSuccess {
|
|
|
|
|
t.Fatal("expected apply operation to fail")
|
|
|
|
|
}
|
|
|
|
|
@ -1104,7 +1118,7 @@ func TestRemote_applyPolicyHardFail(t *testing.T) {
|
|
|
|
|
t.Fatalf("expected an unused answers, got: %v", input.answers)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
errOutput := playback().Err().Error()
|
|
|
|
|
errOutput := viewOutput.Stderr()
|
|
|
|
|
if !strings.Contains(errOutput, "hard failed") {
|
|
|
|
|
t.Fatalf("expected a policy check error, got: %v", errOutput)
|
|
|
|
|
}
|
|
|
|
|
@ -1128,8 +1142,9 @@ func TestRemote_applyPolicySoftFail(t *testing.T) {
|
|
|
|
|
b, bCleanup := testBackendDefault(t)
|
|
|
|
|
defer bCleanup()
|
|
|
|
|
|
|
|
|
|
op, configCleanup := testOperationApply(t, "./testdata/apply-policy-soft-failed")
|
|
|
|
|
op, configCleanup, done := testOperationApply(t, "./testdata/apply-policy-soft-failed")
|
|
|
|
|
defer configCleanup()
|
|
|
|
|
defer done(t)
|
|
|
|
|
|
|
|
|
|
input := testInput(t, map[string]string{
|
|
|
|
|
"override": "override",
|
|
|
|
|
@ -1176,7 +1191,7 @@ func TestRemote_applyPolicySoftFailAutoApprove(t *testing.T) {
|
|
|
|
|
b, bCleanup := testBackendDefault(t)
|
|
|
|
|
defer bCleanup()
|
|
|
|
|
|
|
|
|
|
op, configCleanup, playback := testOperationApplyWithDiagnostics(t, "./testdata/apply-policy-soft-failed")
|
|
|
|
|
op, configCleanup, done := testOperationApply(t, "./testdata/apply-policy-soft-failed")
|
|
|
|
|
defer configCleanup()
|
|
|
|
|
|
|
|
|
|
input := testInput(t, map[string]string{
|
|
|
|
|
@ -1194,6 +1209,7 @@ func TestRemote_applyPolicySoftFailAutoApprove(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<-run.Done()
|
|
|
|
|
viewOutput := done(t)
|
|
|
|
|
if run.Result == backend.OperationSuccess {
|
|
|
|
|
t.Fatal("expected apply operation to fail")
|
|
|
|
|
}
|
|
|
|
|
@ -1205,7 +1221,7 @@ func TestRemote_applyPolicySoftFailAutoApprove(t *testing.T) {
|
|
|
|
|
t.Fatalf("expected an unused answers, got: %v", input.answers)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
errOutput := playback().Err().Error()
|
|
|
|
|
errOutput := viewOutput.Stderr()
|
|
|
|
|
if !strings.Contains(errOutput, "soft failed") {
|
|
|
|
|
t.Fatalf("expected a policy check error, got: %v", errOutput)
|
|
|
|
|
}
|
|
|
|
|
@ -1242,8 +1258,9 @@ func TestRemote_applyPolicySoftFailAutoApply(t *testing.T) {
|
|
|
|
|
t.Fatalf("error creating named workspace: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
op, configCleanup := testOperationApply(t, "./testdata/apply-policy-soft-failed")
|
|
|
|
|
op, configCleanup, done := testOperationApply(t, "./testdata/apply-policy-soft-failed")
|
|
|
|
|
defer configCleanup()
|
|
|
|
|
defer done(t)
|
|
|
|
|
|
|
|
|
|
input := testInput(t, map[string]string{
|
|
|
|
|
"override": "override",
|
|
|
|
|
@ -1290,8 +1307,9 @@ func TestRemote_applyWithRemoteError(t *testing.T) {
|
|
|
|
|
b, bCleanup := testBackendDefault(t)
|
|
|
|
|
defer bCleanup()
|
|
|
|
|
|
|
|
|
|
op, configCleanup := testOperationApply(t, "./testdata/apply-with-error")
|
|
|
|
|
op, configCleanup, done := testOperationApply(t, "./testdata/apply-with-error")
|
|
|
|
|
defer configCleanup()
|
|
|
|
|
defer done(t)
|
|
|
|
|
|
|
|
|
|
op.Workspace = backend.DefaultStateName
|
|
|
|
|
|
|
|
|
|
@ -1393,13 +1411,12 @@ func TestRemote_applyVersionCheck(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// RUN: prepare the apply operation and run it
|
|
|
|
|
op, configCleanup, playback := testOperationApplyWithDiagnostics(t, "./testdata/apply")
|
|
|
|
|
op, configCleanup, done := testOperationApply(t, "./testdata/apply")
|
|
|
|
|
defer configCleanup()
|
|
|
|
|
|
|
|
|
|
streams, done := terminal.StreamsForTesting(t)
|
|
|
|
|
view := views.NewOperation(arguments.ViewHuman, false, views.NewView(streams))
|
|
|
|
|
op.View = view
|
|
|
|
|
defer done(t)
|
|
|
|
|
|
|
|
|
|
input := testInput(t, map[string]string{
|
|
|
|
|
"approve": "yes",
|
|
|
|
|
@ -1416,6 +1433,7 @@ func TestRemote_applyVersionCheck(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// RUN: wait for completion
|
|
|
|
|
<-run.Done()
|
|
|
|
|
output := done(t)
|
|
|
|
|
|
|
|
|
|
if tc.wantErr != "" {
|
|
|
|
|
// ASSERT: if the test case wants an error, check for failure
|
|
|
|
|
@ -1423,7 +1441,7 @@ func TestRemote_applyVersionCheck(t *testing.T) {
|
|
|
|
|
if run.Result != backend.OperationFailure {
|
|
|
|
|
t.Fatalf("expected run to fail, but result was %#v", run.Result)
|
|
|
|
|
}
|
|
|
|
|
errOutput := playback().Err().Error()
|
|
|
|
|
errOutput := output.Stderr()
|
|
|
|
|
if !strings.Contains(errOutput, tc.wantErr) {
|
|
|
|
|
t.Fatalf("missing error %q\noutput: %s", tc.wantErr, errOutput)
|
|
|
|
|
}
|
|
|
|
|
|