~ubuntu-branches/ubuntu/saucy/juju-core/saucy

« back to all changes in this revision

Viewing changes to src/launchpad.net/juju-core/names/service_test.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-20 16:02:16 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20130820160216-5yu1llasa2e2youn
Tags: 1.13.1-0ubuntu1
* New upstream release.
  - Build and install juju metadata plugin.
  - d/NEWS: Add some guidance on upgrading environments from 1.11.x
    to 1.13.x.
* d/NEWS: Add details about lack of upgrade path from juju < 1.11
  and how to interact with older juju environments.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2013 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
 
4
package names_test
 
5
 
 
6
import (
 
7
        gc "launchpad.net/gocheck"
 
8
 
 
9
        "launchpad.net/juju-core/names"
 
10
)
 
11
 
 
12
type serviceSuite struct{}
 
13
 
 
14
var _ = gc.Suite(&serviceSuite{})
 
15
 
 
16
var serviceNameTests = []struct {
 
17
        pattern string
 
18
        valid   bool
 
19
}{
 
20
        {pattern: "", valid: false},
 
21
        {pattern: "wordpress", valid: true},
 
22
        {pattern: "foo42", valid: true},
 
23
        {pattern: "doing55in54", valid: true},
 
24
        {pattern: "%not", valid: false},
 
25
        {pattern: "42also-not", valid: false},
 
26
        {pattern: "but-this-works", valid: true},
 
27
        {pattern: "so-42-far-not-good", valid: false},
 
28
        {pattern: "foo/42", valid: false},
 
29
        {pattern: "is-it-", valid: false},
 
30
        {pattern: "broken2-", valid: false},
 
31
        {pattern: "foo2", valid: true},
 
32
        {pattern: "foo-2", valid: false},
 
33
}
 
34
 
 
35
func (s *serviceSuite) TestServiceNameFormats(c *gc.C) {
 
36
        assertService := func(s string, expect bool) {
 
37
                c.Assert(names.IsService(s), gc.Equals, expect)
 
38
                // Check that anything that is considered a valid service name
 
39
                // is also (in)valid if a(n) (in)valid unit designator is added
 
40
                // to it.
 
41
                c.Assert(names.IsUnit(s+"/0"), gc.Equals, expect)
 
42
                c.Assert(names.IsUnit(s+"/99"), gc.Equals, expect)
 
43
                c.Assert(names.IsUnit(s+"/-1"), gc.Equals, false)
 
44
                c.Assert(names.IsUnit(s+"/blah"), gc.Equals, false)
 
45
                c.Assert(names.IsUnit(s+"/"), gc.Equals, false)
 
46
        }
 
47
 
 
48
        for i, test := range serviceNameTests {
 
49
                c.Logf("test %d: %q", i, test.pattern)
 
50
                assertService(test.pattern, test.valid)
 
51
        }
 
52
}