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