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 upgrader_test | 4 package upgrader_test |
5 | 5 |
6 import ( | 6 import ( |
7 stdtesting "testing" | 7 stdtesting "testing" |
8 | 8 |
9 . "launchpad.net/gocheck" | 9 . "launchpad.net/gocheck" |
10 | 10 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 err := s.upgrader.SetTools(params.AgentTools{ | 95 err := s.upgrader.SetTools(params.AgentTools{ |
96 Tag: "42", | 96 Tag: "42", |
97 Arch: cur.Arch, | 97 Arch: cur.Arch, |
98 Series: cur.Series, | 98 Series: cur.Series, |
99 Major: cur.Major, | 99 Major: cur.Major, |
100 Minor: cur.Minor, | 100 Minor: cur.Minor, |
101 Patch: cur.Patch, | 101 Patch: cur.Patch, |
102 Build: cur.Build, | 102 Build: cur.Build, |
103 }) | 103 }) |
104 c.Assert(err, ErrorMatches, "permission denied") | 104 c.Assert(err, ErrorMatches, "permission denied") |
105 » c.Assert(api.ErrCode(err), Equals, api.CodeUnauthorized) | 105 » c.Assert(params.ErrCode(err), Equals, params.CodeUnauthorized) |
106 } | 106 } |
107 | 107 |
108 func (s *upgraderSuite) TestSetTools(c *C) { | 108 func (s *upgraderSuite) TestSetTools(c *C) { |
109 cur := version.Current | 109 cur := version.Current |
110 tools, err := s.rawMachine.AgentTools() | 110 tools, err := s.rawMachine.AgentTools() |
111 c.Assert(err, checkers.Satisfies, errors.IsNotFoundError) | 111 c.Assert(err, checkers.Satisfies, errors.IsNotFoundError) |
112 c.Assert(tools, IsNil) | 112 c.Assert(tools, IsNil) |
113 err = s.upgrader.SetTools(params.AgentTools{ | 113 err = s.upgrader.SetTools(params.AgentTools{ |
114 Tag: s.rawMachine.Tag(), | 114 Tag: s.rawMachine.Tag(), |
115 Arch: cur.Arch, | 115 Arch: cur.Arch, |
116 Series: cur.Series, | 116 Series: cur.Series, |
117 URL: "", | 117 URL: "", |
118 Major: cur.Major, | 118 Major: cur.Major, |
119 Minor: cur.Minor, | 119 Minor: cur.Minor, |
120 Patch: cur.Patch, | 120 Patch: cur.Patch, |
121 Build: cur.Build, | 121 Build: cur.Build, |
122 }) | 122 }) |
123 c.Assert(err, IsNil) | 123 c.Assert(err, IsNil) |
124 s.rawMachine.Refresh() | 124 s.rawMachine.Refresh() |
125 tools, err = s.rawMachine.AgentTools() | 125 tools, err = s.rawMachine.AgentTools() |
126 c.Assert(err, IsNil) | 126 c.Assert(err, IsNil) |
127 c.Assert(tools, NotNil) | 127 c.Assert(tools, NotNil) |
128 c.Check(tools.Binary, Equals, cur) | 128 c.Check(tools.Binary, Equals, cur) |
129 } | 129 } |
130 | 130 |
131 func (s *upgraderSuite) TestToolsWrongMachine(c *C) { | 131 func (s *upgraderSuite) TestToolsWrongMachine(c *C) { |
132 tools, err := s.upgrader.Tools("42") | 132 tools, err := s.upgrader.Tools("42") |
133 c.Assert(err, ErrorMatches, "permission denied") | 133 c.Assert(err, ErrorMatches, "permission denied") |
134 » c.Assert(api.ErrCode(err), Equals, api.CodeUnauthorized) | 134 » c.Assert(params.ErrCode(err), Equals, params.CodeUnauthorized) |
135 c.Assert(tools, IsNil) | 135 c.Assert(tools, IsNil) |
136 } | 136 } |
137 | 137 |
138 func (s *upgraderSuite) TestTools(c *C) { | 138 func (s *upgraderSuite) TestTools(c *C) { |
139 cur := version.Current | 139 cur := version.Current |
140 curTools := &state.Tools{Binary: cur, URL: ""} | 140 curTools := &state.Tools{Binary: cur, URL: ""} |
141 if curTools.Minor > 0 { | 141 if curTools.Minor > 0 { |
142 curTools.Minor -= 1 | 142 curTools.Minor -= 1 |
143 } | 143 } |
144 s.rawMachine.SetAgentTools(curTools) | 144 s.rawMachine.SetAgentTools(curTools) |
145 // Upgrader.Tools returns the *desired* set of tools, not the currently | 145 // Upgrader.Tools returns the *desired* set of tools, not the currently |
146 // running set. We want to upgraded to cur.Version | 146 // running set. We want to upgraded to cur.Version |
147 tools, err := s.upgrader.Tools(s.rawMachine.Tag()) | 147 tools, err := s.upgrader.Tools(s.rawMachine.Tag()) |
148 c.Assert(err, IsNil) | 148 c.Assert(err, IsNil) |
149 c.Assert(tools, NotNil) | 149 c.Assert(tools, NotNil) |
150 c.Check(tools.Tag, Equals, s.rawMachine.Tag()) | 150 c.Check(tools.Tag, Equals, s.rawMachine.Tag()) |
151 c.Check(tools.Major, Equals, cur.Major) | 151 c.Check(tools.Major, Equals, cur.Major) |
152 c.Check(tools.Minor, Equals, cur.Minor) | 152 c.Check(tools.Minor, Equals, cur.Minor) |
153 c.Check(tools.Patch, Equals, cur.Patch) | 153 c.Check(tools.Patch, Equals, cur.Patch) |
154 c.Check(tools.Build, Equals, cur.Build) | 154 c.Check(tools.Build, Equals, cur.Build) |
155 c.Check(tools.Arch, Equals, cur.Arch) | 155 c.Check(tools.Arch, Equals, cur.Arch) |
156 c.Check(tools.Series, Equals, cur.Series) | 156 c.Check(tools.Series, Equals, cur.Series) |
157 c.Check(tools.URL, Not(Equals), "") | 157 c.Check(tools.URL, Not(Equals), "") |
158 } | 158 } |
OLD | NEW |