prefer the existing instance ID in tests

The old testApplyFn would overwrite ID with "foo" in all cases there
wasn't a diff, which made the test fixtures harder to reason about. If
there's an ID, keep it the same.
This commit is contained in:
James Bardin 2018-05-30 11:25:28 -04:00 committed by Martin Atkins
parent 1350ed8e3a
commit ec8df26a80
1 changed files with 11 additions and 1 deletions

View File

@ -7,6 +7,7 @@ import (
"time"
"github.com/hashicorp/hil"
"github.com/hashicorp/terraform/config"
"github.com/hashicorp/terraform/config/configschema"
"github.com/hashicorp/terraform/configs"
"github.com/zclconf/go-cty/cty"
@ -187,11 +188,20 @@ func testApplyFn(
return nil, nil
}
id := "foo"
// find the OLD id, which is probably in the ID field for now, but eventually
// ID should only be in one place.
id := s.ID
if id == "" {
id = s.Attributes["id"]
}
if idAttr, ok := d.Attributes["id"]; ok && !idAttr.NewComputed {
id = idAttr.New
}
if id == "" || id == config.UnknownVariableValue {
id = "foo"
}
result := &InstanceState{
ID: id,
Attributes: make(map[string]string),