Index: state/service_test.go |
=== modified file 'state/service_test.go' |
--- state/service_test.go 2014-01-15 06:52:56 +0000 |
+++ state/service_test.go 2014-02-17 16:32:56 +0000 |
@@ -6,6 +6,7 @@ |
import ( |
"fmt" |
"sort" |
+ "strconv" |
"labix.org/v2/mgo" |
gc "launchpad.net/gocheck" |
@@ -815,13 +816,13 @@ |
err = s.mysql.Destroy() |
c.Assert(err, gc.IsNil) |
_, err = s.mysql.AddUnit() |
- c.Assert(err, gc.ErrorMatches, `cannot add unit to service "mysql": service is not alive`) |
+ c.Assert(err, gc.ErrorMatches, `cannot add unit to service "mysql": service is no longer alive`) |
err = u.EnsureDead() |
c.Assert(err, gc.IsNil) |
err = u.Remove() |
c.Assert(err, gc.IsNil) |
_, err = s.mysql.AddUnit() |
- c.Assert(err, gc.ErrorMatches, `cannot add unit to service "mysql": service "mysql" not found`) |
+ c.Assert(err, gc.ErrorMatches, `cannot add unit to service "mysql": service is no longer alive`) |
} |
func (s *ServiceSuite) TestReadUnit(c *gc.C) { |
@@ -1429,3 +1430,24 @@ |
c.Assert(state.GetServiceOwnerTag(service), gc.Equals, "") |
c.Assert(service.GetOwnerTag(), gc.Equals, "user-admin") |
} |
+ |
+func (s *ServiceSuite) TestUnitIdsAreUnique(c *gc.C) { |
+ for i, charmName := range []string{"wordpress", "riak", "dummy"} { |
+ // Add a new charm and service with the same name. |
+ charm := s.AddTestingCharm(c, charmName) |
+ service := s.AddTestingService(c, "myservice", charm) |
+ |
+ // Add a unit and check the id increases each time. |
+ unit, err := service.AddUnit() |
+ c.Check(err, gc.IsNil) |
+ c.Check(unit.Name(), gc.Equals, "myservice/"+strconv.Itoa(i)) |
+ |
+ // Destroy the unit and service and retry. |
+ err = unit.Destroy() |
+ c.Check(err, gc.IsNil) |
+ c.Check(unit.Refresh(), jc.Satisfies, errors.IsNotFoundError) |
+ err = service.Destroy() |
+ c.Check(err, gc.IsNil) |
+ c.Check(service.Refresh(), jc.Satisfies, errors.IsNotFoundError) |
+ } |
+} |