github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/core/migration/targetinfo_test.go (about) 1 // Copyright 2016 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package migration_test 5 6 import ( 7 "github.com/juju/errors" 8 "github.com/juju/names" 9 jc "github.com/juju/testing/checkers" 10 "github.com/juju/utils" 11 gc "gopkg.in/check.v1" 12 13 "github.com/juju/juju/core/migration" 14 coretesting "github.com/juju/juju/testing" 15 ) 16 17 type TargetInfoSuite struct { 18 coretesting.BaseSuite 19 } 20 21 var _ = gc.Suite(new(TargetInfoSuite)) 22 23 func (s *TargetInfoSuite) TestValidation(c *gc.C) { 24 tests := []struct { 25 label string 26 tweakInfo func(*migration.TargetInfo) 27 errorPattern string 28 }{{ 29 "empty ControllerTag", 30 func(info *migration.TargetInfo) { 31 info.ControllerTag = names.NewModelTag("fooo") 32 }, 33 "ControllerTag not valid", 34 }, { 35 "invalid ControllerTag", 36 func(info *migration.TargetInfo) { 37 info.ControllerTag = names.NewModelTag("") 38 }, 39 "ControllerTag not valid", 40 }, { 41 "empty Addrs", 42 func(info *migration.TargetInfo) { 43 info.Addrs = []string{} 44 }, 45 "empty Addrs not valid", 46 }, { 47 "invalid Addrs", 48 func(info *migration.TargetInfo) { 49 info.Addrs = []string{"1.2.3.4:555", "abc"} 50 }, 51 `"abc" in Addrs not valid`, 52 }, { 53 "CACert", 54 func(info *migration.TargetInfo) { 55 info.CACert = "" 56 }, 57 "empty CACert not valid", 58 }, { 59 "AuthTag", 60 func(info *migration.TargetInfo) { 61 info.AuthTag = names.UserTag{} 62 }, 63 "empty AuthTag not valid", 64 }, { 65 "Password", 66 func(info *migration.TargetInfo) { 67 info.Password = "" 68 }, 69 "empty Password not valid", 70 }, { 71 "Success", 72 func(*migration.TargetInfo) {}, 73 "", 74 }} 75 76 modelTag := names.NewModelTag(utils.MustNewUUID().String()) 77 for _, test := range tests { 78 c.Logf("---- %s -----------", test.label) 79 80 info := migration.TargetInfo{ 81 ControllerTag: modelTag, 82 Addrs: []string{"1.2.3.4:5555", "4.3.2.1:6666"}, 83 CACert: "cert", 84 AuthTag: names.NewUserTag("user"), 85 Password: "password", 86 } 87 test.tweakInfo(&info) 88 89 err := info.Validate() 90 if test.errorPattern == "" { 91 c.Check(err, jc.ErrorIsNil) 92 } else { 93 c.Check(errors.IsNotValid(err), jc.IsTrue) 94 c.Check(err, gc.ErrorMatches, test.errorPattern) 95 } 96 } 97 }