945
945
func (*StateSuite) TestNameChecks(c *C) {
946
946
assertService := func(s string, expect bool) {
947
947
c.Assert(state.IsServiceName(s), Equals, expect)
948
// Check that anything that is considered a valid service name
949
// is also (in)valid if a(n) (in)valid unit designator is added
948
951
c.Assert(state.IsUnitName(s+"/0"), Equals, expect)
949
952
c.Assert(state.IsUnitName(s+"/99"), Equals, expect)
950
953
c.Assert(state.IsUnitName(s+"/-1"), Equals, false)
951
954
c.Assert(state.IsUnitName(s+"/blah"), Equals, false)
955
c.Assert(state.IsUnitName(s+"/"), Equals, false)
957
// Service names must be non-empty...
953
958
assertService("", false)
959
// must not consist entirely of numbers
954
960
assertService("33", false)
961
// may consist of a single word
955
962
assertService("wordpress", true)
963
// may contain hyphen-seperated words...
964
assertService("super-duper-wordpress", true)
965
// ...but those words must have at least one letter in them
966
assertService("super-1234-wordpress", false)
967
// may contain internal numbers.
956
968
assertService("w0rd-pre55", true)
969
// must not begin with a number
970
assertService("3wordpress", false)
971
// but internal, hyphen-sperated words can begin with numbers
972
assertService("foo-2foo", true)
973
// and may end with a number...
957
974
assertService("foo2", true)
975
// ...unless that number is all by itself
958
976
assertService("foo-2", false)
959
assertService("foo-2foo", true)
961
978
assertMachine := func(s string, expect bool) {
962
979
c.Assert(state.IsMachineId(s), Equals, expect)