github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/state/testing/policy.go (about) 1 // Copyright 2014 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package testing 5 6 import ( 7 "github.com/juju/errors" 8 "github.com/juju/schema" 9 "gopkg.in/juju/environschema.v1" 10 11 "github.com/juju/juju/constraints" 12 "github.com/juju/juju/environs/config" 13 "github.com/juju/juju/instance" 14 "github.com/juju/juju/state" 15 "github.com/juju/juju/storage" 16 ) 17 18 type MockPolicy struct { 19 GetPrechecker func() (state.Prechecker, error) 20 GetConfigValidator func() (config.Validator, error) 21 GetProviderConfigSchemaSource func() (config.ConfigSchemaSource, error) 22 GetConstraintsValidator func() (constraints.Validator, error) 23 GetInstanceDistributor func() (instance.Distributor, error) 24 GetStorageProviderRegistry func() (storage.ProviderRegistry, error) 25 } 26 27 func (p *MockPolicy) Prechecker() (state.Prechecker, error) { 28 if p.GetPrechecker != nil { 29 return p.GetPrechecker() 30 } 31 return nil, errors.NotImplementedf("Prechecker") 32 } 33 34 func (p *MockPolicy) ConfigValidator() (config.Validator, error) { 35 if p.GetConfigValidator != nil { 36 return p.GetConfigValidator() 37 } 38 return nil, errors.NotImplementedf("ConfigValidator") 39 } 40 41 func (p *MockPolicy) ConstraintsValidator() (constraints.Validator, error) { 42 if p.GetConstraintsValidator != nil { 43 return p.GetConstraintsValidator() 44 } 45 return nil, errors.NotImplementedf("ConstraintsValidator") 46 } 47 48 func (p *MockPolicy) InstanceDistributor() (instance.Distributor, error) { 49 if p.GetInstanceDistributor != nil { 50 return p.GetInstanceDistributor() 51 } 52 return nil, errors.NotImplementedf("InstanceDistributor") 53 } 54 55 func (p *MockPolicy) StorageProviderRegistry() (storage.ProviderRegistry, error) { 56 if p.GetStorageProviderRegistry != nil { 57 return p.GetStorageProviderRegistry() 58 } 59 return nil, errors.NotImplementedf("StorageProviderRegistry") 60 } 61 62 func (p *MockPolicy) ProviderConfigSchemaSource() (config.ConfigSchemaSource, error) { 63 if p.GetProviderConfigSchemaSource != nil { 64 return p.GetProviderConfigSchemaSource() 65 } 66 return nil, errors.NotImplementedf("ProviderConfigSchemaSource") 67 } 68 69 type MockConfigSchemaSource struct{} 70 71 func (m *MockConfigSchemaSource) ConfigSchema() schema.Fields { 72 configSchema := environschema.Fields{ 73 "providerAttr": { 74 Type: environschema.Tstring, 75 }, 76 } 77 fs, _, err := configSchema.ValidationSchema() 78 if err != nil { 79 panic(err) 80 } 81 return fs 82 } 83 84 func (m *MockConfigSchemaSource) ConfigDefaults() schema.Defaults { 85 return schema.Defaults{ 86 "providerAttr": "vulch", 87 } 88 }