Index: state/state_test.go |
=== modified file 'state/state_test.go' |
--- state/state_test.go 2013-07-03 15:14:20 +0000 |
+++ state/state_test.go 2013-07-04 14:12:18 +0000 |
@@ -1093,6 +1093,49 @@ |
assertChange(attrs{"fancy-new-key": "arbitrary-value"}) |
} |
+// setAgentVersion sets the current agent version in the state's |
+// environment configuration. |
+func setAgentVersion(st *state.State, vers version.Number) error { |
+ cfg, err := st.EnvironConfig() |
+ if err != nil { |
+ return err |
+ } |
+ cfg, err = cfg.Apply(map[string]interface{}{"agent-version": vers.String()}) |
+ if err != nil { |
+ panic(fmt.Errorf("config refused agent-version: %v", err)) |
+ } |
+ return st.SetEnvironConfig(cfg) |
+} |
+ |
+func (s *StateSuite) TestWatchForEnvironConfigChanges(c *C) { |
+ cur := version.Current.Number |
+ err := setAgentVersion(s.State, cur) |
+ c.Assert(err, IsNil) |
+ w := s.State.WatchForEnvironConfigChanges() |
+ defer statetesting.AssertStop(c, w) |
+ |
+ wc := statetesting.NewNotifyWatcherC(c, s.State, w) |
+ // Initially we get one change notification |
+ wc.AssertOneChange() |
+ |
+ // Multiple changes will only result in a single change notification |
+ newVersion := cur |
+ newVersion.Minor += 1 |
+ err = setAgentVersion(s.State, newVersion) |
+ c.Assert(err, IsNil) |
+ |
+ newerVersion := newVersion |
+ newerVersion.Minor += 1 |
+ err = setAgentVersion(s.State, newerVersion) |
+ c.Assert(err, IsNil) |
+ wc.AssertOneChange() |
+ |
+ // Setting it to the same value does not trigger a change notification |
+ err = setAgentVersion(s.State, newerVersion) |
+ c.Assert(err, IsNil) |
+ wc.AssertNoChange() |
+} |
+ |
func (s *StateSuite) TestWatchEnvironConfigCorruptConfig(c *C) { |
cfg, err := s.State.EnvironConfig() |
c.Assert(err, IsNil) |