Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2)

Unified Diff: state/service_test.go

Issue 64890044: state: Make unit ids unique. Fix #1174610
Patch Set: Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « state/service.go ('k') | state/state.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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)
+ }
+}
« no previous file with comments | « state/service.go ('k') | state/state.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b