OLD | NEW |
1 // Copyright 2012, 2013 Canonical Ltd. | 1 // Copyright 2012, 2013 Canonical Ltd. |
2 // Licensed under the AGPLv3, see LICENCE file for details. | 2 // Licensed under the AGPLv3, see LICENCE file for details. |
3 | 3 |
4 package state_test | 4 package state_test |
5 | 5 |
6 import ( | 6 import ( |
7 "fmt" | 7 "fmt" |
8 "labix.org/v2/mgo/bson" | 8 "labix.org/v2/mgo/bson" |
9 . "launchpad.net/gocheck" | 9 . "launchpad.net/gocheck" |
10 "launchpad.net/juju-core/charm" | 10 "launchpad.net/juju-core/charm" |
(...skipping 1075 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1086 case <-time.After(500 * time.Millisecond): | 1086 case <-time.After(500 * time.Millisecond): |
1087 c.Fatalf("did not get change: %#v", change) | 1087 c.Fatalf("did not get change: %#v", change) |
1088 } | 1088 } |
1089 assertNoChange() | 1089 assertNoChange() |
1090 } | 1090 } |
1091 assertChange(nil) | 1091 assertChange(nil) |
1092 assertChange(attrs{"default-series": "another-series"}) | 1092 assertChange(attrs{"default-series": "another-series"}) |
1093 assertChange(attrs{"fancy-new-key": "arbitrary-value"}) | 1093 assertChange(attrs{"fancy-new-key": "arbitrary-value"}) |
1094 } | 1094 } |
1095 | 1095 |
| 1096 // setAgentVersion sets the current agent version in the state's |
| 1097 // environment configuration. |
| 1098 func setAgentVersion(st *state.State, vers version.Number) error { |
| 1099 cfg, err := st.EnvironConfig() |
| 1100 if err != nil { |
| 1101 return err |
| 1102 } |
| 1103 cfg, err = cfg.Apply(map[string]interface{}{"agent-version": vers.String
()}) |
| 1104 if err != nil { |
| 1105 panic(fmt.Errorf("config refused agent-version: %v", err)) |
| 1106 } |
| 1107 return st.SetEnvironConfig(cfg) |
| 1108 } |
| 1109 |
| 1110 func (s *StateSuite) TestWatchForEnvironConfigChanges(c *C) { |
| 1111 cur := version.Current.Number |
| 1112 err := setAgentVersion(s.State, cur) |
| 1113 c.Assert(err, IsNil) |
| 1114 w := s.State.WatchForEnvironConfigChanges() |
| 1115 defer statetesting.AssertStop(c, w) |
| 1116 |
| 1117 wc := statetesting.NewNotifyWatcherC(c, s.State, w) |
| 1118 // Initially we get one change notification |
| 1119 wc.AssertOneChange() |
| 1120 |
| 1121 // Multiple changes will only result in a single change notification |
| 1122 newVersion := cur |
| 1123 newVersion.Minor += 1 |
| 1124 err = setAgentVersion(s.State, newVersion) |
| 1125 c.Assert(err, IsNil) |
| 1126 |
| 1127 newerVersion := newVersion |
| 1128 newerVersion.Minor += 1 |
| 1129 err = setAgentVersion(s.State, newerVersion) |
| 1130 c.Assert(err, IsNil) |
| 1131 wc.AssertOneChange() |
| 1132 |
| 1133 // Setting it to the same value does not trigger a change notification |
| 1134 err = setAgentVersion(s.State, newerVersion) |
| 1135 c.Assert(err, IsNil) |
| 1136 wc.AssertNoChange() |
| 1137 } |
| 1138 |
1096 func (s *StateSuite) TestWatchEnvironConfigCorruptConfig(c *C) { | 1139 func (s *StateSuite) TestWatchEnvironConfigCorruptConfig(c *C) { |
1097 cfg, err := s.State.EnvironConfig() | 1140 cfg, err := s.State.EnvironConfig() |
1098 c.Assert(err, IsNil) | 1141 c.Assert(err, IsNil) |
1099 | 1142 |
1100 // Corrupt the environment configuration. | 1143 // Corrupt the environment configuration. |
1101 settings := s.Session.DB("juju").C("settings") | 1144 settings := s.Session.DB("juju").C("settings") |
1102 err = settings.UpdateId("e", bson.D{{"$unset", bson.D{{"name", 1}}}}) | 1145 err = settings.UpdateId("e", bson.D{{"$unset", bson.D{{"name", 1}}}}) |
1103 c.Assert(err, IsNil) | 1146 c.Assert(err, IsNil) |
1104 | 1147 |
1105 s.State.Sync() | 1148 s.State.Sync() |
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1734 c.Assert(state.TopParentId("0"), Equals, "0") | 1777 c.Assert(state.TopParentId("0"), Equals, "0") |
1735 c.Assert(state.TopParentId("0/lxc/1"), Equals, "0") | 1778 c.Assert(state.TopParentId("0/lxc/1"), Equals, "0") |
1736 c.Assert(state.TopParentId("0/lxc/1/kvm/2"), Equals, "0") | 1779 c.Assert(state.TopParentId("0/lxc/1/kvm/2"), Equals, "0") |
1737 } | 1780 } |
1738 | 1781 |
1739 func (s *StateSuite) TestParentId(c *C) { | 1782 func (s *StateSuite) TestParentId(c *C) { |
1740 c.Assert(state.ParentId("0"), Equals, "") | 1783 c.Assert(state.ParentId("0"), Equals, "") |
1741 c.Assert(state.ParentId("0/lxc/1"), Equals, "0") | 1784 c.Assert(state.ParentId("0/lxc/1"), Equals, "0") |
1742 c.Assert(state.ParentId("0/lxc/1/kvm/0"), Equals, "0/lxc/1") | 1785 c.Assert(state.ParentId("0/lxc/1/kvm/0"), Equals, "0/lxc/1") |
1743 } | 1786 } |
OLD | NEW |