launchpad.net/~rogpeppe/juju-core/500-errgo-fix@v0.0.0-20140213181702-000000002356/names/service_test.go (about) 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 }