github.com/hashicorp/terraform-plugin-sdk@v1.17.2/terraform/context_components_test.go (about) 1 package terraform 2 3 import ( 4 "github.com/zclconf/go-cty/cty" 5 6 "github.com/hashicorp/terraform-plugin-sdk/internal/configs/configschema" 7 "github.com/hashicorp/terraform-plugin-sdk/internal/providers" 8 "github.com/hashicorp/terraform-plugin-sdk/internal/provisioners" 9 ) 10 11 // simpleMockComponentFactory returns a component factory pre-configured with 12 // one provider and one provisioner, both called "test". 13 // 14 // The provider is built with simpleMockProvider and the provisioner with 15 // simpleMockProvisioner, and all schemas used in both are as built by 16 // function simpleTestSchema. 17 // 18 // Each call to this function produces an entirely-separate set of objects, 19 // so the caller can feel free to modify the returned value to further 20 // customize the mocks contained within. 21 func simpleMockComponentFactory() *basicComponentFactory { 22 // We create these out here, rather than in the factory functions below, 23 // because we want each call to the factory to return the _same_ instance, 24 // so that test code can customize it before passing this component 25 // factory into real code under test. 26 provider := simpleMockProvider() 27 provisioner := simpleMockProvisioner() 28 return &basicComponentFactory{ 29 providers: map[string]providers.Factory{ 30 "test": func() (providers.Interface, error) { 31 return provider, nil 32 }, 33 }, 34 provisioners: map[string]ProvisionerFactory{ 35 "test": func() (provisioners.Interface, error) { 36 return provisioner, nil 37 }, 38 }, 39 } 40 41 } 42 43 // simpleTestSchema returns a block schema that contains a few optional 44 // attributes for use in tests. 45 // 46 // The returned schema contains the following optional attributes: 47 // 48 // test_string, of type string 49 // test_number, of type number 50 // test_bool, of type bool 51 // test_list, of type list(string) 52 // test_map, of type map(string) 53 // 54 // Each call to this function produces an entirely new schema instance, so 55 // callers can feel free to modify it once returned. 56 func simpleTestSchema() *configschema.Block { 57 return &configschema.Block{ 58 Attributes: map[string]*configschema.Attribute{ 59 "test_string": { 60 Type: cty.String, 61 Optional: true, 62 }, 63 "test_number": { 64 Type: cty.String, 65 Optional: true, 66 }, 67 "test_bool": { 68 Type: cty.String, 69 Optional: true, 70 }, 71 "test_list": { 72 Type: cty.String, 73 Optional: true, 74 }, 75 "test_map": { 76 Type: cty.String, 77 Optional: true, 78 }, 79 }, 80 } 81 }