-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathcharm_test.go
115 lines (101 loc) · 3.02 KB
/
charm_test.go
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
107
108
109
110
111
112
113
114
115
// Copyright 2014 Canonical Ltd.
// Licensed under the LGPLv3, see LICENCE file for details.
package names_test
import (
"fmt"
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
"github.com/juju/names/v5"
)
type charmSuite struct{}
var _ = gc.Suite(&charmSuite{})
var validCharmURLs = []string{"charm",
// V1 charm urls.
"local:charm",
"local:charm--1",
"local:charm-1",
"local:series/charm",
"local:series/charm-3",
"local:series/charm-0",
"cs:~user/charm",
"cs:~user/charm-1",
"cs:~user/series/charm",
"cs:~user/series/charm-1",
"cs:series/charm",
"cs:series/charm-with-long-name",
"cs:series/charm-3",
"cs:series/charm-0",
"cs:charm",
"cs:charm--1",
"cs:charm-1",
"charm",
"charm-1",
"series/charm",
"series/charm-1",
// V3 charm urls.
"local:charm-with-long2-name/series/2",
"local:charm-with-long2-name/series",
"local:charm-with-long2-name/2",
"cs:user/charm-with-long-name/series/2",
"cs:charm-with-long2-name/series/2",
"cs:user/charm-with-long-name/2",
"cs:user/charm-with-long-name/series",
"cs:charm-with-long-name/2",
"cs:charm-with-long-name/series",
"cs:user/charm-with-long-name",
"user/charm-with-long-name/series/2",
"charm-with-long2-name/series/2",
"user/charm-with-long-name/2",
"user/charm-with-long-name/series",
"charm-with-long-name/2",
"charm-with-long-name/series",
"user/charm-with-long-name",
}
func (s *charmSuite) TestValidCharmURLs(c *gc.C) {
for _, url := range validCharmURLs {
c.Logf("Processing tag %q", url)
c.Assert(names.IsValidCharm(url), jc.IsTrue)
}
}
func (s *charmSuite) TestInvalidCharmURLs(c *gc.C) {
invalidURLs := []string{"",
"local:~user/charm", // false: user on local
"local:~user/series/charm", // false: user on local
"local:~user/series/charm-1", // false: user on local
"local:charm--2", // false: only -1 is a valid negative revision
"blah:charm-2", // false: invalid schema
"local:series/charm-01", // false: revision is funny
"local:user/name/series/2", // false: local charms can't have users
}
for _, url := range invalidURLs {
c.Logf("Processing tag %q", url)
c.Assert(names.IsValidCharm(url), jc.IsFalse)
}
}
func (s *charmSuite) TestParseCharmTagValid(c *gc.C) {
for _, tag := range validCharmURLs {
c.Logf("Processing tag %q", tag)
s.assertParseCharmTagValid(c, fmt.Sprintf("charm-%v", tag), names.NewCharmTag(tag))
}
}
func (s *charmSuite) TestParseCharmTagInvalid(c *gc.C) {
invalidTags := []string{"",
"blah",
"charm",
"user-blah",
}
for _, aTag := range invalidTags {
c.Logf("Processing tag %q", aTag)
s.assertParseCharmTagInvalid(c, aTag)
}
}
func (s *charmSuite) assertParseCharmTagValid(c *gc.C, tag string, expected names.Tag) {
got, err := names.ParseCharmTag(tag)
c.Assert(err, jc.ErrorIsNil)
c.Check(got, gc.FitsTypeOf, expected)
c.Check(got, gc.Equals, expected)
}
func (s *charmSuite) assertParseCharmTagInvalid(c *gc.C, tag string) {
_, err := names.ParseCharmTag(tag)
c.Check(err, gc.ErrorMatches, fmt.Sprintf(".*%q is not a valid.*", tag))
}