forked from juju/names
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action_test.go
61 lines (51 loc) · 1.63 KB
/
action_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 2014 Canonical Ltd.
// Licensed under the LGPLv3, see LICENCE file for details.
package names_test
import (
gc "gopkg.in/check.v1"
"github.com/juju/names"
)
type actionSuite struct{}
var _ = gc.Suite(&actionSuite{})
var parseActionTagTests = []struct {
tag string
expected names.Tag
err error
}{
{tag: "", err: names.InvalidTagError("", "")},
{tag: "action-f47ac10b-58cc-4372-a567-0e02b2c3d479", expected: names.NewActionTag("f47ac10b-58cc-4372-a567-0e02b2c3d479")},
{tag: "action-012345678", err: names.InvalidTagError("action-012345678", "action")},
{tag: "action-1234567", err: names.InvalidTagError("action-1234567", "action")},
{tag: "bob", err: names.InvalidTagError("bob", "")},
{tag: "service-ned", err: names.InvalidTagError("service-ned", names.ActionTagKind)}}
func (s *actionSuite) TestParseActionTag(c *gc.C) {
for i, t := range parseActionTagTests {
c.Logf("test %d: %s", i, t.tag)
got, err := names.ParseActionTag(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)
}
}
func (s *actionSuite) TestActionReceiverTag(c *gc.C) {
testCases := []struct {
name string
expected names.Tag
valid bool
}{
{name: "mysql", valid: false},
{name: "mysql/3", expected: names.NewUnitTag("mysql/3"), valid: true},
}
for _, tcase := range testCases {
tag, err := names.ActionReceiverTag(tcase.name)
c.Check(err == nil, gc.Equals, tcase.valid)
if err != nil {
continue
}
c.Check(tag, gc.FitsTypeOf, tcase.expected)
c.Check(tag, gc.Equals, tcase.expected)
}
}