github.com/opentofu/opentofu@v1.7.1/internal/tofu/transform_module_variable_test.go (about) 1 // Copyright (c) The OpenTofu Authors 2 // SPDX-License-Identifier: MPL-2.0 3 // Copyright (c) 2023 HashiCorp, Inc. 4 // SPDX-License-Identifier: MPL-2.0 5 6 package tofu 7 8 import ( 9 "strings" 10 "testing" 11 12 "github.com/opentofu/opentofu/internal/addrs" 13 ) 14 15 func TestModuleVariableTransformer(t *testing.T) { 16 g := Graph{Path: addrs.RootModuleInstance} 17 module := testModule(t, "transform-module-var-basic") 18 19 { 20 tf := &RootVariableTransformer{Config: module} 21 if err := tf.Transform(&g); err != nil { 22 t.Fatalf("err: %s", err) 23 } 24 } 25 26 { 27 tf := &ModuleVariableTransformer{Config: module} 28 if err := tf.Transform(&g); err != nil { 29 t.Fatalf("err: %s", err) 30 } 31 } 32 33 actual := strings.TrimSpace(g.String()) 34 expected := strings.TrimSpace(testTransformModuleVarBasicStr) 35 if actual != expected { 36 t.Fatalf("bad:\n\n%s", actual) 37 } 38 } 39 40 func TestModuleVariableTransformer_nested(t *testing.T) { 41 g := Graph{Path: addrs.RootModuleInstance} 42 module := testModule(t, "transform-module-var-nested") 43 44 { 45 tf := &RootVariableTransformer{Config: module} 46 if err := tf.Transform(&g); err != nil { 47 t.Fatalf("err: %s", err) 48 } 49 } 50 51 { 52 tf := &ModuleVariableTransformer{Config: module} 53 if err := tf.Transform(&g); err != nil { 54 t.Fatalf("err: %s", err) 55 } 56 } 57 58 actual := strings.TrimSpace(g.String()) 59 expected := strings.TrimSpace(testTransformModuleVarNestedStr) 60 if actual != expected { 61 t.Fatalf("bad:\n\n%s", actual) 62 } 63 } 64 65 const testTransformModuleVarBasicStr = ` 66 module.child.var.value (expand) 67 ` 68 69 const testTransformModuleVarNestedStr = ` 70 module.child.module.child.var.value (expand) 71 module.child.var.value (expand) 72 `