core: Fix TestContext2Apply_issue7824

This test was incorrectly amended on the first pass to create a
configuration snapshot from the step zero configuration, rather than the
step one configuration that the save plan is built from.

Along with that, it needed various other minor updates to match with
details that have shifted:
- "id" and "type" attributes must be explicitly declared in schema
- template_file.parent has count = 1, which now causes it to get an index
  and be a list where before it did not.
This commit is contained in:
Martin Atkins 2018-09-26 11:40:32 -07:00
parent 49fa2b3f35
commit f88b4fd1f4
1 changed files with 12 additions and 9 deletions

View File

@ -8658,7 +8658,8 @@ func TestContext2Apply_issue7824(t *testing.T) {
}
}
// GH-5254
// This deals with the situation where a splat expression is used referring
// to another resource whose count is non-constant.
func TestContext2Apply_issue5254(t *testing.T) {
// Create a provider. We use "template" here just to match the repro
// we got from the issue itself.
@ -8671,16 +8672,16 @@ func TestContext2Apply_issue5254(t *testing.T) {
Attributes: map[string]*configschema.Attribute{
"template": {Type: cty.String, Optional: true},
"__template_requires_new": {Type: cty.Bool, Optional: true},
"id": {Type: cty.String, Computed: true},
"type": {Type: cty.String, Computed: true},
},
},
},
}
m, snap := testModuleWithSnapshot(t, "issue-5254/step-0")
// Apply cleanly step 0
ctx := testContext2(t, &ContextOpts{
Config: m,
Config: testModule(t, "issue-5254/step-0"),
ProviderResolver: providers.ResolverFixed(
map[string]providers.Factory{
"template": testProviderFuncFixed(p),
@ -8698,9 +8699,11 @@ func TestContext2Apply_issue5254(t *testing.T) {
t.Fatalf("err: %s", diags.Err())
}
m, snap := testModuleWithSnapshot(t, "issue-5254/step-1")
// Application success. Now make the modification and store a plan
ctx = testContext2(t, &ContextOpts{
Config: testModule(t, "issue-5254/step-1"),
Config: m,
State: state,
ProviderResolver: providers.ResolverFixed(
map[string]providers.Factory{
@ -8744,15 +8747,15 @@ template_file.child:
type = template_file
Dependencies:
template_file.parent.*
template_file.parent:
template_file.parent
template_file.parent.0:
ID = foo
provider = provider.template
template = Hi
type = template_file
`)
`)
if actual != expected {
t.Fatalf("expected state: \n%s\ngot: \n%s", expected, actual)
t.Fatalf("wrong final state\ngot:\n%s\n\nwant:\n%s", actual, expected)
}
}