core: Assorted small test fixes

Rebasing the v0.12 dev branch to master caught a few changes that didn't
pass tests afterwards, so this is a catchup commit to fix those.
This commit is contained in:
Martin Atkins 2018-06-26 14:40:12 -07:00
parent cf4a5e6336
commit 2d9c779784
2 changed files with 29 additions and 65 deletions

View File

@ -6658,19 +6658,19 @@ func TestContext2Apply_destroyOutputs(t *testing.T) {
ctx = testContext2(t, &ContextOpts{ ctx = testContext2(t, &ContextOpts{
Destroy: true, Destroy: true,
State: state, State: state,
Module: m, Config: m,
ProviderResolver: ResourceProviderResolverFixed( ProviderResolver: ResourceProviderResolverFixed(
map[string]ResourceProviderFactory{ map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
), ),
}) })
if _, err := ctx.Plan(); err != nil { if _, diags := ctx.Plan(); diags.HasErrors() {
t.Fatal(err) t.Fatal(diags.Err())
} }
if _, err = ctx.Apply(); err != nil { if _, diags := ctx.Apply(); diags.HasErrors() {
t.Fatal(err) t.Fatal(diags.Err())
} }
} }
@ -7489,27 +7489,6 @@ aws_instance.foo:
`) `)
} }
func TestContext2Apply_targetEmpty(t *testing.T) {
m := testModule(t, "apply-targeted")
p := testProvider("aws")
p.ApplyFn = testApplyFn
p.DiffFn = testDiffFn
ctx := testContext2(t, &ContextOpts{
Module: m,
ProviderResolver: ResourceProviderResolverFixed(
map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
),
Targets: []string{""},
})
_, err := ctx.Apply()
if err == nil {
t.Fatalf("should error")
}
}
func TestContext2Apply_targetedCount(t *testing.T) { func TestContext2Apply_targetedCount(t *testing.T) {
m := testModule(t, "apply-targeted-count") m := testModule(t, "apply-targeted-count")
p := testProvider("aws") p := testProvider("aws")
@ -9739,22 +9718,22 @@ func TestContext2Apply_plannedDestroyInterpolatedCount(t *testing.T) {
} }
ctx := testContext2(t, &ContextOpts{ ctx := testContext2(t, &ContextOpts{
Module: m, Config: m,
ProviderResolver: providerResolver, ProviderResolver: providerResolver,
State: s, State: s,
Destroy: true, Destroy: true,
}) })
plan, err := ctx.Plan() plan, diags := ctx.Plan()
if err != nil { if diags.HasErrors() {
t.Fatalf("plan failed: %s", err) t.Fatalf("plan failed: %s", diags.Err())
} }
// We'll marshal and unmarshal the plan here, to ensure that we have // We'll marshal and unmarshal the plan here, to ensure that we have
// a clean new context as would be created if we separately ran // a clean new context as would be created if we separately ran
// terraform plan -out=tfplan && terraform apply tfplan // terraform plan -out=tfplan && terraform apply tfplan
var planBuf bytes.Buffer var planBuf bytes.Buffer
err = WritePlan(plan, &planBuf) err := WritePlan(plan, &planBuf)
if err != nil { if err != nil {
t.Fatalf("failed to write plan: %s", err) t.Fatalf("failed to write plan: %s", err)
} }
@ -9763,18 +9742,18 @@ func TestContext2Apply_plannedDestroyInterpolatedCount(t *testing.T) {
t.Fatalf("failed to read plan: %s", err) t.Fatalf("failed to read plan: %s", err)
} }
ctx, err = plan.Context(&ContextOpts{ ctx, diags = plan.Context(&ContextOpts{
ProviderResolver: providerResolver, ProviderResolver: providerResolver,
Destroy: true, Destroy: true,
}) })
if err != nil { if diags.HasErrors() {
t.Fatalf("failed to create context for plan: %s", err) t.Fatalf("failed to create context for plan: %s", diags.Err())
} }
// Applying the plan should now succeed // Applying the plan should now succeed
_, err = ctx.Apply() _, diags = ctx.Apply()
if err != nil { if diags.HasErrors() {
t.Fatalf("apply failed: %s", err) t.Fatalf("apply failed: %s", diags.Err())
} }
} }
@ -9819,20 +9798,25 @@ func TestContext2Apply_scaleInMultivarRef(t *testing.T) {
} }
ctx := testContext2(t, &ContextOpts{ ctx := testContext2(t, &ContextOpts{
Module: m, Config: m,
ProviderResolver: providerResolver, ProviderResolver: providerResolver,
State: s, State: s,
Variables: map[string]interface{}{"count": "0"}, Variables: InputValues{
"count": {
Value: cty.NumberIntVal(0),
SourceType: ValueFromCaller,
},
},
}) })
_, err := ctx.Plan() _, diags := ctx.Plan()
if err != nil { if diags.HasErrors() {
t.Fatalf("plan failed: %s", err) t.Fatalf("plan failed: %s", diags.Err())
} }
// Applying the plan should now succeed // Applying the plan should now succeed
_, err = ctx.Apply() _, diags = ctx.Apply()
if err != nil { if diags.HasErrors() {
t.Fatalf("apply failed: %s", err) t.Fatalf("apply failed: %s", diags.Err())
} }
} }

View File

@ -2973,26 +2973,6 @@ STATE:
} }
} }
func TestContext2Plan_targetEmpty(t *testing.T) {
m := testModule(t, "plan-targeted")
p := testProvider("aws")
p.DiffFn = testDiffFn
ctx := testContext2(t, &ContextOpts{
Module: m,
ProviderResolver: ResourceProviderResolverFixed(
map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
),
Targets: []string{""},
})
_, err := ctx.Plan()
if err == nil {
t.Fatal("should error")
}
}
// Test that targeting a module properly plans any inputs that depend // Test that targeting a module properly plans any inputs that depend
// on another module. // on another module.
func TestContext2Plan_targetedCrossModule(t *testing.T) { func TestContext2Plan_targetedCrossModule(t *testing.T) {