Skip to content

Commit fba9698

Browse files
committed
add sad path tests for the API version check
1 parent 2cbc577 commit fba9698

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

backend/remote/backend_apply_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,38 @@ func TestRemote_applyWithTarget(t *testing.T) {
299299
}
300300
}
301301

302+
func TestRemote_applyWithTargetIncompatibleAPIVersion(t *testing.T) {
303+
b, bCleanup := testBackendDefault(t)
304+
b.client.SetFakeRemoteAPIVersion("")
305+
defer bCleanup()
306+
307+
op, configCleanup := testOperationPlan(t, "./testdata/plan")
308+
defer configCleanup()
309+
310+
addr, _ := addrs.ParseAbsResourceStr("null_resource.foo")
311+
312+
op.Targets = []addrs.Targetable{addr}
313+
op.Workspace = backend.DefaultStateName
314+
315+
run, err := b.Operation(context.Background(), op)
316+
if err != nil {
317+
t.Fatalf("error starting operation: %v", err)
318+
}
319+
320+
<-run.Done()
321+
if run.Result == backend.OperationSuccess {
322+
t.Fatal("expected apply operation to fail")
323+
}
324+
if !run.PlanEmpty {
325+
t.Fatalf("expected plan to be empty")
326+
}
327+
328+
errOutput := b.CLI.(*cli.MockUi).ErrorWriter.String()
329+
if !strings.Contains(errOutput, "Resource targeting is not supported") {
330+
t.Fatalf("expected a targeting error, got: %v", errOutput)
331+
}
332+
}
333+
302334
func TestRemote_applyWithVariables(t *testing.T) {
303335
b, bCleanup := testBackendDefault(t)
304336
defer bCleanup()

backend/remote/backend_plan_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,38 @@ func TestRemote_planWithTarget(t *testing.T) {
338338
}
339339
}
340340

341+
func TestRemote_planWithTargetIncompatibleAPIVersion(t *testing.T) {
342+
b, bCleanup := testBackendDefault(t)
343+
b.client.SetFakeRemoteAPIVersion("")
344+
defer bCleanup()
345+
346+
op, configCleanup := testOperationPlan(t, "./testdata/plan")
347+
defer configCleanup()
348+
349+
addr, _ := addrs.ParseAbsResourceStr("null_resource.foo")
350+
351+
op.Targets = []addrs.Targetable{addr}
352+
op.Workspace = backend.DefaultStateName
353+
354+
run, err := b.Operation(context.Background(), op)
355+
if err != nil {
356+
t.Fatalf("error starting operation: %v", err)
357+
}
358+
359+
<-run.Done()
360+
if run.Result == backend.OperationSuccess {
361+
t.Fatal("expected plan operation to fail")
362+
}
363+
if !run.PlanEmpty {
364+
t.Fatalf("expected plan to be empty")
365+
}
366+
367+
errOutput := b.CLI.(*cli.MockUi).ErrorWriter.String()
368+
if !strings.Contains(errOutput, "Resource targeting is not supported") {
369+
t.Fatalf("expected a targeting error, got: %v", errOutput)
370+
}
371+
}
372+
341373
func TestRemote_planWithVariables(t *testing.T) {
342374
b, bCleanup := testBackendDefault(t)
343375
defer bCleanup()

0 commit comments

Comments
 (0)