core: Add resource count scale-out EvalTree test

This test ensures that the right EvalSequence gets set for a refresh
node with no state. This will ultimately assert that nodes on scale out
will not go down the regular refresh path, which would result in an
error due to the nil state - instead, we stub this node so that we get a
diff on it that can be used to effect computed/unknown values on
interpolations that may depend on this node.
This commit is contained in:
Chris Marchesi 2017-06-22 03:44:16 -07:00
parent 42ebbc6e0e
commit 01e3386e13
1 changed files with 80 additions and 0 deletions

View File

@ -1,8 +1,11 @@
package terraform
import (
"reflect"
"sync"
"testing"
"github.com/davecgh/go-spew/spew"
)
func TestNodeRefreshableManagedResourceDynamicExpand_scaleOut(t *testing.T) {
@ -152,3 +155,80 @@ root - terraform.graphNodeRoot
t.Fatalf("Expected:\n%s\nGot:\n%s", expected, actual)
}
}
func TestNodeRefreshableManagedResourceEvalTree_scaleOut(t *testing.T) {
var provider ResourceProvider
var state *InstanceState
var resourceConfig *ResourceConfig
addr, err := ParseResourceAddress("aws_instance.foo[2]")
if err != nil {
t.Fatalf("bad: %s", err)
}
m := testModule(t, "refresh-resource-scale-inout")
n := &NodeRefreshableManagedResourceInstance{
NodeAbstractResource: &NodeAbstractResource{
Addr: addr,
Config: m.Config().Resources[0],
},
}
actual := n.EvalTree()
expected := &EvalSequence{
Nodes: []EvalNode{
&EvalInterpolate{
Config: n.Config.RawConfig.Copy(),
Resource: &Resource{
Name: addr.Name,
Type: addr.Type,
CountIndex: addr.Index,
},
Output: &resourceConfig,
},
&EvalGetProvider{
Name: n.ProvidedBy()[0],
Output: &provider,
},
&EvalValidateResource{
Provider: &provider,
Config: &resourceConfig,
ResourceName: n.Config.Name,
ResourceType: n.Config.Type,
ResourceMode: n.Config.Mode,
IgnoreWarnings: true,
},
&EvalReadState{
Name: addr.stateId(),
Output: &state,
},
&EvalDiff{
Name: addr.stateId(),
Info: &InstanceInfo{
Id: addr.stateId(),
Type: addr.Type,
ModulePath: normalizeModulePath(addr.Path),
},
Config: &resourceConfig,
Resource: n.Config,
Provider: &provider,
State: &state,
OutputState: &state,
Stub: true,
},
&EvalWriteState{
Name: addr.stateId(),
ResourceType: n.Config.Type,
Provider: n.Config.Provider,
Dependencies: n.StateReferences(),
State: &state,
},
},
}
if !reflect.DeepEqual(expected, actual) {
t.Fatalf("Expected:\n\n%s\nGot:\n\n%s\n", spew.Sdump(expected), spew.Sdump(actual))
}
}