~juju-qa/ubuntu/xenial/juju/xenial-2.0-beta3

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/core/modelmigration/targetinfo_test.go

  • Committer: Martin Packman
  • Date: 2016-03-30 19:31:08 UTC
  • mfrom: (1.1.41)
  • Revision ID: martin.packman@canonical.com-20160330193108-h9iz3ak334uk0z5r
Merge new upstream source 2.0~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright 2016 Canonical Ltd.
2
 
// Licensed under the AGPLv3, see LICENCE file for details.
3
 
 
4
 
package modelmigration_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
 
        migration "github.com/juju/juju/core/modelmigration"
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
 
                "EntityTag",
60
 
                func(info *migration.TargetInfo) {
61
 
                        info.EntityTag = names.NewMachineTag("")
62
 
                },
63
 
                "empty EntityTag 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
 
                        EntityTag:     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
 
}