forked from juju/names
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisk_test.go
61 lines (48 loc) · 1.75 KB
/
disk_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
// Copyright 2013 Canonical Ltd.
// Licensed under the LGPLv3, see LICENCE file for details.
package names_test
import (
"fmt"
gc "gopkg.in/check.v1"
"github.com/juju/names"
)
type diskSuite struct{}
var _ = gc.Suite(&diskSuite{})
func (s *diskSuite) TestDiskTag(c *gc.C) {
c.Assert(names.NewDiskTag("1").String(), gc.Equals, "disk-1")
}
func (s *diskSuite) TestDiskNameValidity(c *gc.C) {
assertDiskNameValid(c, "0")
assertDiskNameValid(c, "1000")
assertDiskNameInvalid(c, "-1")
assertDiskNameInvalid(c, "")
assertDiskNameInvalid(c, "one")
assertDiskNameInvalid(c, "#")
}
func (s *diskSuite) TestParseDiskTag(c *gc.C) {
assertParseDiskTag(c, "disk-0", names.NewDiskTag("0"))
assertParseDiskTag(c, "disk-88", names.NewDiskTag("88"))
assertParseDiskTagInvalid(c, "", names.InvalidTagError("", ""))
assertParseDiskTagInvalid(c, "one", names.InvalidTagError("one", ""))
assertParseDiskTagInvalid(c, "disk-", names.InvalidTagError("disk-", names.DiskTagKind))
assertParseDiskTagInvalid(c, "machine-0", names.InvalidTagError("machine-0", names.DiskTagKind))
}
func assertDiskNameValid(c *gc.C, name string) {
c.Assert(names.IsValidDisk(name), gc.Equals, true)
names.NewDiskTag(name)
}
func assertDiskNameInvalid(c *gc.C, name string) {
c.Assert(names.IsValidDisk(name), gc.Equals, false)
testDiskTag := func() { names.NewDiskTag(name) }
expect := fmt.Sprintf("%q is not a valid disk name", name)
c.Assert(testDiskTag, gc.PanicMatches, expect)
}
func assertParseDiskTag(c *gc.C, tag string, expect names.DiskTag) {
t, err := names.ParseDiskTag(tag)
c.Assert(err, gc.IsNil)
c.Assert(t, gc.Equals, expect)
}
func assertParseDiskTagInvalid(c *gc.C, tag string, expect error) {
_, err := names.ParseDiskTag(tag)
c.Assert(err, gc.ErrorMatches, expect.Error())
}