1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
// Copyright 2016 Canonical Ltd.
// Licensed under the LGPLv3, see LICENCE file for details.
package names_test
import (
gc "gopkg.in/check.v1"
"github.com/juju/names/v4"
)
type cloudSuite struct{}
var _ = gc.Suite(&cloudSuite{})
func (s *cloudSuite) TestCloudTag(c *gc.C) {
for i, t := range []struct {
input string
string string
}{
{
input: "bob",
string: "cloud-bob",
},
} {
c.Logf("test %d: %s", i, t.input)
cloudTag := names.NewCloudTag(t.input)
c.Check(cloudTag.String(), gc.Equals, t.string)
c.Check(cloudTag.Id(), gc.Equals, t.input)
}
}
func (s *cloudSuite) TestIsValidCloud(c *gc.C) {
for i, t := range []struct {
string string
expect bool
}{
{"", false},
{"bob", true},
{"Bob", true},
{"bOB", true},
{"b^b", false},
{"bob1", true},
{"bob-1", true},
{"bob.1", true},
{"1bob", true},
{"1-bob", true},
{"1+bob", false},
{"1.bob", true},
{"a", true},
{"0foo", true},
{"foo bar", false},
{"bar{}", false},
{"bar+foo", false},
{"bar_foo", true},
{"bar_", true},
{"bar!", false},
{"bar^", false},
{"bar*", false},
{"foo=bar", false},
{"foo?", false},
{"[bar]", false},
{"'foo'", false},
{"%bar", false},
{"&bar", false},
{"#1foo", false},
{"bar@", false},
{"@local", false},
{"not/valid", false},
} {
c.Logf("test %d: %s", i, t.string)
c.Assert(names.IsValidCloud(t.string), gc.Equals, t.expect, gc.Commentf("%s", t.string))
}
}
func (s *cloudSuite) TestParseCloudTag(c *gc.C) {
for i, t := range []struct {
tag string
expected names.Tag
err error
}{{
tag: "",
err: names.InvalidTagError("", ""),
}, {
tag: "cloud-aws",
expected: names.NewCloudTag("aws"),
}, {
tag: "aws",
err: names.InvalidTagError("aws", ""),
}, {
tag: "unit-aws",
err: names.InvalidTagError("unit-aws", names.UnitTagKind), // not a valid unit name either
}, {
tag: "application-aws",
err: names.InvalidTagError("application-aws", names.CloudTagKind),
}} {
c.Logf("test %d: %s", i, t.tag)
got, err := names.ParseCloudTag(t.tag)
if err != nil || t.err != nil {
c.Check(err, gc.DeepEquals, t.err)
continue
}
c.Check(got, gc.FitsTypeOf, t.expected)
c.Check(got, gc.Equals, t.expected)
}
}
|