~ubuntu-branches/ubuntu/vivid/juju-core/vivid-proposed

« back to all changes in this revision

Viewing changes to src/github.com/juju/names/tag_test.go

  • Committer: Package Import Robot
  • Author(s): Curtis C. Hovey
  • Date: 2015-09-29 19:43:29 UTC
  • mfrom: (47.1.4 wily-proposed)
  • Revision ID: package-import@ubuntu.com-20150929194329-9y496tbic30hc7vp
Tags: 1.24.6-0ubuntu1~15.04.1
Backport of 1.24.6 from wily. (LP: #1500916, #1497087)

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
        {tag: "network-42", kind: names.NetworkTagKind},
32
32
        {tag: "ab01cd23-0123-4edc-9a8b-fedcba987654", err: `"ab01cd23-0123-4edc-9a8b-fedcba987654" is not a valid tag`},
33
33
        {tag: "action-ab01cd23-0123-4edc-9a8b-fedcba987654", kind: names.ActionTagKind},
34
 
        {tag: "disk-0", kind: names.DiskTagKind},
 
34
        {tag: "volume-0", kind: names.VolumeTagKind},
 
35
        {tag: "storage-data-0", kind: names.StorageTagKind},
 
36
        {tag: "filesystem-0", kind: names.FilesystemTagKind},
 
37
        {tag: "space", err: `"space" is not a valid tag`},
 
38
        {tag: "space-42", kind: names.SpaceTagKind},
35
39
}
36
40
 
37
41
func (*tagSuite) TestTagKind(c *gc.C) {
155
159
        expectType: names.ActionTag{},
156
160
        resultId:   "abedaf33-3212-4fde-aeca-87356432deca",
157
161
}, {
158
 
        tag:        "disk-2",
159
 
        expectKind: names.DiskTagKind,
160
 
        expectType: names.DiskTag{},
 
162
        tag:        "volume-2",
 
163
        expectKind: names.VolumeTagKind,
 
164
        expectType: names.VolumeTag{},
161
165
        resultId:   "2",
162
166
}, {
 
167
        tag:        "filesystem-3",
 
168
        expectKind: names.FilesystemTagKind,
 
169
        expectType: names.FilesystemTag{},
 
170
        resultId:   "3",
 
171
}, {
 
172
        tag:        "storage-block-storage-0",
 
173
        expectKind: names.StorageTagKind,
 
174
        expectType: names.StorageTag{},
 
175
        resultId:   "block-storage/0",
 
176
}, {
163
177
        tag:       "foo",
164
178
        resultErr: `"foo" is not a valid tag`,
 
179
}, {
 
180
        tag:        "space-",
 
181
        resultErr:  `"space-" is not a valid space tag`,
 
182
}, {
 
183
        tag:        "space-myspace1",
 
184
        expectKind: names.SpaceTagKind,
 
185
        expectType: names.SpaceTag{},
 
186
        resultId:   "myspace1",
165
187
}}
166
188
 
167
189
var makeTag = map[string]func(string) names.Tag{
168
 
        names.MachineTagKind:  func(tag string) names.Tag { return names.NewMachineTag(tag) },
169
 
        names.UnitTagKind:     func(tag string) names.Tag { return names.NewUnitTag(tag) },
170
 
        names.ServiceTagKind:  func(tag string) names.Tag { return names.NewServiceTag(tag) },
171
 
        names.RelationTagKind: func(tag string) names.Tag { return names.NewRelationTag(tag) },
172
 
        names.EnvironTagKind:  func(tag string) names.Tag { return names.NewEnvironTag(tag) },
173
 
        names.UserTagKind:     func(tag string) names.Tag { return names.NewUserTag(tag) },
174
 
        names.NetworkTagKind:  func(tag string) names.Tag { return names.NewNetworkTag(tag) },
175
 
        names.ActionTagKind:   func(tag string) names.Tag { return names.NewActionTag(tag) },
176
 
        names.DiskTagKind:     func(tag string) names.Tag { return names.NewDiskTag(tag) },
 
190
        names.MachineTagKind:    func(tag string) names.Tag { return names.NewMachineTag(tag) },
 
191
        names.UnitTagKind:       func(tag string) names.Tag { return names.NewUnitTag(tag) },
 
192
        names.ServiceTagKind:    func(tag string) names.Tag { return names.NewServiceTag(tag) },
 
193
        names.RelationTagKind:   func(tag string) names.Tag { return names.NewRelationTag(tag) },
 
194
        names.EnvironTagKind:    func(tag string) names.Tag { return names.NewEnvironTag(tag) },
 
195
        names.UserTagKind:       func(tag string) names.Tag { return names.NewUserTag(tag) },
 
196
        names.NetworkTagKind:    func(tag string) names.Tag { return names.NewNetworkTag(tag) },
 
197
        names.ActionTagKind:     func(tag string) names.Tag { return names.NewActionTag(tag) },
 
198
        names.VolumeTagKind:     func(tag string) names.Tag { return names.NewVolumeTag(tag) },
 
199
        names.FilesystemTagKind: func(tag string) names.Tag { return names.NewFilesystemTag(tag) },
 
200
        names.StorageTagKind:    func(tag string) names.Tag { return names.NewStorageTag(tag) },
 
201
        names.SpaceTagKind:      func(tag string) names.Tag { return names.NewSpaceTag(tag) },
177
202
}
178
203
 
179
204
func (*tagSuite) TestParseTag(c *gc.C) {
219
244
                }
220
245
        }
221
246
}
 
247
 
 
248
func (*tagSuite) TestReadableString(c *gc.C) {
 
249
        var readableStringTests = []struct {
 
250
                tag    names.Tag
 
251
                result string
 
252
        }{{
 
253
                tag:    nil,
 
254
                result: "",
 
255
        }, {
 
256
                tag:    names.NewMachineTag("0"),
 
257
                result: "machine 0",
 
258
        }, {
 
259
                tag:    names.NewUnitTag("wordpress/2"),
 
260
                result: "unit wordpress/2",
 
261
        }}
 
262
 
 
263
        for i, test := range readableStringTests {
 
264
                c.Logf("test %d: expected result %q", i, test.result)
 
265
                resultStr := names.ReadableString(test.tag)
 
266
                c.Assert(resultStr, gc.Equals, test.result)
 
267
        }
 
268
}