LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2013 Canonical Ltd. | 1 // Copyright 2013 Canonical Ltd. |
2 // Licensed under the AGPLv3, see LICENCE file for details. | 2 // Licensed under the AGPLv3, see LICENCE file for details. |
3 | 3 |
4 package names_test | 4 package names_test |
5 | 5 |
6 import ( | 6 import ( |
7 gc "launchpad.net/gocheck" | 7 gc "launchpad.net/gocheck" |
8 | 8 |
9 "launchpad.net/juju-core/names" | 9 "launchpad.net/juju-core/names" |
10 ) | 10 ) |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 } | 120 } |
121 | 121 |
122 func (*tagSuite) TestParseTag(c *gc.C) { | 122 func (*tagSuite) TestParseTag(c *gc.C) { |
123 for i, test := range parseTagTests { | 123 for i, test := range parseTagTests { |
124 c.Logf("test %d: %q expectKind %q", i, test.tag, test.expectKind
) | 124 c.Logf("test %d: %q expectKind %q", i, test.tag, test.expectKind
) |
125 kind, id, err := names.ParseTag(test.tag, test.expectKind) | 125 kind, id, err := names.ParseTag(test.tag, test.expectKind) |
126 if test.resultErr != "" { | 126 if test.resultErr != "" { |
127 c.Assert(err, gc.ErrorMatches, test.resultErr) | 127 c.Assert(err, gc.ErrorMatches, test.resultErr) |
128 c.Assert(kind, gc.Equals, "") | 128 c.Assert(kind, gc.Equals, "") |
129 c.Assert(id, gc.Equals, "") | 129 c.Assert(id, gc.Equals, "") |
| 130 |
| 131 // If the tag has a valid kind which matches the |
| 132 // expected kind, test that using an empty |
| 133 // expectKind does not change the error message. |
| 134 if tagKind, err := names.TagKind(test.tag); err == nil &
& tagKind == test.expectKind { |
| 135 kind, id, err := names.ParseTag(test.tag, "") |
| 136 c.Assert(err, gc.ErrorMatches, test.resultErr) |
| 137 c.Assert(kind, gc.Equals, "") |
| 138 c.Assert(id, gc.Equals, "") |
| 139 } |
130 } else { | 140 } else { |
131 c.Assert(err, gc.IsNil) | 141 c.Assert(err, gc.IsNil) |
132 c.Assert(id, gc.Equals, test.resultId) | 142 c.Assert(id, gc.Equals, test.resultId) |
133 if test.expectKind != "" { | 143 if test.expectKind != "" { |
134 c.Assert(kind, gc.Equals, test.expectKind) | 144 c.Assert(kind, gc.Equals, test.expectKind) |
135 } else { | 145 } else { |
136 expectKind, err := names.TagKind(test.tag) | 146 expectKind, err := names.TagKind(test.tag) |
137 c.Assert(err, gc.IsNil) | 147 c.Assert(err, gc.IsNil) |
138 c.Assert(kind, gc.Equals, expectKind) | 148 c.Assert(kind, gc.Equals, expectKind) |
139 } | 149 } |
140 // Check that it's reversible. | 150 // Check that it's reversible. |
141 if f := makeTag[kind]; f != nil { | 151 if f := makeTag[kind]; f != nil { |
142 reversed := f(id) | 152 reversed := f(id) |
143 c.Assert(reversed, gc.Equals, test.tag) | 153 c.Assert(reversed, gc.Equals, test.tag) |
144 } | 154 } |
145 // Check that it parses ok without an expectKind. | 155 // Check that it parses ok without an expectKind. |
146 kind1, id1, err1 := names.ParseTag(test.tag, "") | 156 kind1, id1, err1 := names.ParseTag(test.tag, "") |
147 c.Assert(err1, gc.IsNil) | 157 c.Assert(err1, gc.IsNil) |
148 c.Assert(kind1, gc.Equals, test.expectKind) | 158 c.Assert(kind1, gc.Equals, test.expectKind) |
149 c.Assert(id1, gc.Equals, id) | 159 c.Assert(id1, gc.Equals, id) |
150 } | 160 } |
151 } | 161 } |
152 } | 162 } |
LEFT | RIGHT |