~axwalk/juju-core/trunk

« back to all changes in this revision

Viewing changes to names/service_test.go

  • Committer: Tarmac
  • Author(s): Dimiter Naydenov
  • Date: 2013-07-30 18:39:16 UTC
  • mfrom: (1548.3.8 081-common-names)
  • Revision ID: tarmac-20130730183916-t2lui5ndotkzqrth
[r=dimitern] names: New package

This introduces a new juju-core/names pacakge,
which contains all name and tag related functions
shared between state and API: IsUnitName, UnitTag,
UnitNameFromTag, MachineTag, MachineIdFromTag,
IsServiceName, etc.

Because of the pacakge name, some functions were
renamed: names.IsUnit, IsService, UnitFromTag,
all refer to names.

In addition, a change was made to these two
functions: UnitNameFromTag and MachineIdFromTag.
Both of them now return (string, error), rather
than just string. The error return is used in
case the passed tag string has an invalid format.
Because of this change, some places needed slight
refactoring, otherwise no other changes where made.

https://codereview.appspot.com/12034043/

R=fwereade, rogpeppe

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: "wordpress", valid: true},
 
21
        {pattern: "foo42", valid: true},
 
22
        {pattern: "doing55in54", valid: true},
 
23
        {pattern: "%not", valid: false},
 
24
        {pattern: "42also-not", valid: false},
 
25
        {pattern: "but-this-works", valid: true},
 
26
        {pattern: "so-42-far-not-good", valid: false},
 
27
        {pattern: "foo/42", valid: false},
 
28
        {pattern: "is-it-", valid: false},
 
29
        {pattern: "broken2-", valid: false},
 
30
}
 
31
 
 
32
func (s *serviceSuite) TestServiceNameFormats(c *gc.C) {
 
33
        for i, test := range serviceNameTests {
 
34
                c.Logf("%d. %q", i, test.pattern)
 
35
                c.Assert(names.IsService(test.pattern), gc.Equals, test.valid)
 
36
        }
 
37
}