github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/provider/azure/config_test.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package azure_test 5 6 import ( 7 "github.com/Azure/go-autorest/autorest/mocks" 8 jc "github.com/juju/testing/checkers" 9 gc "gopkg.in/check.v1" 10 11 "github.com/juju/juju/environs" 12 "github.com/juju/juju/environs/config" 13 "github.com/juju/juju/provider/azure" 14 "github.com/juju/juju/testing" 15 ) 16 17 const ( 18 fakeApplicationId = "00000000-0000-0000-0000-000000000000" 19 fakeSubscriptionId = "22222222-2222-2222-2222-222222222222" 20 fakeStorageAccountKey = "quay" 21 ) 22 23 type configSuite struct { 24 testing.BaseSuite 25 26 provider environs.EnvironProvider 27 } 28 29 var _ = gc.Suite(&configSuite{}) 30 31 func (s *configSuite) SetUpTest(c *gc.C) { 32 s.BaseSuite.SetUpTest(c) 33 s.provider = newProvider(c, azure.ProviderConfig{ 34 Sender: mocks.NewSender(), 35 }) 36 } 37 38 func (s *configSuite) TestValidateNew(c *gc.C) { 39 s.assertConfigValid(c, nil) 40 } 41 42 func (s *configSuite) TestValidateInvalidStorageAccountType(c *gc.C) { 43 s.assertConfigInvalid( 44 c, testing.Attrs{"storage-account-type": "savings"}, 45 `invalid storage account type "savings", expected one of: \["Standard_LRS" "Standard_GRS" "Standard_RAGRS" "Standard_ZRS" "Premium_LRS"\]`, 46 ) 47 } 48 49 func (s *configSuite) TestValidateInvalidFirewallMode(c *gc.C) { 50 s.assertConfigInvalid( 51 c, testing.Attrs{"firewall-mode": "global"}, 52 "global firewall mode is not supported", 53 ) 54 } 55 56 func (s *configSuite) TestValidateModelNameLength(c *gc.C) { 57 s.assertConfigInvalid( 58 c, testing.Attrs{"name": "someextremelyoverlylongishmodelname"}, 59 `resource group name "juju-someextremelyoverlylongishmodelname-model-deadbeef-0bad-400d-8000-4b1d0d06f00d" is too long 60 61 Please choose a model name of no more than 32 characters.`) 62 } 63 64 func (s *configSuite) TestValidateStorageAccountTypeCantChange(c *gc.C) { 65 cfgOld := makeTestModelConfig(c, testing.Attrs{"storage-account-type": "Standard_LRS"}) 66 _, err := s.provider.Validate(cfgOld, cfgOld) 67 c.Assert(err, jc.ErrorIsNil) 68 69 cfgNew := makeTestModelConfig(c, testing.Attrs{"storage-account-type": "Premium_LRS"}) 70 _, err = s.provider.Validate(cfgNew, cfgOld) 71 c.Assert(err, gc.ErrorMatches, `cannot change immutable "storage-account-type" config \(Standard_LRS -> Premium_LRS\)`) 72 } 73 74 func (s *configSuite) assertConfigValid(c *gc.C, attrs testing.Attrs) { 75 cfg := makeTestModelConfig(c, attrs) 76 _, err := s.provider.Validate(cfg, nil) 77 c.Assert(err, jc.ErrorIsNil) 78 } 79 80 func (s *configSuite) assertConfigInvalid(c *gc.C, attrs testing.Attrs, expect string) { 81 cfg := makeTestModelConfig(c, attrs) 82 _, err := s.provider.Validate(cfg, nil) 83 c.Assert(err, gc.ErrorMatches, expect) 84 } 85 86 func makeTestModelConfig(c *gc.C, extra ...testing.Attrs) *config.Config { 87 attrs := testing.Attrs{ 88 "type": "azure", 89 "agent-version": "1.2.3", 90 } 91 for _, extra := range extra { 92 attrs = attrs.Merge(extra) 93 } 94 attrs = testing.FakeConfig().Merge(attrs) 95 cfg, err := config.New(config.NoDefaults, attrs) 96 c.Assert(err, jc.ErrorIsNil) 97 return cfg 98 }