github.com/ibm-cloud/terraform@v0.6.4-0.20170726051544-8872b87621df/terraform/node_resource_destroy_test.go (about) 1 package terraform 2 3 import ( 4 "strings" 5 "sync" 6 "testing" 7 ) 8 9 func TestNodeDestroyResourceDynamicExpand_deposedCount(t *testing.T) { 10 var stateLock sync.RWMutex 11 state := &State{ 12 Modules: []*ModuleState{ 13 &ModuleState{ 14 Path: rootModulePath, 15 Resources: map[string]*ResourceState{ 16 "aws_instance.bar.0": &ResourceState{ 17 Type: "aws_instance", 18 Deposed: []*InstanceState{ 19 &InstanceState{ 20 ID: "foo", 21 }, 22 }, 23 }, 24 "aws_instance.bar.1": &ResourceState{ 25 Type: "aws_instance", 26 Deposed: []*InstanceState{ 27 &InstanceState{ 28 ID: "bar", 29 }, 30 }, 31 }, 32 }, 33 }, 34 }, 35 } 36 37 addr, err := parseResourceAddressInternal("aws_instance.bar.0") 38 if err != nil { 39 t.Fatalf("err: %s", err) 40 } 41 42 m := testModule(t, "apply-cbd-count") 43 n := &NodeDestroyResource{ 44 NodeAbstractResource: &NodeAbstractResource{ 45 Addr: addr, 46 ResourceState: state.Modules[0].Resources["aws_instance.bar.0"], 47 Config: m.Config().Resources[0], 48 }, 49 } 50 51 g, err := n.DynamicExpand(&MockEvalContext{ 52 PathPath: []string{"root"}, 53 StateState: state, 54 StateLock: &stateLock, 55 }) 56 if err != nil { 57 t.Fatalf("err: %s", err) 58 } 59 60 actual := strings.TrimSpace(g.String()) 61 expected := strings.TrimSpace(` 62 aws_instance.bar.0 (deposed #0) 63 `) 64 if actual != expected { 65 t.Fatalf("bad:\n\n%s", actual) 66 } 67 }