github.com/hashicorp/terraform-plugin-sdk@v1.17.2/terraform/transform_transitive_reduction_test.go (about) 1 package terraform 2 3 import ( 4 "strings" 5 "testing" 6 7 "github.com/hashicorp/terraform-plugin-sdk/internal/addrs" 8 "github.com/hashicorp/terraform-plugin-sdk/internal/configs/configschema" 9 "github.com/zclconf/go-cty/cty" 10 ) 11 12 func TestTransitiveReductionTransformer(t *testing.T) { 13 mod := testModule(t, "transform-trans-reduce-basic") 14 15 g := Graph{Path: addrs.RootModuleInstance} 16 { 17 tf := &ConfigTransformer{Config: mod} 18 if err := tf.Transform(&g); err != nil { 19 t.Fatalf("err: %s", err) 20 } 21 t.Logf("graph after ConfigTransformer:\n%s", g.String()) 22 } 23 24 { 25 transform := &AttachResourceConfigTransformer{Config: mod} 26 if err := transform.Transform(&g); err != nil { 27 t.Fatalf("err: %s", err) 28 } 29 } 30 31 { 32 transform := &AttachSchemaTransformer{ 33 Schemas: &Schemas{ 34 Providers: map[string]*ProviderSchema{ 35 "aws": { 36 ResourceTypes: map[string]*configschema.Block{ 37 "aws_instance": { 38 Attributes: map[string]*configschema.Attribute{ 39 "A": { 40 Type: cty.String, 41 Optional: true, 42 }, 43 "B": { 44 Type: cty.String, 45 Optional: true, 46 }, 47 }, 48 }, 49 }, 50 }, 51 }, 52 }, 53 } 54 if err := transform.Transform(&g); err != nil { 55 t.Fatalf("err: %s", err) 56 } 57 } 58 59 { 60 transform := &ReferenceTransformer{} 61 if err := transform.Transform(&g); err != nil { 62 t.Fatalf("err: %s", err) 63 } 64 t.Logf("graph after ReferenceTransformer:\n%s", g.String()) 65 } 66 67 { 68 transform := &TransitiveReductionTransformer{} 69 if err := transform.Transform(&g); err != nil { 70 t.Fatalf("err: %s", err) 71 } 72 t.Logf("graph after TransitiveReductionTransformer:\n%s", g.String()) 73 } 74 75 actual := strings.TrimSpace(g.String()) 76 expected := strings.TrimSpace(testTransformTransReduceBasicStr) 77 if actual != expected { 78 t.Errorf("wrong result\ngot:\n%s\n\nwant:\n%s", actual, expected) 79 } 80 } 81 82 const testTransformTransReduceBasicStr = ` 83 aws_instance.A 84 aws_instance.B 85 aws_instance.A 86 aws_instance.C 87 aws_instance.B 88 `