github.com/graywolf-at-work-2/terraform-vendor@v1.4.5/internal/lang/globalref/analyzer_test.go (about) 1 package globalref 2 3 import ( 4 "context" 5 "path/filepath" 6 "testing" 7 8 "github.com/hashicorp/terraform/internal/addrs" 9 "github.com/hashicorp/terraform/internal/configs/configload" 10 "github.com/hashicorp/terraform/internal/configs/configschema" 11 "github.com/hashicorp/terraform/internal/initwd" 12 "github.com/hashicorp/terraform/internal/providers" 13 "github.com/hashicorp/terraform/internal/registry" 14 "github.com/zclconf/go-cty/cty" 15 ) 16 17 func testAnalyzer(t *testing.T, fixtureName string) *Analyzer { 18 configDir := filepath.Join("testdata", fixtureName) 19 20 loader, cleanup := configload.NewLoaderForTests(t) 21 defer cleanup() 22 23 inst := initwd.NewModuleInstaller(loader.ModulesDir(), registry.NewClient(nil, nil)) 24 _, instDiags := inst.InstallModules(context.Background(), configDir, true, initwd.ModuleInstallHooksImpl{}) 25 if instDiags.HasErrors() { 26 t.Fatalf("unexpected module installation errors: %s", instDiags.Err().Error()) 27 } 28 if err := loader.RefreshModules(); err != nil { 29 t.Fatalf("failed to refresh modules after install: %s", err) 30 } 31 32 cfg, loadDiags := loader.LoadConfig(configDir) 33 if loadDiags.HasErrors() { 34 t.Fatalf("unexpected configuration errors: %s", loadDiags.Error()) 35 } 36 37 resourceTypeSchema := &configschema.Block{ 38 Attributes: map[string]*configschema.Attribute{ 39 "string": {Type: cty.String, Optional: true}, 40 "number": {Type: cty.Number, Optional: true}, 41 "any": {Type: cty.DynamicPseudoType, Optional: true}, 42 }, 43 BlockTypes: map[string]*configschema.NestedBlock{ 44 "single": { 45 Nesting: configschema.NestingSingle, 46 Block: configschema.Block{ 47 Attributes: map[string]*configschema.Attribute{ 48 "z": {Type: cty.String, Optional: true}, 49 }, 50 }, 51 }, 52 "group": { 53 Nesting: configschema.NestingGroup, 54 Block: configschema.Block{ 55 Attributes: map[string]*configschema.Attribute{ 56 "z": {Type: cty.String, Optional: true}, 57 }, 58 }, 59 }, 60 "list": { 61 Nesting: configschema.NestingList, 62 Block: configschema.Block{ 63 Attributes: map[string]*configschema.Attribute{ 64 "z": {Type: cty.String, Optional: true}, 65 }, 66 }, 67 }, 68 "map": { 69 Nesting: configschema.NestingMap, 70 Block: configschema.Block{ 71 Attributes: map[string]*configschema.Attribute{ 72 "z": {Type: cty.String, Optional: true}, 73 }, 74 }, 75 }, 76 "set": { 77 Nesting: configschema.NestingSet, 78 Block: configschema.Block{ 79 Attributes: map[string]*configschema.Attribute{ 80 "z": {Type: cty.String, Optional: true}, 81 }, 82 }, 83 }, 84 }, 85 } 86 schemas := map[addrs.Provider]*providers.Schemas{ 87 addrs.MustParseProviderSourceString("hashicorp/test"): { 88 ResourceTypes: map[string]*configschema.Block{ 89 "test_thing": resourceTypeSchema, 90 }, 91 DataSources: map[string]*configschema.Block{ 92 "test_thing": resourceTypeSchema, 93 }, 94 }, 95 } 96 97 return NewAnalyzer(cfg, schemas) 98 }