OLD | NEW |
1 package state_test | 1 package state_test |
2 | 2 |
3 import ( | 3 import ( |
4 "fmt" | 4 "fmt" |
5 "labix.org/v2/mgo/bson" | 5 "labix.org/v2/mgo/bson" |
6 . "launchpad.net/gocheck" | 6 . "launchpad.net/gocheck" |
7 "launchpad.net/juju-core/charm" | 7 "launchpad.net/juju-core/charm" |
8 "launchpad.net/juju-core/environs/config" | 8 "launchpad.net/juju-core/environs/config" |
9 "launchpad.net/juju-core/state" | 9 "launchpad.net/juju-core/state" |
10 "launchpad.net/juju-core/testing" | 10 "launchpad.net/juju-core/testing" |
(...skipping 927 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
938 state.SortPorts(p) | 938 state.SortPorts(p) |
939 c.Check(p, DeepEquals, t.want) | 939 c.Check(p, DeepEquals, t.want) |
940 state.SortPorts(p) | 940 state.SortPorts(p) |
941 c.Check(p, DeepEquals, t.want) | 941 c.Check(p, DeepEquals, t.want) |
942 } | 942 } |
943 } | 943 } |
944 | 944 |
945 func (*StateSuite) TestNameChecks(c *C) { | 945 func (*StateSuite) TestNameChecks(c *C) { |
946 assertService := func(s string, expect bool) { | 946 assertService := func(s string, expect bool) { |
947 c.Assert(state.IsServiceName(s), Equals, expect) | 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 |
| 950 // to it. |
948 c.Assert(state.IsUnitName(s+"/0"), Equals, expect) | 951 c.Assert(state.IsUnitName(s+"/0"), Equals, expect) |
949 c.Assert(state.IsUnitName(s+"/99"), Equals, expect) | 952 c.Assert(state.IsUnitName(s+"/99"), Equals, expect) |
950 c.Assert(state.IsUnitName(s+"/-1"), Equals, false) | 953 c.Assert(state.IsUnitName(s+"/-1"), Equals, false) |
951 c.Assert(state.IsUnitName(s+"/blah"), Equals, false) | 954 c.Assert(state.IsUnitName(s+"/blah"), Equals, false) |
| 955 c.Assert(state.IsUnitName(s+"/"), Equals, false) |
952 } | 956 } |
| 957 // Service names must be non-empty... |
953 assertService("", false) | 958 assertService("", false) |
| 959 // must not consist entirely of numbers |
954 assertService("33", false) | 960 assertService("33", false) |
| 961 // may consist of a single word |
955 assertService("wordpress", true) | 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 assertService("w0rd-pre55", true) | 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 assertService("foo2", true) | 974 assertService("foo2", true) |
| 975 // ...unless that number is all by itself |
958 assertService("foo-2", false) | 976 assertService("foo-2", false) |
959 assertService("foo-2foo", true) | |
960 | 977 |
961 assertMachine := func(s string, expect bool) { | 978 assertMachine := func(s string, expect bool) { |
962 c.Assert(state.IsMachineId(s), Equals, expect) | 979 c.Assert(state.IsMachineId(s), Equals, expect) |
963 } | 980 } |
964 assertMachine("0", true) | 981 assertMachine("0", true) |
965 assertMachine("1", true) | 982 assertMachine("1", true) |
966 assertMachine("1000001", true) | 983 assertMachine("1000001", true) |
967 assertMachine("01", false) | 984 assertMachine("01", false) |
968 assertMachine("-1", false) | 985 assertMachine("-1", false) |
969 assertMachine("", false) | 986 assertMachine("", false) |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1374 c.Assert(e.EntityName(), Equals, u.EntityName()) | 1391 c.Assert(e.EntityName(), Equals, u.EntityName()) |
1375 | 1392 |
1376 user, err := s.State.AddUser("arble", "pass") | 1393 user, err := s.State.AddUser("arble", "pass") |
1377 c.Assert(err, IsNil) | 1394 c.Assert(err, IsNil) |
1378 | 1395 |
1379 e, err = s.State.Entity(user.EntityName()) | 1396 e, err = s.State.Entity(user.EntityName()) |
1380 c.Assert(err, IsNil) | 1397 c.Assert(err, IsNil) |
1381 c.Assert(e, FitsTypeOf, user) | 1398 c.Assert(e, FitsTypeOf, user) |
1382 c.Assert(e.EntityName(), Equals, user.EntityName()) | 1399 c.Assert(e.EntityName(), Equals, user.EntityName()) |
1383 } | 1400 } |
OLD | NEW |