Merge lp:~sergiusens/snappy/dont_get_this into lp:~snappy-dev/snappy/snappy-moved-to-github
- dont_get_this
- Merge into snappy-moved-to-github
Proposed by
Sergio Schvezov
Status: | Merged |
---|---|
Merged at revision: | 123 |
Proposed branch: | lp:~sergiusens/snappy/dont_get_this |
Merge into: | lp:~snappy-dev/snappy/snappy-moved-to-github |
Diff against target: |
423 lines (+64/-67) 9 files modified
cmd/snappy/cmd_booted.go (+1/-1) cmd/snappy/cmd_info.go (+3/-3) snappy/list.go (+2/-2) snappy/parts.go (+12/-12) snappy/remove.go (+1/-1) snappy/snapp.go (+7/-9) snappy/snapp_test.go (+23/-23) snappy/systemimage.go (+8/-9) snappy/systemimage_test.go (+7/-7) |
To merge this branch: | bzr merge lp:~sergiusens/snappy/dont_get_this |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Michael Vogt (community) | Approve | ||
Review via email:
|
Commit message
Description of the change
https:/
Even though these aren't properties for fields per se, they are properties of the system and I'm going to use common idomatic go from around (no Get in the names).
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'cmd/snappy/cmd_booted.go' | |||
2 | --- cmd/snappy/cmd_booted.go 2015-01-26 14:13:15 +0000 | |||
3 | +++ cmd/snappy/cmd_booted.go 2015-01-27 19:16:59 +0000 | |||
4 | @@ -15,7 +15,7 @@ | |||
5 | 15 | } | 15 | } |
6 | 16 | 16 | ||
7 | 17 | func (x *CmdBooted) Execute(args []string) (err error) { | 17 | func (x *CmdBooted) Execute(args []string) (err error) { |
9 | 18 | parts, err := snappy.GetInstalledSnappsByType("core") | 18 | parts, err := snappy.InstalledSnappsByType("core") |
10 | 19 | if err != nil { | 19 | if err != nil { |
11 | 20 | return err | 20 | return err |
12 | 21 | } | 21 | } |
13 | 22 | 22 | ||
14 | === modified file 'cmd/snappy/cmd_info.go' | |||
15 | --- cmd/snappy/cmd_info.go 2015-01-26 14:30:14 +0000 | |||
16 | +++ cmd/snappy/cmd_info.go 2015-01-27 19:16:59 +0000 | |||
17 | @@ -25,13 +25,13 @@ | |||
18 | 25 | 25 | ||
19 | 26 | func info() error { | 26 | func info() error { |
20 | 27 | release := "unknown" | 27 | release := "unknown" |
22 | 28 | parts, err := snappy.GetInstalledSnappsByType("core") | 28 | parts, err := snappy.InstalledSnappsByType("core") |
23 | 29 | if len(parts) == 1 && err == nil { | 29 | if len(parts) == 1 && err == nil { |
24 | 30 | release = parts[0].(*snappy.SystemImagePart).Channel() | 30 | release = parts[0].(*snappy.SystemImagePart).Channel() |
25 | 31 | } | 31 | } |
26 | 32 | 32 | ||
29 | 33 | frameworks, _ := snappy.GetInstalledSnappNamesByType("framework") | 33 | frameworks, _ := snappy.InstalledSnappNamesByType("framework") |
30 | 34 | apps, _ := snappy.GetInstalledSnappNamesByType("app") | 34 | apps, _ := snappy.InstalledSnappNamesByType("app") |
31 | 35 | 35 | ||
32 | 36 | fmt.Printf("release: %s\n", release) | 36 | fmt.Printf("release: %s\n", release) |
33 | 37 | fmt.Printf("architecture: %s\n", snappy.Architecture()) | 37 | fmt.Printf("architecture: %s\n", snappy.Architecture()) |
34 | 38 | 38 | ||
35 | === modified file 'snappy/list.go' | |||
36 | --- snappy/list.go 2015-01-26 14:13:15 +0000 | |||
37 | +++ snappy/list.go 2015-01-27 19:16:59 +0000 | |||
38 | @@ -3,11 +3,11 @@ | |||
39 | 3 | func ListInstalled() ([]Part, error) { | 3 | func ListInstalled() ([]Part, error) { |
40 | 4 | m := NewMetaRepository() | 4 | m := NewMetaRepository() |
41 | 5 | 5 | ||
43 | 6 | return m.GetInstalled() | 6 | return m.Installed() |
44 | 7 | } | 7 | } |
45 | 8 | 8 | ||
46 | 9 | func ListUpdates() ([]Part, error) { | 9 | func ListUpdates() ([]Part, error) { |
47 | 10 | m := NewMetaRepository() | 10 | m := NewMetaRepository() |
48 | 11 | 11 | ||
50 | 12 | return m.GetUpdates() | 12 | return m.Updates() |
51 | 13 | } | 13 | } |
52 | 14 | 14 | ||
53 | === modified file 'snappy/parts.go' | |||
54 | --- snappy/parts.go 2015-01-27 08:18:14 +0000 | |||
55 | +++ snappy/parts.go 2015-01-27 19:16:59 +0000 | |||
56 | @@ -42,8 +42,8 @@ | |||
57 | 42 | Search(terms string) ([]Part, error) | 42 | Search(terms string) ([]Part, error) |
58 | 43 | Details(snappName string) ([]Part, error) | 43 | Details(snappName string) ([]Part, error) |
59 | 44 | 44 | ||
62 | 45 | GetUpdates() ([]Part, error) | 45 | Updates() ([]Part, error) |
63 | 46 | GetInstalled() ([]Part, error) | 46 | Installed() ([]Part, error) |
64 | 47 | } | 47 | } |
65 | 48 | 48 | ||
66 | 49 | type MetaRepository struct { | 49 | type MetaRepository struct { |
67 | @@ -70,9 +70,9 @@ | |||
68 | 70 | return m | 70 | return m |
69 | 71 | } | 71 | } |
70 | 72 | 72 | ||
72 | 73 | func (m *MetaRepository) GetInstalled() (parts []Part, err error) { | 73 | func (m *MetaRepository) Installed() (parts []Part, err error) { |
73 | 74 | for _, r := range m.all { | 74 | for _, r := range m.all { |
75 | 75 | installed, err := r.GetInstalled() | 75 | installed, err := r.Installed() |
76 | 76 | if err != nil { | 76 | if err != nil { |
77 | 77 | return parts, err | 77 | return parts, err |
78 | 78 | } | 78 | } |
79 | @@ -82,9 +82,9 @@ | |||
80 | 82 | return parts, err | 82 | return parts, err |
81 | 83 | } | 83 | } |
82 | 84 | 84 | ||
84 | 85 | func (m *MetaRepository) GetUpdates() (parts []Part, err error) { | 85 | func (m *MetaRepository) Updates() (parts []Part, err error) { |
85 | 86 | for _, r := range m.all { | 86 | for _, r := range m.all { |
87 | 87 | updates, err := r.GetUpdates() | 87 | updates, err := r.Updates() |
88 | 88 | if err != nil { | 88 | if err != nil { |
89 | 89 | return parts, err | 89 | return parts, err |
90 | 90 | } | 90 | } |
91 | @@ -118,9 +118,9 @@ | |||
92 | 118 | return parts, err | 118 | return parts, err |
93 | 119 | } | 119 | } |
94 | 120 | 120 | ||
96 | 121 | func GetInstalledSnappsByType(searchExp string) (res []Part, err error) { | 121 | func InstalledSnappsByType(searchExp string) (res []Part, err error) { |
97 | 122 | m := NewMetaRepository() | 122 | m := NewMetaRepository() |
99 | 123 | installed, err := m.GetInstalled() | 123 | installed, err := m.Installed() |
100 | 124 | if err != nil { | 124 | if err != nil { |
101 | 125 | return res, err | 125 | return res, err |
102 | 126 | } | 126 | } |
103 | @@ -138,17 +138,17 @@ | |||
104 | 138 | return | 138 | return |
105 | 139 | } | 139 | } |
106 | 140 | 140 | ||
109 | 141 | var GetInstalledSnappNamesByType = func(snappType string) (res []string, err error) { | 141 | var InstalledSnappNamesByType = func(snappType string) (res []string, err error) { |
110 | 142 | installed, err := GetInstalledSnappsByType(snappType) | 142 | installed, err := InstalledSnappsByType(snappType) |
111 | 143 | for _, part := range installed { | 143 | for _, part := range installed { |
112 | 144 | res = append(res, part.Name()) | 144 | res = append(res, part.Name()) |
113 | 145 | } | 145 | } |
114 | 146 | return | 146 | return |
115 | 147 | } | 147 | } |
116 | 148 | 148 | ||
118 | 149 | func GetInstalledSnappByName(needle string) Part { | 149 | func InstalledSnappByName(needle string) Part { |
119 | 150 | m := NewMetaRepository() | 150 | m := NewMetaRepository() |
121 | 151 | installed, err := m.GetInstalled() | 151 | installed, err := m.Installed() |
122 | 152 | if err != nil { | 152 | if err != nil { |
123 | 153 | return nil | 153 | return nil |
124 | 154 | } | 154 | } |
125 | 155 | 155 | ||
126 | === modified file 'snappy/remove.go' | |||
127 | --- snappy/remove.go 2015-01-26 14:13:15 +0000 | |||
128 | +++ snappy/remove.go 2015-01-27 19:16:59 +0000 | |||
129 | @@ -1,7 +1,7 @@ | |||
130 | 1 | package snappy | 1 | package snappy |
131 | 2 | 2 | ||
132 | 3 | func Remove(partName string) error { | 3 | func Remove(partName string) error { |
134 | 4 | part := GetInstalledSnappByName(partName) | 4 | part := InstalledSnappByName(partName) |
135 | 5 | if part != nil { | 5 | if part != nil { |
136 | 6 | if err := part.Uninstall(); err != nil { | 6 | if err := part.Uninstall(); err != nil { |
137 | 7 | return err | 7 | return err |
138 | 8 | 8 | ||
139 | === modified file 'snappy/snapp.go' | |||
140 | --- snappy/snapp.go 2015-01-26 14:30:14 +0000 | |||
141 | +++ snappy/snapp.go 2015-01-27 19:16:59 +0000 | |||
142 | @@ -181,13 +181,11 @@ | |||
143 | 181 | return versions, err | 181 | return versions, err |
144 | 182 | } | 182 | } |
145 | 183 | 183 | ||
148 | 184 | func (s *SnappLocalRepository) GetUpdates() (parts []Part, err error) { | 184 | func (s *SnappLocalRepository) Updates() (parts []Part, err error) { |
147 | 185 | |||
149 | 186 | return parts, err | 185 | return parts, err |
150 | 187 | } | 186 | } |
151 | 188 | 187 | ||
154 | 189 | func (s *SnappLocalRepository) GetInstalled() (parts []Part, err error) { | 188 | func (s *SnappLocalRepository) Installed() (parts []Part, err error) { |
153 | 190 | |||
155 | 191 | globExpr := path.Join(s.path, "*", "*", "meta", "package.yaml") | 189 | globExpr := path.Join(s.path, "*", "*", "meta", "package.yaml") |
156 | 192 | matches, err := filepath.Glob(globExpr) | 190 | matches, err := filepath.Glob(globExpr) |
157 | 193 | if err != nil { | 191 | if err != nil { |
158 | @@ -332,7 +330,7 @@ | |||
159 | 332 | 330 | ||
160 | 333 | // set headers | 331 | // set headers |
161 | 334 | req.Header.Set("Accept", "application/hal+json") | 332 | req.Header.Set("Accept", "application/hal+json") |
163 | 335 | frameworks, _ := GetInstalledSnappNamesByType("framework") | 333 | frameworks, _ := InstalledSnappNamesByType("framework") |
164 | 336 | frameworks = append(frameworks, "ubuntu-core-15.04-dev1") | 334 | frameworks = append(frameworks, "ubuntu-core-15.04-dev1") |
165 | 337 | req.Header.Set("X-Ubuntu-Frameworks", strings.Join(frameworks, ",")) | 335 | req.Header.Set("X-Ubuntu-Frameworks", strings.Join(frameworks, ",")) |
166 | 338 | req.Header.Set("X-Ubuntu-Architecture", Architecture()) | 336 | req.Header.Set("X-Ubuntu-Architecture", Architecture()) |
167 | @@ -366,7 +364,7 @@ | |||
168 | 366 | 364 | ||
169 | 367 | // set headers | 365 | // set headers |
170 | 368 | req.Header.Set("Accept", "application/hal+json") | 366 | req.Header.Set("Accept", "application/hal+json") |
172 | 369 | frameworks, _ := GetInstalledSnappNamesByType("framework") | 367 | frameworks, _ := InstalledSnappNamesByType("framework") |
173 | 370 | frameworks = append(frameworks, "ubuntu-core-15.04-dev1") | 368 | frameworks = append(frameworks, "ubuntu-core-15.04-dev1") |
174 | 371 | req.Header.Set("X-Ubuntu-Frameworks", strings.Join(frameworks, ",")) | 369 | req.Header.Set("X-Ubuntu-Frameworks", strings.Join(frameworks, ",")) |
175 | 372 | req.Header.Set("X-Ubuntu-Architecture", Architecture()) | 370 | req.Header.Set("X-Ubuntu-Architecture", Architecture()) |
176 | @@ -393,10 +391,10 @@ | |||
177 | 393 | return parts, err | 391 | return parts, err |
178 | 394 | } | 392 | } |
179 | 395 | 393 | ||
181 | 396 | func (s *SnappUbuntuStoreRepository) GetUpdates() (parts []Part, err error) { | 394 | func (s *SnappUbuntuStoreRepository) Updates() (parts []Part, err error) { |
182 | 397 | // the store only supports apps and framworks currently, so no | 395 | // the store only supports apps and framworks currently, so no |
183 | 398 | // sense in sending it our ubuntu-core snapp | 396 | // sense in sending it our ubuntu-core snapp |
185 | 399 | installed, err := GetInstalledSnappNamesByType("app,framework") | 397 | installed, err := InstalledSnappNamesByType("app,framework") |
186 | 400 | if err != nil || len(installed) == 0 { | 398 | if err != nil || len(installed) == 0 { |
187 | 401 | return parts, err | 399 | return parts, err |
188 | 402 | } | 400 | } |
189 | @@ -431,6 +429,6 @@ | |||
190 | 431 | return parts, nil | 429 | return parts, nil |
191 | 432 | } | 430 | } |
192 | 433 | 431 | ||
194 | 434 | func (s *SnappUbuntuStoreRepository) GetInstalled() (parts []Part, err error) { | 432 | func (s *SnappUbuntuStoreRepository) Installed() (parts []Part, err error) { |
195 | 435 | return parts, err | 433 | return parts, err |
196 | 436 | } | 434 | } |
197 | 437 | 435 | ||
198 | === modified file 'snappy/snapp_test.go' | |||
199 | --- snappy/snapp_test.go 2015-01-23 19:28:17 +0000 | |||
200 | +++ snappy/snapp_test.go 2015-01-27 19:16:59 +0000 | |||
201 | @@ -108,7 +108,7 @@ | |||
202 | 108 | snapp := NewLocalSnappRepository(path.Join(s.tempdir, "apps")) | 108 | snapp := NewLocalSnappRepository(path.Join(s.tempdir, "apps")) |
203 | 109 | c.Assert(snapp, NotNil) | 109 | c.Assert(snapp, NotNil) |
204 | 110 | 110 | ||
206 | 111 | installed, err := snapp.GetInstalled() | 111 | installed, err := snapp.Installed() |
207 | 112 | c.Assert(err, IsNil) | 112 | c.Assert(err, IsNil) |
208 | 113 | c.Assert(len(installed), Equals, 1) | 113 | c.Assert(len(installed), Equals, 1) |
209 | 114 | c.Assert(installed[0].Name(), Equals, "hello-app") | 114 | c.Assert(installed[0].Name(), Equals, "hello-app") |
210 | @@ -159,16 +159,16 @@ | |||
211 | 159 | const MockUpdatesJson = ` | 159 | const MockUpdatesJson = ` |
212 | 160 | [ | 160 | [ |
213 | 161 | { | 161 | { |
224 | 162 | "status": "Published", | 162 | "status": "Published", |
225 | 163 | "name": "hello-world", | 163 | "name": "hello-world", |
226 | 164 | "changelog": "", | 164 | "changelog": "", |
227 | 165 | "icon_url": "https://myapps.developer.ubuntu.com/site_media/appmedia/2015/01/hello.svg.png", | 165 | "icon_url": "https://myapps.developer.ubuntu.com/site_media/appmedia/2015/01/hello.svg.png", |
228 | 166 | "title": "Hello world example", | 166 | "title": "Hello world example", |
229 | 167 | "binary_filesize": 31166, | 167 | "binary_filesize": 31166, |
230 | 168 | "anon_download_url": "https://public.apps.ubuntu.com/anon/download/com.ubuntu.snappy/hello-world/hello-world_1.0.5_all.snap", | 168 | "anon_download_url": "https://public.apps.ubuntu.com/anon/download/com.ubuntu.snappy/hello-world/hello-world_1.0.5_all.snap", |
231 | 169 | "allow_unauthenticated": true, | 169 | "allow_unauthenticated": true, |
232 | 170 | "version": "1.0.5", | 170 | "version": "1.0.5", |
233 | 171 | "download_url": "https://public.apps.ubuntu.com/download/com.ubuntu.snappy/hello-world/hello-world_1.0.5_all.snap", | 171 | "download_url": "https://public.apps.ubuntu.com/download/com.ubuntu.snappy/hello-world/hello-world_1.0.5_all.snap", |
234 | 172 | "download_sha512": "3e8b192e18907d8195c2e380edd048870eda4f6dbcba8f65e4625d6efac3c37d11d607147568ade6f002b6baa30762c6da02e7ee462de7c56301ddbdc10d87f6" | 172 | "download_sha512": "3e8b192e18907d8195c2e380edd048870eda4f6dbcba8f65e4625d6efac3c37d11d607147568ade6f002b6baa30762c6da02e7ee462de7c56301ddbdc10d87f6" |
235 | 173 | } | 173 | } |
236 | 174 | ] | 174 | ] |
237 | @@ -270,17 +270,17 @@ | |||
238 | 270 | c.Assert(results[0].Description(), Equals, "Show random XKCD comic") | 270 | c.Assert(results[0].Description(), Equals, "Show random XKCD comic") |
239 | 271 | } | 271 | } |
240 | 272 | 272 | ||
244 | 273 | func mockGetInstalledSnappNamesByType(mockSnapps []string) (mockRestorer func()) { | 273 | func mockInstalledSnappNamesByType(mockSnapps []string) (mockRestorer func()) { |
245 | 274 | origFunc := GetInstalledSnappNamesByType | 274 | origFunc := InstalledSnappNamesByType |
246 | 275 | GetInstalledSnappNamesByType = func(snappType string) (res []string, err error) { | 275 | InstalledSnappNamesByType = func(snappType string) (res []string, err error) { |
247 | 276 | return mockSnapps, nil | 276 | return mockSnapps, nil |
248 | 277 | } | 277 | } |
249 | 278 | return func() { | 278 | return func() { |
251 | 279 | GetInstalledSnappNamesByType = origFunc | 279 | InstalledSnappNamesByType = origFunc |
252 | 280 | } | 280 | } |
253 | 281 | } | 281 | } |
254 | 282 | 282 | ||
256 | 283 | func (s *SnappTestSuite) TestUbuntuStoreRepositoryGetUpdates(c *C) { | 283 | func (s *SnappTestSuite) TestUbuntuStoreRepositoryUpdates(c *C) { |
257 | 284 | mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | 284 | mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
258 | 285 | json_req, err := ioutil.ReadAll(r.Body) | 285 | json_req, err := ioutil.ReadAll(r.Body) |
259 | 286 | c.Assert(err, IsNil) | 286 | c.Assert(err, IsNil) |
260 | @@ -295,20 +295,20 @@ | |||
261 | 295 | c.Assert(snapp, NotNil) | 295 | c.Assert(snapp, NotNil) |
262 | 296 | snapp.bulkUri = mockServer.URL + "/updates/" | 296 | snapp.bulkUri = mockServer.URL + "/updates/" |
263 | 297 | 297 | ||
265 | 298 | // override the real GetInstalledSnappNamesByType to return our | 298 | // override the real InstalledSnappNamesByType to return our |
266 | 299 | // mock data | 299 | // mock data |
268 | 300 | mockRestorer := mockGetInstalledSnappNamesByType([]string{"hello-world"}) | 300 | mockRestorer := mockInstalledSnappNamesByType([]string{"hello-world"}) |
269 | 301 | defer mockRestorer() | 301 | defer mockRestorer() |
270 | 302 | 302 | ||
271 | 303 | // the actual test | 303 | // the actual test |
273 | 304 | results, err := snapp.GetUpdates() | 304 | results, err := snapp.Updates() |
274 | 305 | c.Assert(err, IsNil) | 305 | c.Assert(err, IsNil) |
275 | 306 | c.Assert(len(results), Equals, 1) | 306 | c.Assert(len(results), Equals, 1) |
276 | 307 | c.Assert(results[0].Name(), Equals, "hello-world") | 307 | c.Assert(results[0].Name(), Equals, "hello-world") |
277 | 308 | c.Assert(results[0].Version(), Equals, "1.0.5") | 308 | c.Assert(results[0].Version(), Equals, "1.0.5") |
278 | 309 | } | 309 | } |
279 | 310 | 310 | ||
281 | 311 | func (s *SnappTestSuite) TestUbuntuStoreRepositoryGetUpdatesNoSnapps(c *C) { | 311 | func (s *SnappTestSuite) TestUbuntuStoreRepositoryUpdatesNoSnapps(c *C) { |
282 | 312 | 312 | ||
283 | 313 | snapp := NewUbuntuStoreSnappRepository() | 313 | snapp := NewUbuntuStoreSnappRepository() |
284 | 314 | c.Assert(snapp, NotNil) | 314 | c.Assert(snapp, NotNil) |
285 | @@ -316,16 +316,16 @@ | |||
286 | 316 | // ensure we do not hit the net if there is nothing installed | 316 | // ensure we do not hit the net if there is nothing installed |
287 | 317 | // (otherwise the store will send us all snapps) | 317 | // (otherwise the store will send us all snapps) |
288 | 318 | snapp.bulkUri = "http://i-do.not-exist.really-not" | 318 | snapp.bulkUri = "http://i-do.not-exist.really-not" |
290 | 319 | mockRestorer := mockGetInstalledSnappNamesByType([]string{}) | 319 | mockRestorer := mockInstalledSnappNamesByType([]string{}) |
291 | 320 | defer mockRestorer() | 320 | defer mockRestorer() |
292 | 321 | 321 | ||
293 | 322 | // the actual test | 322 | // the actual test |
295 | 323 | results, err := snapp.GetUpdates() | 323 | results, err := snapp.Updates() |
296 | 324 | c.Assert(err, IsNil) | 324 | c.Assert(err, IsNil) |
297 | 325 | c.Assert(len(results), Equals, 0) | 325 | c.Assert(len(results), Equals, 0) |
298 | 326 | } | 326 | } |
299 | 327 | 327 | ||
301 | 328 | func (s *SnappTestSuite) TestUbuntuStoreRepositoryGetDetails(c *C) { | 328 | func (s *SnappTestSuite) TestUbuntuStoreRepositoryDetails(c *C) { |
302 | 329 | mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | 329 | mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
303 | 330 | c.Assert(strings.HasSuffix(r.URL.String(), "xkcd-webserver"), Equals, true) | 330 | c.Assert(strings.HasSuffix(r.URL.String(), "xkcd-webserver"), Equals, true) |
304 | 331 | io.WriteString(w, MockDetailsJson) | 331 | io.WriteString(w, MockDetailsJson) |
305 | 332 | 332 | ||
306 | === modified file 'snappy/systemimage.go' | |||
307 | --- snappy/systemimage.go 2015-01-27 11:41:12 +0000 | |||
308 | +++ snappy/systemimage.go 2015-01-27 19:16:59 +0000 | |||
309 | @@ -416,7 +416,7 @@ | |||
310 | 416 | partition: s.partition}, err | 416 | partition: s.partition}, err |
311 | 417 | } | 417 | } |
312 | 418 | 418 | ||
314 | 419 | func (s *SystemImageRepository) getCurrentPart() Part { | 419 | func (s *SystemImageRepository) CurrentPart() Part { |
315 | 420 | configFile := s.myroot + systemImageChannelConfig | 420 | configFile := s.myroot + systemImageChannelConfig |
316 | 421 | part, err := s.makePartFromSystemImageConfigFile(configFile, true) | 421 | part, err := s.makePartFromSystemImageConfigFile(configFile, true) |
317 | 422 | if err != nil { | 422 | if err != nil { |
318 | @@ -426,7 +426,7 @@ | |||
319 | 426 | } | 426 | } |
320 | 427 | 427 | ||
321 | 428 | // Returns the part associated with the other rootfs (if any) | 428 | // Returns the part associated with the other rootfs (if any) |
323 | 429 | func (s *SystemImageRepository) getOtherPart() Part { | 429 | func (s *SystemImageRepository) OtherPart() Part { |
324 | 430 | var part Part | 430 | var part Part |
325 | 431 | s.partition.RunWithOther(func(otherRoot string) (err error) { | 431 | s.partition.RunWithOther(func(otherRoot string) (err error) { |
326 | 432 | configFile := s.myroot + otherRoot + systemImageChannelConfig | 432 | configFile := s.myroot + otherRoot + systemImageChannelConfig |
327 | @@ -442,7 +442,7 @@ | |||
328 | 442 | func (s *SystemImageRepository) Search(terms string) (versions []Part, err error) { | 442 | func (s *SystemImageRepository) Search(terms string) (versions []Part, err error) { |
329 | 443 | if strings.Contains(terms, systemImagePartName) { | 443 | if strings.Contains(terms, systemImagePartName) { |
330 | 444 | s.proxy.Information() | 444 | s.proxy.Information() |
332 | 445 | part := s.getCurrentPart() | 445 | part := s.CurrentPart() |
333 | 446 | versions = append(versions, part) | 446 | versions = append(versions, part) |
334 | 447 | } | 447 | } |
335 | 448 | return versions, err | 448 | return versions, err |
336 | @@ -451,14 +451,13 @@ | |||
337 | 451 | func (s *SystemImageRepository) Details(snappName string) (versions []Part, err error) { | 451 | func (s *SystemImageRepository) Details(snappName string) (versions []Part, err error) { |
338 | 452 | if snappName == systemImagePartName { | 452 | if snappName == systemImagePartName { |
339 | 453 | s.proxy.Information() | 453 | s.proxy.Information() |
341 | 454 | part := s.getCurrentPart() | 454 | part := s.CurrentPart() |
342 | 455 | versions = append(versions, part) | 455 | versions = append(versions, part) |
343 | 456 | } | 456 | } |
344 | 457 | return versions, err | 457 | return versions, err |
345 | 458 | } | 458 | } |
346 | 459 | 459 | ||
349 | 460 | func (s *SystemImageRepository) GetUpdates() (parts []Part, err error) { | 460 | func (s *SystemImageRepository) Updates() (parts []Part, err error) { |
348 | 461 | |||
350 | 462 | if _, err = s.proxy.CheckForUpdate(); err != nil { | 461 | if _, err = s.proxy.CheckForUpdate(); err != nil { |
351 | 463 | return parts, err | 462 | return parts, err |
352 | 464 | } | 463 | } |
353 | @@ -479,15 +478,15 @@ | |||
354 | 479 | return parts, err | 478 | return parts, err |
355 | 480 | } | 479 | } |
356 | 481 | 480 | ||
358 | 482 | func (s *SystemImageRepository) GetInstalled() (parts []Part, err error) { | 481 | func (s *SystemImageRepository) Installed() (parts []Part, err error) { |
359 | 483 | // current partition | 482 | // current partition |
361 | 484 | curr := s.getCurrentPart() | 483 | curr := s.CurrentPart() |
362 | 485 | if curr != nil { | 484 | if curr != nil { |
363 | 486 | parts = append(parts, curr) | 485 | parts = append(parts, curr) |
364 | 487 | } | 486 | } |
365 | 488 | 487 | ||
366 | 489 | // other partition | 488 | // other partition |
368 | 490 | other := s.getOtherPart() | 489 | other := s.OtherPart() |
369 | 491 | if other != nil { | 490 | if other != nil { |
370 | 492 | parts = append(parts, other) | 491 | parts = append(parts, other) |
371 | 493 | } | 492 | } |
372 | 494 | 493 | ||
373 | === modified file 'snappy/systemimage_test.go' | |||
374 | --- snappy/systemimage_test.go 2015-01-26 10:05:08 +0000 | |||
375 | +++ snappy/systemimage_test.go 2015-01-27 19:16:59 +0000 | |||
376 | @@ -248,7 +248,7 @@ | |||
377 | 248 | 248 | ||
378 | 249 | func (s *SITestSuite) TestTestInstalled(c *C) { | 249 | func (s *SITestSuite) TestTestInstalled(c *C) { |
379 | 250 | // whats installed | 250 | // whats installed |
381 | 251 | parts, err := s.systemImage.GetInstalled() | 251 | parts, err := s.systemImage.Installed() |
382 | 252 | c.Assert(err, IsNil) | 252 | c.Assert(err, IsNil) |
383 | 253 | // we have one active and one inactive | 253 | // we have one active and one inactive |
384 | 254 | c.Assert(len(parts), Equals, 2) | 254 | c.Assert(len(parts), Equals, 2) |
385 | @@ -262,16 +262,16 @@ | |||
386 | 262 | c.Assert(parts[1].Version(), Equals, "3.14") | 262 | c.Assert(parts[1].Version(), Equals, "3.14") |
387 | 263 | } | 263 | } |
388 | 264 | 264 | ||
391 | 265 | func (s *SITestSuite) TestGetUpdateNoUpdate(c *C) { | 265 | func (s *SITestSuite) TestUpdateNoUpdate(c *C) { |
392 | 266 | parts, err := s.systemImage.GetUpdates() | 266 | parts, err := s.systemImage.Updates() |
393 | 267 | c.Assert(err, IsNil) | 267 | c.Assert(err, IsNil) |
394 | 268 | c.Assert(len(parts), Equals, 0) | 268 | c.Assert(len(parts), Equals, 0) |
395 | 269 | } | 269 | } |
396 | 270 | 270 | ||
398 | 271 | func (s *SITestSuite) TestGetUpdateHasUpdate(c *C) { | 271 | func (s *SITestSuite) TestUpdateHasUpdate(c *C) { |
399 | 272 | // add a update | 272 | // add a update |
400 | 273 | s.mockSystemImage.info["target_build_number"] = "3.14" | 273 | s.mockSystemImage.info["target_build_number"] = "3.14" |
402 | 274 | parts, err := s.systemImage.GetUpdates() | 274 | parts, err := s.systemImage.Updates() |
403 | 275 | c.Assert(err, IsNil) | 275 | c.Assert(err, IsNil) |
404 | 276 | c.Assert(len(parts), Equals, 1) | 276 | c.Assert(len(parts), Equals, 1) |
405 | 277 | c.Assert(parts[0].Name(), Equals, "ubuntu-core") | 277 | c.Assert(parts[0].Name(), Equals, "ubuntu-core") |
406 | @@ -308,7 +308,7 @@ | |||
407 | 308 | func (s *SITestSuite) TestSystemImagePartInstallUpdatesPartition(c *C) { | 308 | func (s *SITestSuite) TestSystemImagePartInstallUpdatesPartition(c *C) { |
408 | 309 | // add a update | 309 | // add a update |
409 | 310 | s.mockSystemImage.info["target_build_number"] = "3.14" | 310 | s.mockSystemImage.info["target_build_number"] = "3.14" |
411 | 311 | parts, err := s.systemImage.GetUpdates() | 311 | parts, err := s.systemImage.Updates() |
412 | 312 | 312 | ||
413 | 313 | sp := parts[0].(*SystemImagePart) | 313 | sp := parts[0].(*SystemImagePart) |
414 | 314 | mockPartition := MockPartition{} | 314 | mockPartition := MockPartition{} |
415 | @@ -322,7 +322,7 @@ | |||
416 | 322 | func (s *SITestSuite) TestSystemImagePartInstall(c *C) { | 322 | func (s *SITestSuite) TestSystemImagePartInstall(c *C) { |
417 | 323 | // add a update | 323 | // add a update |
418 | 324 | s.mockSystemImage.info["target_build_number"] = "3.14" | 324 | s.mockSystemImage.info["target_build_number"] = "3.14" |
420 | 325 | parts, err := s.systemImage.GetUpdates() | 325 | parts, err := s.systemImage.Updates() |
421 | 326 | 326 | ||
422 | 327 | sp := parts[0].(*SystemImagePart) | 327 | sp := parts[0].(*SystemImagePart) |
423 | 328 | mockPartition := MockPartition{} | 328 | mockPartition := MockPartition{} |
Thanks Sergio, this looks good and is more idiomatic go. The only small adjustment I made is that "OtherPart" -> "otherPart" and "CurrentPart" -> "currentPart" as I consider this more internal API (Installed() is the API the user should use).