Merge lp:~fgimenez/snappy/cli-pkg into lp:~snappy-dev/snappy/snappy-moved-to-github
- cli-pkg
- Merge into snappy-moved-to-github
Proposed by
Federico Gimenez
Status: | Merged |
---|---|
Approved by: | Federico Gimenez |
Approved revision: | 722 |
Merged at revision: | 733 |
Proposed branch: | lp:~fgimenez/snappy/cli-pkg |
Merge into: | lp:~snappy-dev/snappy/snappy-moved-to-github |
Diff against target: |
1166 lines (+306/-175) 24 files modified
_integration-tests/tests/apt_test.go (+5/-4) _integration-tests/tests/config_test.go (+3/-2) _integration-tests/tests/failover_rclocal_crash_test.go (+12/-10) _integration-tests/tests/failover_systemd_loop_test.go (+18/-17) _integration-tests/tests/failover_test.go (+10/-10) _integration-tests/tests/failover_zero_size_file_test.go (+12/-11) _integration-tests/tests/helloDbus_test.go (+2/-1) _integration-tests/tests/info_test.go (+13/-12) _integration-tests/tests/installApp_test.go (+4/-3) _integration-tests/tests/installFramework_test.go (+3/-2) _integration-tests/tests/list_test.go (+8/-7) _integration-tests/tests/rollback_test.go (+18/-17) _integration-tests/tests/search_test.go (+8/-7) _integration-tests/tests/ubuntuFan_test.go (+10/-9) _integration-tests/tests/update_test.go (+8/-8) _integration-tests/tests/writablePaths_test.go (+3/-3) _integration-tests/testutils/build/snap.go (+3/-3) _integration-tests/testutils/build/snap_test.go (+3/-3) _integration-tests/testutils/cli/cli.go (+57/-0) _integration-tests/testutils/cli/cli_test.go (+85/-0) _integration-tests/testutils/common/common.go (+15/-41) _integration-tests/testutils/common/info.go (+2/-1) _integration-tests/testutils/runner/runner.go (+1/-1) _integration-tests/testutils/wait/wait.go (+3/-3) |
To merge this branch: | bzr merge lp:~fgimenez/snappy/cli-pkg |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Federico Gimenez (community) | Approve | ||
Leo Arias (community) | Needs Fixing | ||
Review via email: mp+272896@code.launchpad.net |
Commit message
cli package with ExecCommand functions
Description of the change
cli package with ExecCommand functions
The cli package unit tests have been implemented using the technique described in [1]. Also the remaining unnamed "common" package imports and the references to check when importing the gocheck package have been removed.
To post a comment you must log in.
lp:~fgimenez/snappy/cli-pkg
updated
- 721. By Federico Gimenez
-
merged trunk
- 722. By Federico Gimenez
-
config_test updated to cli
Revision history for this message
Federico Gimenez (fgimenez) wrote : | # |
Merged and working, thanks Leo
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file '_integration-tests/tests/apt_test.go' |
2 | --- _integration-tests/tests/apt_test.go 2015-07-28 04:03:52 +0000 |
3 | +++ _integration-tests/tests/apt_test.go 2015-10-02 10:23:57 +0000 |
4 | @@ -20,19 +20,20 @@ |
5 | package tests |
6 | |
7 | import ( |
8 | - . "launchpad.net/snappy/_integration-tests/testutils/common" |
9 | + "launchpad.net/snappy/_integration-tests/testutils/cli" |
10 | + "launchpad.net/snappy/_integration-tests/testutils/common" |
11 | |
12 | - check "gopkg.in/check.v1" |
13 | + "gopkg.in/check.v1" |
14 | ) |
15 | |
16 | var _ = check.Suite(&aptSuite{}) |
17 | |
18 | type aptSuite struct { |
19 | - SnappySuite |
20 | + common.SnappySuite |
21 | } |
22 | |
23 | func (s *aptSuite) TestAptGetMustPrintError(c *check.C) { |
24 | - aptOutput := ExecCommand(c, "apt-get", "update") |
25 | + aptOutput := cli.ExecCommand(c, "apt-get", "update") |
26 | |
27 | expected := "Ubuntu Core does not use apt-get, see 'snappy --help'!\n" |
28 | c.Assert(aptOutput, check.Equals, expected) |
29 | |
30 | === modified file '_integration-tests/tests/config_test.go' |
31 | --- _integration-tests/tests/config_test.go 2015-09-30 08:07:52 +0000 |
32 | +++ _integration-tests/tests/config_test.go 2015-10-02 10:23:57 +0000 |
33 | @@ -24,6 +24,7 @@ |
34 | "os" |
35 | "strings" |
36 | |
37 | + "launchpad.net/snappy/_integration-tests/testutils/cli" |
38 | "launchpad.net/snappy/_integration-tests/testutils/common" |
39 | |
40 | "gopkg.in/check.v1" |
41 | @@ -97,13 +98,13 @@ |
42 | } |
43 | _, err = configFile.Write([]byte(config)) |
44 | |
45 | - common.ExecCommand(c, "sudo", "snappy", "config", "ubuntu-core", configFile.Name()) |
46 | + cli.ExecCommand(c, "sudo", "snappy", "config", "ubuntu-core", configFile.Name()) |
47 | |
48 | return |
49 | } |
50 | |
51 | func currentConfig(c *check.C) string { |
52 | - return common.ExecCommand(c, "sudo", "snappy", "config", "ubuntu-core") |
53 | + return cli.ExecCommand(c, "sudo", "snappy", "config", "ubuntu-core") |
54 | } |
55 | |
56 | func configString(cfg string) string { |
57 | |
58 | === modified file '_integration-tests/tests/failover_rclocal_crash_test.go' |
59 | --- _integration-tests/tests/failover_rclocal_crash_test.go 2015-09-09 06:56:19 +0000 |
60 | +++ _integration-tests/tests/failover_rclocal_crash_test.go 2015-10-02 10:23:57 +0000 |
61 | @@ -22,26 +22,28 @@ |
62 | import ( |
63 | "fmt" |
64 | |
65 | - . "launchpad.net/snappy/_integration-tests/testutils/common" |
66 | + "launchpad.net/snappy/_integration-tests/testutils/cli" |
67 | + "launchpad.net/snappy/_integration-tests/testutils/common" |
68 | |
69 | - check "gopkg.in/check.v1" |
70 | + "gopkg.in/check.v1" |
71 | ) |
72 | |
73 | type rcLocalCrash struct{} |
74 | |
75 | func (rcLocalCrash) set(c *check.C) { |
76 | - MakeWritable(c, BaseAltPartitionPath) |
77 | - defer MakeReadonly(c, BaseAltPartitionPath) |
78 | - targetFile := fmt.Sprintf("%s/etc/rc.local", BaseAltPartitionPath) |
79 | - ExecCommand(c, "sudo", "chmod", "a+xw", targetFile) |
80 | - ExecCommandToFile(c, targetFile, |
81 | + common.MakeWritable(c, common.BaseAltPartitionPath) |
82 | + defer common.MakeReadonly(c, common.BaseAltPartitionPath) |
83 | + targetFile := fmt.Sprintf("%s/etc/rc.local", common.BaseAltPartitionPath) |
84 | + cli.ExecCommand(c, "sudo", "chmod", "a+xw", targetFile) |
85 | + |
86 | + cli.ExecCommandToFile(c, targetFile, |
87 | "sudo", "echo", "#!bin/sh\nprintf c > /proc/sysrq-trigger") |
88 | } |
89 | |
90 | func (rcLocalCrash) unset(c *check.C) { |
91 | - MakeWritable(c, BaseAltPartitionPath) |
92 | - defer MakeReadonly(c, BaseAltPartitionPath) |
93 | - ExecCommand(c, "sudo", "rm", fmt.Sprintf("%s/etc/rc.local", BaseAltPartitionPath)) |
94 | + common.MakeWritable(c, common.BaseAltPartitionPath) |
95 | + defer common.MakeReadonly(c, common.BaseAltPartitionPath) |
96 | + cli.ExecCommand(c, "sudo", "rm", fmt.Sprintf("%s/etc/rc.local", common.BaseAltPartitionPath)) |
97 | } |
98 | |
99 | /* |
100 | |
101 | === modified file '_integration-tests/tests/failover_systemd_loop_test.go' |
102 | --- _integration-tests/tests/failover_systemd_loop_test.go 2015-07-30 16:22:30 +0000 |
103 | +++ _integration-tests/tests/failover_systemd_loop_test.go 2015-10-02 10:23:57 +0000 |
104 | @@ -22,9 +22,10 @@ |
105 | import ( |
106 | "fmt" |
107 | |
108 | - . "launchpad.net/snappy/_integration-tests/testutils/common" |
109 | + "launchpad.net/snappy/_integration-tests/testutils/cli" |
110 | + "launchpad.net/snappy/_integration-tests/testutils/common" |
111 | |
112 | - check "gopkg.in/check.v1" |
113 | + "gopkg.in/check.v1" |
114 | ) |
115 | |
116 | const ( |
117 | @@ -61,51 +62,51 @@ |
118 | type systemdDependencyLoop struct{} |
119 | |
120 | func (systemdDependencyLoop) set(c *check.C) { |
121 | - installService(c, "deadlock", deadlockService, BaseAltPartitionPath) |
122 | - installService(c, "emerg-reboot", rebootService, BaseAltPartitionPath) |
123 | + installService(c, "deadlock", deadlockService, common.BaseAltPartitionPath) |
124 | + installService(c, "emerg-reboot", rebootService, common.BaseAltPartitionPath) |
125 | } |
126 | |
127 | func (systemdDependencyLoop) unset(c *check.C) { |
128 | - unInstallService(c, "deadlock", BaseAltPartitionPath) |
129 | - unInstallService(c, "emerg-reboot", BaseAltPartitionPath) |
130 | + unInstallService(c, "deadlock", common.BaseAltPartitionPath) |
131 | + unInstallService(c, "emerg-reboot", common.BaseAltPartitionPath) |
132 | } |
133 | |
134 | func installService(c *check.C, serviceName, serviceCfg, basePath string) { |
135 | - MakeWritable(c, basePath) |
136 | - defer MakeReadonly(c, basePath) |
137 | + common.MakeWritable(c, basePath) |
138 | + defer common.MakeReadonly(c, basePath) |
139 | |
140 | // Create service file |
141 | serviceFile := fmt.Sprintf("%s%s/%s.service", basePath, baseSystemdPath, serviceName) |
142 | - ExecCommand(c, "sudo", "chmod", "a+w", fmt.Sprintf("%s%s", basePath, baseSystemdPath)) |
143 | - ExecCommandToFile(c, serviceFile, "sudo", "echo", serviceCfg) |
144 | + cli.ExecCommand(c, "sudo", "chmod", "a+w", fmt.Sprintf("%s%s", basePath, baseSystemdPath)) |
145 | + cli.ExecCommandToFile(c, serviceFile, "sudo", "echo", serviceCfg) |
146 | |
147 | // Create requires directory |
148 | requiresDirPart := fmt.Sprintf("%s/%s", baseSystemdPath, systemdTargetRequiresDir) |
149 | requiresDir := fmt.Sprintf("%s%s", basePath, requiresDirPart) |
150 | - ExecCommand(c, "sudo", "mkdir", "-p", requiresDir) |
151 | + cli.ExecCommand(c, "sudo", "mkdir", "-p", requiresDir) |
152 | |
153 | // Symlink from the requires dir to the service file (with chroot for being |
154 | // usable in the other partition) |
155 | - ExecCommand(c, "sudo", "chroot", basePath, "ln", "-s", |
156 | + cli.ExecCommand(c, "sudo", "chroot", basePath, "ln", "-s", |
157 | fmt.Sprintf("%s/%s.service", baseSystemdPath, serviceName), |
158 | fmt.Sprintf("%s/%s.service", requiresDirPart, serviceName), |
159 | ) |
160 | } |
161 | |
162 | func unInstallService(c *check.C, serviceName, basePath string) { |
163 | - MakeWritable(c, basePath) |
164 | - defer MakeReadonly(c, basePath) |
165 | + common.MakeWritable(c, basePath) |
166 | + defer common.MakeReadonly(c, basePath) |
167 | |
168 | // Disable the service |
169 | - ExecCommand(c, "sudo", "chroot", basePath, |
170 | + cli.ExecCommand(c, "sudo", "chroot", basePath, |
171 | "systemctl", "disable", fmt.Sprintf("%s.service", serviceName)) |
172 | |
173 | // Remove the service file |
174 | - ExecCommand(c, "sudo", "rm", |
175 | + cli.ExecCommand(c, "sudo", "rm", |
176 | fmt.Sprintf("%s%s/%s.service", basePath, baseSystemdPath, serviceName)) |
177 | |
178 | // Remove the requires symlink |
179 | - ExecCommand(c, "sudo", "rm", |
180 | + cli.ExecCommand(c, "sudo", "rm", |
181 | fmt.Sprintf("%s%s/%s/%s.service", basePath, baseSystemdPath, systemdTargetRequiresDir, serviceName)) |
182 | } |
183 | |
184 | |
185 | === modified file '_integration-tests/tests/failover_test.go' |
186 | --- _integration-tests/tests/failover_test.go 2015-07-28 04:03:52 +0000 |
187 | +++ _integration-tests/tests/failover_test.go 2015-10-02 10:23:57 +0000 |
188 | @@ -20,15 +20,15 @@ |
189 | package tests |
190 | |
191 | import ( |
192 | - check "gopkg.in/check.v1" |
193 | + "gopkg.in/check.v1" |
194 | |
195 | - . "launchpad.net/snappy/_integration-tests/testutils/common" |
196 | + "launchpad.net/snappy/_integration-tests/testutils/common" |
197 | ) |
198 | |
199 | var _ = check.Suite(&failoverSuite{}) |
200 | |
201 | type failoverSuite struct { |
202 | - SnappySuite |
203 | + common.SnappySuite |
204 | } |
205 | |
206 | // The types that implement this interface can be used in the test logic |
207 | @@ -43,16 +43,16 @@ |
208 | // type implementing the failer interface and call this function with an instance |
209 | // of it |
210 | func commonFailoverTest(c *check.C, f failer) { |
211 | - currentVersion := GetCurrentUbuntuCoreVersion(c) |
212 | + currentVersion := common.GetCurrentUbuntuCoreVersion(c) |
213 | |
214 | - if AfterReboot(c) { |
215 | - RemoveRebootMark(c) |
216 | + if common.AfterReboot(c) { |
217 | + common.RemoveRebootMark(c) |
218 | f.unset(c) |
219 | - c.Assert(GetSavedVersion(c), check.Equals, currentVersion) |
220 | + c.Assert(common.GetSavedVersion(c), check.Equals, currentVersion) |
221 | } else { |
222 | - SetSavedVersion(c, currentVersion-1) |
223 | - CallFakeUpdate(c) |
224 | + common.SetSavedVersion(c, currentVersion-1) |
225 | + common.CallFakeUpdate(c) |
226 | f.set(c) |
227 | - Reboot(c) |
228 | + common.Reboot(c) |
229 | } |
230 | } |
231 | |
232 | === modified file '_integration-tests/tests/failover_zero_size_file_test.go' |
233 | --- _integration-tests/tests/failover_zero_size_file_test.go 2015-09-25 14:35:29 +0000 |
234 | +++ _integration-tests/tests/failover_zero_size_file_test.go 2015-10-02 10:23:57 +0000 |
235 | @@ -25,7 +25,8 @@ |
236 | "path/filepath" |
237 | "strings" |
238 | |
239 | - . "launchpad.net/snappy/_integration-tests/testutils/common" |
240 | + "launchpad.net/snappy/_integration-tests/testutils/cli" |
241 | + "launchpad.net/snappy/_integration-tests/testutils/common" |
242 | "launchpad.net/snappy/_integration-tests/testutils/partition" |
243 | |
244 | "gopkg.in/check.v1" |
245 | @@ -45,11 +46,11 @@ |
246 | type zeroSizeSystemd struct{} |
247 | |
248 | func (zeroSizeKernel) set(c *check.C) { |
249 | - commonSet(c, BaseAltPartitionPath, origBootFilenamePattern, kernelFilename) |
250 | + commonSet(c, common.BaseAltPartitionPath, origBootFilenamePattern, kernelFilename) |
251 | } |
252 | |
253 | func (zeroSizeKernel) unset(c *check.C) { |
254 | - commonUnset(c, BaseAltPartitionPath, origBootFilenamePattern, kernelFilename) |
255 | + commonUnset(c, common.BaseAltPartitionPath, origBootFilenamePattern, kernelFilename) |
256 | } |
257 | |
258 | func (zeroSizeInitrd) set(c *check.C) { |
259 | @@ -71,11 +72,11 @@ |
260 | } |
261 | |
262 | func (zeroSizeSystemd) set(c *check.C) { |
263 | - commonSet(c, BaseAltPartitionPath, origSystemdFilenamePattern, systemdFilename) |
264 | + commonSet(c, common.BaseAltPartitionPath, origSystemdFilenamePattern, systemdFilename) |
265 | } |
266 | |
267 | func (zeroSizeSystemd) unset(c *check.C) { |
268 | - commonUnset(c, BaseAltPartitionPath, origSystemdFilenamePattern, systemdFilename) |
269 | + commonUnset(c, common.BaseAltPartitionPath, origSystemdFilenamePattern, systemdFilename) |
270 | } |
271 | |
272 | func commonSet(c *check.C, baseOtherPath, origPattern, filename string) { |
273 | @@ -105,17 +106,17 @@ |
274 | func renameFile(c *check.C, basePath, oldFilename, newFilename string, keepOld bool) { |
275 | // Only need to make writable and revert for BaseAltPartitionPath, |
276 | // kernel files' boot directory is writable |
277 | - if basePath == BaseAltPartitionPath { |
278 | - MakeWritable(c, basePath) |
279 | - defer MakeReadonly(c, basePath) |
280 | + if basePath == common.BaseAltPartitionPath { |
281 | + common.MakeWritable(c, basePath) |
282 | + defer common.MakeReadonly(c, basePath) |
283 | } |
284 | |
285 | - ExecCommand(c, "sudo", "mv", oldFilename, newFilename) |
286 | + cli.ExecCommand(c, "sudo", "mv", oldFilename, newFilename) |
287 | |
288 | if keepOld { |
289 | - ExecCommand(c, "sudo", "touch", oldFilename) |
290 | + cli.ExecCommand(c, "sudo", "touch", oldFilename) |
291 | mode := getFileMode(c, newFilename) |
292 | - ExecCommand(c, "sudo", "chmod", fmt.Sprintf("%o", mode), oldFilename) |
293 | + cli.ExecCommand(c, "sudo", "chmod", fmt.Sprintf("%o", mode), oldFilename) |
294 | } |
295 | } |
296 | |
297 | |
298 | === modified file '_integration-tests/tests/helloDbus_test.go' |
299 | --- _integration-tests/tests/helloDbus_test.go 2015-09-11 08:47:39 +0000 |
300 | +++ _integration-tests/tests/helloDbus_test.go 2015-10-02 10:23:57 +0000 |
301 | @@ -20,6 +20,7 @@ |
302 | package tests |
303 | |
304 | import ( |
305 | + "launchpad.net/snappy/_integration-tests/testutils/cli" |
306 | "launchpad.net/snappy/_integration-tests/testutils/common" |
307 | |
308 | "gopkg.in/check.v1" |
309 | @@ -38,7 +39,7 @@ |
310 | common.InstallSnap(c, "hello-dbus-app.canonical") |
311 | defer common.RemoveSnap(c, "hello-dbus-app.canonical") |
312 | |
313 | - output := common.ExecCommand(c, "hello-dbus-app.client") |
314 | + output := cli.ExecCommand(c, "hello-dbus-app.client") |
315 | |
316 | expected := "PASS\n" |
317 | |
318 | |
319 | === modified file '_integration-tests/tests/info_test.go' |
320 | --- _integration-tests/tests/info_test.go 2015-07-31 07:55:33 +0000 |
321 | +++ _integration-tests/tests/info_test.go 2015-10-02 10:23:57 +0000 |
322 | @@ -22,41 +22,42 @@ |
323 | import ( |
324 | "fmt" |
325 | |
326 | - . "launchpad.net/snappy/_integration-tests/testutils/common" |
327 | + "launchpad.net/snappy/_integration-tests/testutils/cli" |
328 | + "launchpad.net/snappy/_integration-tests/testutils/common" |
329 | |
330 | - check "gopkg.in/check.v1" |
331 | + "gopkg.in/check.v1" |
332 | ) |
333 | |
334 | var _ = check.Suite(&infoSuite{}) |
335 | |
336 | type infoSuite struct { |
337 | - SnappySuite |
338 | + common.SnappySuite |
339 | } |
340 | |
341 | func (s *infoSuite) TestInfoMustPrintReleaseAndChannel(c *check.C) { |
342 | // skip test when having a remote testbed (we can't know which the |
343 | // release and channels are) |
344 | - if Cfg.RemoteTestbed { |
345 | + if common.Cfg.RemoteTestbed { |
346 | c.Skip(fmt.Sprintf( |
347 | "Skipping %s while testing in remote testbed", |
348 | c.TestName())) |
349 | } |
350 | |
351 | - infoOutput := ExecCommand(c, "snappy", "info") |
352 | + infoOutput := cli.ExecCommand(c, "snappy", "info") |
353 | |
354 | expected := "(?ms)" + |
355 | - fmt.Sprintf("^release: ubuntu-core/%s/%s\n", Cfg.Release, Cfg.Channel) + |
356 | + fmt.Sprintf("^release: ubuntu-core/%s/%s\n", common.Cfg.Release, common.Cfg.Channel) + |
357 | ".*" |
358 | |
359 | c.Assert(infoOutput, check.Matches, expected) |
360 | } |
361 | |
362 | func (s *infoSuite) TestInfoMustPrintInstalledApps(c *check.C) { |
363 | - InstallSnap(c, "hello-world") |
364 | + common.InstallSnap(c, "hello-world") |
365 | s.AddCleanup(func() { |
366 | - RemoveSnap(c, "hello-world") |
367 | + common.RemoveSnap(c, "hello-world") |
368 | }) |
369 | - infoOutput := ExecCommand(c, "snappy", "info") |
370 | + infoOutput := cli.ExecCommand(c, "snappy", "info") |
371 | |
372 | expected := "(?ms)" + |
373 | ".*" + |
374 | @@ -65,11 +66,11 @@ |
375 | } |
376 | |
377 | func (s *infoSuite) TestInfoMustPrintInstalledFrameworks(c *check.C) { |
378 | - InstallSnap(c, "hello-dbus-fwk.canonical") |
379 | + common.InstallSnap(c, "hello-dbus-fwk.canonical") |
380 | s.AddCleanup(func() { |
381 | - RemoveSnap(c, "hello-dbus-fwk.canonical") |
382 | + common.RemoveSnap(c, "hello-dbus-fwk.canonical") |
383 | }) |
384 | - infoOutput := ExecCommand(c, "snappy", "info") |
385 | + infoOutput := cli.ExecCommand(c, "snappy", "info") |
386 | |
387 | expected := "(?ms)" + |
388 | ".*" + |
389 | |
390 | === modified file '_integration-tests/tests/installApp_test.go' |
391 | --- _integration-tests/tests/installApp_test.go 2015-09-24 19:51:26 +0000 |
392 | +++ _integration-tests/tests/installApp_test.go 2015-10-02 10:23:57 +0000 |
393 | @@ -23,10 +23,11 @@ |
394 | "net/http" |
395 | "os/exec" |
396 | |
397 | + "launchpad.net/snappy/_integration-tests/testutils/cli" |
398 | "launchpad.net/snappy/_integration-tests/testutils/common" |
399 | "launchpad.net/snappy/_integration-tests/testutils/wait" |
400 | |
401 | - check "gopkg.in/check.v1" |
402 | + "gopkg.in/check.v1" |
403 | ) |
404 | |
405 | var _ = check.Suite(&installAppSuite{}) |
406 | @@ -57,7 +58,7 @@ |
407 | common.RemoveSnap(c, "hello-world") |
408 | }) |
409 | |
410 | - echoOutput := common.ExecCommand(c, "hello-world.echo") |
411 | + echoOutput := cli.ExecCommand(c, "hello-world.echo") |
412 | |
413 | c.Assert(echoOutput, check.Equals, "Hello World!\n") |
414 | } |
415 | @@ -89,7 +90,7 @@ |
416 | common.RemoveSnap(c, "hello-world") |
417 | }) |
418 | |
419 | - infoOutput := common.ExecCommand(c, "snappy", "info") |
420 | + infoOutput := cli.ExecCommand(c, "snappy", "info") |
421 | |
422 | expected := "(?ms).*^apps: hello-world.canonical\n" |
423 | c.Assert(infoOutput, check.Matches, expected) |
424 | |
425 | === modified file '_integration-tests/tests/installFramework_test.go' |
426 | --- _integration-tests/tests/installFramework_test.go 2015-09-03 10:46:21 +0000 |
427 | +++ _integration-tests/tests/installFramework_test.go 2015-10-02 10:23:57 +0000 |
428 | @@ -23,10 +23,11 @@ |
429 | "fmt" |
430 | "regexp" |
431 | |
432 | + "launchpad.net/snappy/_integration-tests/testutils/cli" |
433 | "launchpad.net/snappy/_integration-tests/testutils/common" |
434 | "launchpad.net/snappy/_integration-tests/testutils/wait" |
435 | |
436 | - check "gopkg.in/check.v1" |
437 | + "gopkg.in/check.v1" |
438 | ) |
439 | |
440 | var _ = check.Suite(&installFrameworkSuite{}) |
441 | @@ -50,7 +51,7 @@ |
442 | err := wait.ForActiveService(c, dockerService) |
443 | c.Assert(err, check.IsNil) |
444 | |
445 | - statusOutput := common.ExecCommand( |
446 | + statusOutput := cli.ExecCommand( |
447 | c, "systemctl", "status", |
448 | dockerService) |
449 | |
450 | |
451 | === modified file '_integration-tests/tests/list_test.go' |
452 | --- _integration-tests/tests/list_test.go 2015-07-28 04:03:52 +0000 |
453 | +++ _integration-tests/tests/list_test.go 2015-10-02 10:23:57 +0000 |
454 | @@ -23,16 +23,17 @@ |
455 | "fmt" |
456 | "os" |
457 | |
458 | - . "launchpad.net/snappy/_integration-tests/testutils/common" |
459 | + "launchpad.net/snappy/_integration-tests/testutils/cli" |
460 | + "launchpad.net/snappy/_integration-tests/testutils/common" |
461 | |
462 | "github.com/mvo5/goconfigparser" |
463 | - check "gopkg.in/check.v1" |
464 | + "gopkg.in/check.v1" |
465 | ) |
466 | |
467 | var _ = check.Suite(&listSuite{}) |
468 | |
469 | type listSuite struct { |
470 | - SnappySuite |
471 | + common.SnappySuite |
472 | } |
473 | |
474 | func getVersionFromConfig(c *check.C) string { |
475 | @@ -51,7 +52,7 @@ |
476 | } |
477 | |
478 | func (s *listSuite) TestListMustPrintCoreVersion(c *check.C) { |
479 | - listOutput := ExecCommand(c, "snappy", "list") |
480 | + listOutput := cli.ExecCommand(c, "snappy", "list") |
481 | |
482 | expected := "(?ms)" + |
483 | "Name +Date +Version +Developer *\n" + |
484 | @@ -62,12 +63,12 @@ |
485 | } |
486 | |
487 | func (s *listSuite) TestListMustPrintAppVersion(c *check.C) { |
488 | - InstallSnap(c, "hello-world") |
489 | + common.InstallSnap(c, "hello-world") |
490 | s.AddCleanup(func() { |
491 | - RemoveSnap(c, "hello-world") |
492 | + common.RemoveSnap(c, "hello-world") |
493 | }) |
494 | |
495 | - listOutput := ExecCommand(c, "snappy", "list") |
496 | + listOutput := cli.ExecCommand(c, "snappy", "list") |
497 | expected := "(?ms)" + |
498 | "Name +Date +Version +Developer *\n" + |
499 | ".*" + |
500 | |
501 | === modified file '_integration-tests/tests/rollback_test.go' |
502 | --- _integration-tests/tests/rollback_test.go 2015-10-01 14:40:47 +0000 |
503 | +++ _integration-tests/tests/rollback_test.go 2015-10-02 10:23:57 +0000 |
504 | @@ -22,37 +22,38 @@ |
505 | import ( |
506 | "strconv" |
507 | |
508 | - . "launchpad.net/snappy/_integration-tests/testutils/common" |
509 | + "launchpad.net/snappy/_integration-tests/testutils/cli" |
510 | + "launchpad.net/snappy/_integration-tests/testutils/common" |
511 | "launchpad.net/snappy/_integration-tests/testutils/partition" |
512 | "launchpad.net/snappy/_integration-tests/testutils/wait" |
513 | |
514 | - check "gopkg.in/check.v1" |
515 | + "gopkg.in/check.v1" |
516 | ) |
517 | |
518 | var _ = check.Suite(&rollbackSuite{}) |
519 | |
520 | type rollbackSuite struct { |
521 | - SnappySuite |
522 | + common.SnappySuite |
523 | } |
524 | |
525 | func (s *rollbackSuite) TestRollbackMustRebootToOtherVersion(c *check.C) { |
526 | - if BeforeReboot() { |
527 | - CallFakeUpdate(c) |
528 | - Reboot(c) |
529 | - } else if CheckRebootMark(c.TestName()) { |
530 | - RemoveRebootMark(c) |
531 | + if common.BeforeReboot() { |
532 | + common.CallFakeUpdate(c) |
533 | + common.Reboot(c) |
534 | + } else if common.CheckRebootMark(c.TestName()) { |
535 | + common.RemoveRebootMark(c) |
536 | // Workaround for bug https://bugs.launchpad.net/snappy/+bug/1498293 |
537 | // TODO remove once the bug is fixed. --elopio - 2015-09-30 |
538 | wait.ForFunction(c, "regular", partition.Mode) |
539 | - currentVersion := GetCurrentUbuntuCoreVersion(c) |
540 | - c.Assert(currentVersion > GetSavedVersion(c), check.Equals, true) |
541 | - ExecCommand(c, "sudo", "snappy", "rollback", "ubuntu-core", |
542 | - strconv.Itoa(GetSavedVersion(c))) |
543 | - SetSavedVersion(c, currentVersion) |
544 | - RebootWithMark(c, c.TestName()+"-rollback") |
545 | - } else if CheckRebootMark(c.TestName() + "-rollback") { |
546 | - RemoveRebootMark(c) |
547 | + currentVersion := common.GetCurrentUbuntuCoreVersion(c) |
548 | + c.Assert(currentVersion > common.GetSavedVersion(c), check.Equals, true) |
549 | + cli.ExecCommand(c, "sudo", "snappy", "rollback", "ubuntu-core", |
550 | + strconv.Itoa(common.GetSavedVersion(c))) |
551 | + common.SetSavedVersion(c, currentVersion) |
552 | + common.RebootWithMark(c, c.TestName()+"-rollback") |
553 | + } else if common.CheckRebootMark(c.TestName() + "-rollback") { |
554 | + common.RemoveRebootMark(c) |
555 | c.Assert( |
556 | - GetCurrentUbuntuCoreVersion(c) < GetSavedVersion(c), check.Equals, true) |
557 | + common.GetCurrentUbuntuCoreVersion(c) < common.GetSavedVersion(c), check.Equals, true) |
558 | } |
559 | } |
560 | |
561 | === modified file '_integration-tests/tests/search_test.go' |
562 | --- _integration-tests/tests/search_test.go 2015-07-28 04:03:52 +0000 |
563 | +++ _integration-tests/tests/search_test.go 2015-10-02 10:23:57 +0000 |
564 | @@ -20,19 +20,20 @@ |
565 | package tests |
566 | |
567 | import ( |
568 | - . "launchpad.net/snappy/_integration-tests/testutils/common" |
569 | + "launchpad.net/snappy/_integration-tests/testutils/cli" |
570 | + "launchpad.net/snappy/_integration-tests/testutils/common" |
571 | |
572 | - . "gopkg.in/check.v1" |
573 | + "gopkg.in/check.v1" |
574 | ) |
575 | |
576 | -var _ = Suite(&searchSuite{}) |
577 | +var _ = check.Suite(&searchSuite{}) |
578 | |
579 | type searchSuite struct { |
580 | - SnappySuite |
581 | + common.SnappySuite |
582 | } |
583 | |
584 | -func (s *searchSuite) TestSearchFrameworkMustPrintMatch(c *C) { |
585 | - searchOutput := ExecCommand(c, "snappy", "search", "hello-dbus-fwk") |
586 | +func (s *searchSuite) TestSearchFrameworkMustPrintMatch(c *check.C) { |
587 | + searchOutput := cli.ExecCommand(c, "snappy", "search", "hello-dbus-fwk") |
588 | |
589 | expected := "(?ms)" + |
590 | "Name +Version +Summary *\n" + |
591 | @@ -40,5 +41,5 @@ |
592 | "^hello-dbus-fwk +.* +hello-dbus-fwk *\n" + |
593 | ".*" |
594 | |
595 | - c.Assert(searchOutput, Matches, expected) |
596 | + c.Assert(searchOutput, check.Matches, expected) |
597 | } |
598 | |
599 | === modified file '_integration-tests/tests/ubuntuFan_test.go' |
600 | --- _integration-tests/tests/ubuntuFan_test.go 2015-09-24 21:06:01 +0000 |
601 | +++ _integration-tests/tests/ubuntuFan_test.go 2015-10-02 10:23:57 +0000 |
602 | @@ -25,6 +25,7 @@ |
603 | "os/exec" |
604 | "strings" |
605 | |
606 | + "launchpad.net/snappy/_integration-tests/testutils/cli" |
607 | "launchpad.net/snappy/_integration-tests/testutils/common" |
608 | "launchpad.net/snappy/_integration-tests/testutils/wait" |
609 | |
610 | @@ -75,7 +76,7 @@ |
611 | } |
612 | |
613 | func (s *fanTestSuite) TestFanCommandCreatesFanBridge(c *check.C) { |
614 | - output := common.ExecCommand(c, "ifconfig") |
615 | + output := cli.ExecCommand(c, "ifconfig") |
616 | |
617 | expectedPattern := fmt.Sprintf("(?msi).*%s.*%s.*", s.fanName(), s.bridgeIP) |
618 | |
619 | @@ -89,7 +90,7 @@ |
620 | s.configureDockerToUseBridge(c) |
621 | defer s.removeBridgeFromDockerConf(c) |
622 | |
623 | - output := common.ExecCommand(c, "docker", "run", "-t", baseContainer, "ifconfig") |
624 | + output := cli.ExecCommand(c, "docker", "run", "-t", baseContainer, "ifconfig") |
625 | |
626 | expectedIP := strings.TrimRight(s.bridgeIP, ".1") + ".2" |
627 | expectedPattern := fmt.Sprintf("(?ms).*inet addr:%s.*", expectedIP) |
628 | @@ -105,12 +106,12 @@ |
629 | defer s.removeBridgeFromDockerConf(c) |
630 | |
631 | // spin up first container |
632 | - common.ExecCommand(c, "docker", "run", "-d", "-t", baseContainer) |
633 | + cli.ExecCommand(c, "docker", "run", "-d", "-t", baseContainer) |
634 | // the first assigned IP in the fan will end with ".2" |
635 | firstIPAddr := strings.TrimRight(s.bridgeIP, ".1") + ".2" |
636 | |
637 | // ping from a second container |
638 | - output := common.ExecCommand(c, "docker", "run", "-t", baseContainer, "ping", firstIPAddr, "-c", "1") |
639 | + output := cli.ExecCommand(c, "docker", "run", "-t", baseContainer, "ping", firstIPAddr, "-c", "1") |
640 | |
641 | expectedPattern := "(?ms).*1 packets transmitted, 1 packets received, 0% packet loss.*" |
642 | |
643 | @@ -142,14 +143,14 @@ |
644 | } |
645 | |
646 | func (s *fanTestSuite) fanCtl(c *check.C, cmd string) string { |
647 | - return common.ExecCommand(c, |
648 | + return cli.ExecCommand(c, |
649 | "sudo", "fanctl", cmd, firstOverlaySegment+".0.0.0/8", s.subjectIP+"/16") |
650 | } |
651 | |
652 | func (s *fanTestSuite) configureDockerToUseBridge(c *check.C) { |
653 | cfgFile := dockerCfgFile(c) |
654 | |
655 | - common.ExecCommand(c, "sudo", "sed", "-i", |
656 | + cli.ExecCommand(c, "sudo", "sed", "-i", |
657 | fmt.Sprintf(`s/DOCKER_OPTIONS=\"\"/DOCKER_OPTIONS=\"%s\"/`, s.dockerOptions()), |
658 | cfgFile) |
659 | |
660 | @@ -159,7 +160,7 @@ |
661 | func (s *fanTestSuite) removeBridgeFromDockerConf(c *check.C) { |
662 | cfgFile := dockerCfgFile(c) |
663 | |
664 | - common.ExecCommand(c, "sudo", "sed", "-i", |
665 | + cli.ExecCommand(c, "sudo", "sed", "-i", |
666 | `s/DOCKER_OPTIONS=\".*\"/DOCKER_OPTIONS=\"\"/`, |
667 | cfgFile) |
668 | |
669 | @@ -175,7 +176,7 @@ |
670 | dockerVersion := common.GetCurrentVersion(c, "docker") |
671 | dockerService := fmt.Sprintf("docker_docker-daemon_%s.service", dockerVersion) |
672 | |
673 | - common.ExecCommand(c, "sudo", "systemctl", "restart", dockerService) |
674 | + cli.ExecCommand(c, "sudo", "systemctl", "restart", dockerService) |
675 | |
676 | // we need to wait until the socket is ready, an active systemctl status is not enough |
677 | err := wait.ForCommand(c, `(?ms).*docker\.sock\s.*`, "ls", "/run") |
678 | @@ -199,7 +200,7 @@ |
679 | err := wait.ForActiveService(c, dockerService) |
680 | c.Assert(err, check.IsNil) |
681 | |
682 | - common.ExecCommand(c, "docker", "pull", baseContainer) |
683 | + cli.ExecCommand(c, "docker", "pull", baseContainer) |
684 | } |
685 | |
686 | func tearDownDocker(c *check.C) { |
687 | |
688 | === modified file '_integration-tests/tests/update_test.go' |
689 | --- _integration-tests/tests/update_test.go 2015-09-10 15:55:23 +0000 |
690 | +++ _integration-tests/tests/update_test.go 2015-10-02 10:23:57 +0000 |
691 | @@ -23,7 +23,7 @@ |
692 | "io/ioutil" |
693 | "path" |
694 | |
695 | - . "launchpad.net/snappy/_integration-tests/testutils/common" |
696 | + "launchpad.net/snappy/_integration-tests/testutils/common" |
697 | "launchpad.net/snappy/_integration-tests/testutils/partition" |
698 | |
699 | "gopkg.in/check.v1" |
700 | @@ -32,7 +32,7 @@ |
701 | var _ = check.Suite(&updateSuite{}) |
702 | |
703 | type updateSuite struct { |
704 | - SnappySuite |
705 | + common.SnappySuite |
706 | } |
707 | |
708 | func (s *updateSuite) assertBootDirContents(c *check.C) { |
709 | @@ -62,17 +62,17 @@ |
710 | // modified to fake an update. If there is a version available, the image will |
711 | // be up-to-date after running this test. |
712 | func (s *updateSuite) TestUpdateToSameReleaseAndChannel(c *check.C) { |
713 | - if BeforeReboot() { |
714 | - updateOutput := CallFakeUpdate(c) |
715 | + if common.BeforeReboot() { |
716 | + updateOutput := common.CallFakeUpdate(c) |
717 | expected := "(?ms)" + |
718 | ".*" + |
719 | "^Reboot to use .*ubuntu-core.\n" |
720 | c.Assert(updateOutput, check.Matches, expected) |
721 | s.assertBootDirContents(c) |
722 | - Reboot(c) |
723 | - } else if AfterReboot(c) { |
724 | - RemoveRebootMark(c) |
725 | - c.Assert(GetCurrentUbuntuCoreVersion(c) > GetSavedVersion(c), |
726 | + common.Reboot(c) |
727 | + } else if common.AfterReboot(c) { |
728 | + common.RemoveRebootMark(c) |
729 | + c.Assert(common.GetCurrentUbuntuCoreVersion(c) > common.GetSavedVersion(c), |
730 | check.Equals, true) |
731 | } |
732 | } |
733 | |
734 | === modified file '_integration-tests/tests/writablePaths_test.go' |
735 | --- _integration-tests/tests/writablePaths_test.go 2015-07-28 04:03:52 +0000 |
736 | +++ _integration-tests/tests/writablePaths_test.go 2015-10-02 10:23:57 +0000 |
737 | @@ -27,9 +27,9 @@ |
738 | "path/filepath" |
739 | "strings" |
740 | |
741 | - . "launchpad.net/snappy/_integration-tests/testutils/common" |
742 | + "launchpad.net/snappy/_integration-tests/testutils/common" |
743 | |
744 | - check "gopkg.in/check.v1" |
745 | + "gopkg.in/check.v1" |
746 | ) |
747 | |
748 | const writablePathsListFile = "/etc/system-image/writable-paths" |
749 | @@ -37,7 +37,7 @@ |
750 | var _ = check.Suite(&writablePathsSuite{}) |
751 | |
752 | type writablePathsSuite struct { |
753 | - SnappySuite |
754 | + common.SnappySuite |
755 | } |
756 | |
757 | var IsWritable check.Checker = &isWritable{} |
758 | |
759 | === modified file '_integration-tests/testutils/build/snap.go' |
760 | --- _integration-tests/testutils/build/snap.go 2015-09-28 10:35:06 +0000 |
761 | +++ _integration-tests/testutils/build/snap.go 2015-10-02 10:23:57 +0000 |
762 | @@ -24,7 +24,7 @@ |
763 | "path/filepath" |
764 | |
765 | "gopkg.in/check.v1" |
766 | - "launchpad.net/snappy/_integration-tests/testutils/common" |
767 | + "launchpad.net/snappy/_integration-tests/testutils/cli" |
768 | ) |
769 | |
770 | const ( |
771 | @@ -42,11 +42,11 @@ |
772 | |
773 | var ( |
774 | // dependency aliasing |
775 | - commonExecCommand = common.ExecCommand |
776 | + cliExecCommand = cli.ExecCommand |
777 | ) |
778 | |
779 | func buildSnap(c *check.C, snapPath string) string { |
780 | - return commonExecCommand(c, "snappy", "build", snapPath, "-o", snapPath) |
781 | + return cliExecCommand(c, "snappy", "build", snapPath, "-o", snapPath) |
782 | } |
783 | |
784 | // LocalSnap issues the command to build a snap and returns the path of the generated file |
785 | |
786 | === modified file '_integration-tests/testutils/build/snap_test.go' |
787 | --- _integration-tests/testutils/build/snap_test.go 2015-09-28 10:44:44 +0000 |
788 | +++ _integration-tests/testutils/build/snap_test.go 2015-10-02 10:23:57 +0000 |
789 | @@ -37,13 +37,13 @@ |
790 | var _ = check.Suite(&snapBuildTestSuite{}) |
791 | |
792 | func (s *snapBuildTestSuite) SetUpSuite(c *check.C) { |
793 | - s.backExecCommand = commonExecCommand |
794 | - commonExecCommand = s.fakeExecCommand |
795 | + s.backExecCommand = cliExecCommand |
796 | + cliExecCommand = s.fakeExecCommand |
797 | s.defaultSnapName = "mySnapName" |
798 | } |
799 | |
800 | func (s *snapBuildTestSuite) TearDownSuite(c *check.C) { |
801 | - commonExecCommand = s.backExecCommand |
802 | + cliExecCommand = s.backExecCommand |
803 | } |
804 | |
805 | func (s *snapBuildTestSuite) SetUpTest(c *check.C) { |
806 | |
807 | === added directory '_integration-tests/testutils/cli' |
808 | === added file '_integration-tests/testutils/cli/cli.go' |
809 | --- _integration-tests/testutils/cli/cli.go 1970-01-01 00:00:00 +0000 |
810 | +++ _integration-tests/testutils/cli/cli.go 2015-10-02 10:23:57 +0000 |
811 | @@ -0,0 +1,57 @@ |
812 | +// -*- Mode: Go; indent-tabs-mode: t -*- |
813 | + |
814 | +/* |
815 | + * Copyright (C) 2015 Canonical Ltd |
816 | + * |
817 | + * This program is free software: you can redistribute it and/or modify |
818 | + * it under the terms of the GNU General Public License version 3 as |
819 | + * published by the Free Software Foundation. |
820 | + * |
821 | + * This program is distributed in the hope that it will be useful, |
822 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
823 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
824 | + * GNU General Public License for more details. |
825 | + * |
826 | + * You should have received a copy of the GNU General Public License |
827 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
828 | + * |
829 | + */ |
830 | + |
831 | +package cli |
832 | + |
833 | +import ( |
834 | + "fmt" |
835 | + "os" |
836 | + "os/exec" |
837 | + "strings" |
838 | + |
839 | + "gopkg.in/check.v1" |
840 | +) |
841 | + |
842 | +var execCommand = exec.Command |
843 | + |
844 | +// ExecCommand executes a shell command and returns a string with the output |
845 | +// of the command. In case of error, it will fail the test. |
846 | +func ExecCommand(c *check.C, cmds ...string) string { |
847 | + fmt.Println(strings.Join(cmds, " ")) |
848 | + cmd := execCommand(cmds[0], cmds[1:len(cmds)]...) |
849 | + output, err := cmd.CombinedOutput() |
850 | + stringOutput := string(output) |
851 | + fmt.Print(stringOutput) |
852 | + c.Assert(err, check.IsNil, check.Commentf("Error: %v", stringOutput)) |
853 | + return stringOutput |
854 | +} |
855 | + |
856 | +// ExecCommandToFile executes a shell command and saves the output of the |
857 | +// command to a file. In case of error, it will fail the test. |
858 | +func ExecCommandToFile(c *check.C, filename string, cmds ...string) { |
859 | + cmd := execCommand(cmds[0], cmds[1:len(cmds)]...) |
860 | + outfile, err := os.Create(filename) |
861 | + c.Assert(err, check.IsNil, check.Commentf("Error creating output file %s", filename)) |
862 | + |
863 | + defer outfile.Close() |
864 | + cmd.Stdout = outfile |
865 | + |
866 | + err = cmd.Run() |
867 | + c.Assert(err, check.IsNil, check.Commentf("Error executing command '%v': %v", cmds, err)) |
868 | +} |
869 | |
870 | === added file '_integration-tests/testutils/cli/cli_test.go' |
871 | --- _integration-tests/testutils/cli/cli_test.go 1970-01-01 00:00:00 +0000 |
872 | +++ _integration-tests/testutils/cli/cli_test.go 2015-10-02 10:23:57 +0000 |
873 | @@ -0,0 +1,85 @@ |
874 | +// -*- Mode: Go; indent-tabs-mode: t -*- |
875 | + |
876 | +/* |
877 | + * Copyright (C) 2015 Canonical Ltd |
878 | + * |
879 | + * This program is free software: you can redistribute it and/or modify |
880 | + * it under the terms of the GNU General Public License version 3 as |
881 | + * published by the Free Software Foundation. |
882 | + * |
883 | + * This program is distributed in the hope that it will be useful, |
884 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
885 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
886 | + * GNU General Public License for more details. |
887 | + * |
888 | + * You should have received a copy of the GNU General Public License |
889 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
890 | + * |
891 | + */ |
892 | + |
893 | +package cli |
894 | + |
895 | +import ( |
896 | + "fmt" |
897 | + "io/ioutil" |
898 | + "os" |
899 | + "os/exec" |
900 | + "testing" |
901 | + |
902 | + "gopkg.in/check.v1" |
903 | +) |
904 | + |
905 | +const execOutput = "myoutput" |
906 | + |
907 | +// Hook up check.v1 into the "go test" runner |
908 | +func Test(t *testing.T) { check.TestingT(t) } |
909 | + |
910 | +type cliTestSuite struct { |
911 | + backExecCommand func(string, ...string) *exec.Cmd |
912 | +} |
913 | + |
914 | +var _ = check.Suite(&cliTestSuite{}) |
915 | + |
916 | +func (s *cliTestSuite) SetUpSuite(c *check.C) { |
917 | + s.backExecCommand = execCommand |
918 | + execCommand = s.fakeExecCommand |
919 | +} |
920 | + |
921 | +func (s *cliTestSuite) TearDownSuite(c *check.C) { |
922 | + execCommand = s.backExecCommand |
923 | +} |
924 | + |
925 | +func (s *cliTestSuite) fakeExecCommand(command string, args ...string) *exec.Cmd { |
926 | + cs := []string{"-check.f=cliTestSuite.TestHelperProcess", "--", command} |
927 | + cs = append(cs, args...) |
928 | + cmd := exec.Command(os.Args[0], cs...) |
929 | + cmd.Env = []string{"GO_WANT_HELPER_PROCESS=1"} |
930 | + return cmd |
931 | +} |
932 | + |
933 | +func (s *cliTestSuite) TestHelperProcess(c *check.C) { |
934 | + if os.Getenv("GO_WANT_HELPER_PROCESS") != "1" { |
935 | + return |
936 | + } |
937 | + fmt.Fprintf(os.Stdout, execOutput) |
938 | + os.Exit(0) |
939 | +} |
940 | + |
941 | +func (s *cliTestSuite) TestExecCommand(c *check.C) { |
942 | + actualOutput := ExecCommand(c, "mycmd") |
943 | + |
944 | + c.Assert(actualOutput, check.Equals, execOutput) |
945 | +} |
946 | + |
947 | +func (s *cliTestSuite) TestExecCommandToFile(c *check.C) { |
948 | + outputFile, err := ioutil.TempFile("", "snappy-exec") |
949 | + c.Assert(err, check.IsNil) |
950 | + outputFile.Close() |
951 | + defer os.Remove(outputFile.Name()) |
952 | + |
953 | + ExecCommandToFile(c, outputFile.Name(), "mycmd") |
954 | + |
955 | + actualFileContents, err := ioutil.ReadFile(outputFile.Name()) |
956 | + c.Assert(err, check.IsNil) |
957 | + c.Assert(string(actualFileContents), check.Equals, execOutput) |
958 | +} |
959 | |
960 | === modified file '_integration-tests/testutils/common/common.go' |
961 | --- _integration-tests/testutils/common/common.go 2015-09-28 14:42:52 +0000 |
962 | +++ _integration-tests/testutils/common/common.go 2015-10-02 10:23:57 +0000 |
963 | @@ -23,7 +23,6 @@ |
964 | "fmt" |
965 | "io/ioutil" |
966 | "os" |
967 | - "os/exec" |
968 | "path/filepath" |
969 | "regexp" |
970 | "strconv" |
971 | @@ -31,6 +30,7 @@ |
972 | |
973 | "gopkg.in/check.v1" |
974 | |
975 | + "launchpad.net/snappy/_integration-tests/testutils/cli" |
976 | "launchpad.net/snappy/_integration-tests/testutils/config" |
977 | ) |
978 | |
979 | @@ -54,8 +54,8 @@ |
980 | // SetUpSuite disables the snappy autopilot. It will run before all the |
981 | // integration suites. |
982 | func (s *SnappySuite) SetUpSuite(c *check.C) { |
983 | - ExecCommand(c, "sudo", "systemctl", "stop", "snappy-autopilot.timer") |
984 | - ExecCommand(c, "sudo", "systemctl", "disable", "snappy-autopilot.timer") |
985 | + cli.ExecCommand(c, "sudo", "systemctl", "stop", "snappy-autopilot.timer") |
986 | + cli.ExecCommand(c, "sudo", "systemctl", "disable", "snappy-autopilot.timer") |
987 | var err error |
988 | Cfg, err = config.ReadConfig( |
989 | "_integration-tests/data/output/testconfig.json") |
990 | @@ -66,7 +66,7 @@ |
991 | switchSystemImageConf(c, Cfg.TargetRelease, Cfg.TargetChannel, "0") |
992 | // Always use the installed snappy because we are updating from an old |
993 | // image, so we should not use the snappy from the branch. |
994 | - output := ExecCommand(c, "sudo", "/usr/bin/snappy", "update") |
995 | + output := cli.ExecCommand(c, "sudo", "/usr/bin/snappy", "update") |
996 | if output != "" { |
997 | RebootWithMark(c, "setupsuite-update") |
998 | } |
999 | @@ -77,7 +77,7 @@ |
1000 | Cfg.Update = false |
1001 | Cfg.Write() |
1002 | if Cfg.Rollback { |
1003 | - ExecCommand(c, "sudo", "snappy", "rollback", "ubuntu-core") |
1004 | + cli.ExecCommand(c, "sudo", "snappy", "rollback", "ubuntu-core") |
1005 | RebootWithMark(c, "setupsuite-rollback") |
1006 | } |
1007 | } else if CheckRebootMark("setupsuite-rollback") { |
1008 | @@ -131,7 +131,7 @@ |
1009 | defer MakeReadonly(c, target) |
1010 | original := filepath.Join(target, channelCfgFile) |
1011 | c.Logf("Restoring %s...", original) |
1012 | - ExecCommand(c, "sudo", "mv", backup, original) |
1013 | + cli.ExecCommand(c, "sudo", "mv", backup, original) |
1014 | } |
1015 | } |
1016 | } |
1017 | @@ -169,12 +169,12 @@ |
1018 | } |
1019 | for value, regex := range replaceRegex { |
1020 | if value != "" { |
1021 | - ExecCommand(c, |
1022 | + cli.ExecCommand(c, |
1023 | "sudo", "sed", "-i", fmt.Sprintf(regex, value), file) |
1024 | } |
1025 | } |
1026 | // Leave the new file in the test log. |
1027 | - ExecCommand(c, "cat", file) |
1028 | + cli.ExecCommand(c, "cat", file) |
1029 | } |
1030 | |
1031 | func channelCfgBackupFile() string { |
1032 | @@ -185,35 +185,9 @@ |
1033 | return filepath.Join(os.Getenv("ADT_ARTIFACTS"), "channel.ini.other") |
1034 | } |
1035 | |
1036 | -// ExecCommand executes a shell command and returns a string with the output |
1037 | -// of the command. In case of error, it will fail the test. |
1038 | -func ExecCommand(c *check.C, cmds ...string) string { |
1039 | - fmt.Println(strings.Join(cmds, " ")) |
1040 | - cmd := exec.Command(cmds[0], cmds[1:len(cmds)]...) |
1041 | - output, err := cmd.CombinedOutput() |
1042 | - stringOutput := string(output) |
1043 | - fmt.Print(stringOutput) |
1044 | - c.Assert(err, check.IsNil, check.Commentf("Error: %v", stringOutput)) |
1045 | - return stringOutput |
1046 | -} |
1047 | - |
1048 | -// ExecCommandToFile executes a shell command and saves the output of the |
1049 | -// command to a file. In case of error, it will fail the test. |
1050 | -func ExecCommandToFile(c *check.C, filename string, cmds ...string) { |
1051 | - cmd := exec.Command(cmds[0], cmds[1:len(cmds)]...) |
1052 | - outfile, err := os.Create(filename) |
1053 | - c.Assert(err, check.IsNil, check.Commentf("Error creating output file %s", filename)) |
1054 | - |
1055 | - defer outfile.Close() |
1056 | - cmd.Stdout = outfile |
1057 | - |
1058 | - err = cmd.Run() |
1059 | - c.Assert(err, check.IsNil, check.Commentf("Error executing command '%v': %v", cmds, err)) |
1060 | -} |
1061 | - |
1062 | // GetCurrentVersion returns the version of the installed and active package. |
1063 | func GetCurrentVersion(c *check.C, packageName string) string { |
1064 | - output := ExecCommand(c, "snappy", "list") |
1065 | + output := cli.ExecCommand(c, "snappy", "list") |
1066 | pattern := "(?mU)^" + packageName + " +(.*)$" |
1067 | re := regexp.MustCompile(pattern) |
1068 | match := re.FindStringSubmatch(string(output)) |
1069 | @@ -237,7 +211,7 @@ |
1070 | func CallFakeUpdate(c *check.C) string { |
1071 | c.Log("Preparing fake and calling update.") |
1072 | fakeAvailableUpdate(c) |
1073 | - return ExecCommand(c, "sudo", "snappy", "update") |
1074 | + return cli.ExecCommand(c, "sudo", "snappy", "update") |
1075 | } |
1076 | |
1077 | func fakeAvailableUpdate(c *check.C) { |
1078 | @@ -257,7 +231,7 @@ |
1079 | MakeWritable(c, target) |
1080 | defer MakeReadonly(c, target) |
1081 | // Back up the file. It will be restored during the test tear down. |
1082 | - ExecCommand(c, "cp", file, backup) |
1083 | + cli.ExecCommand(c, "cp", file, backup) |
1084 | replaceSystemImageValues(c, file, "", "", strconv.Itoa(newVersion)) |
1085 | } |
1086 | } |
1087 | @@ -265,12 +239,12 @@ |
1088 | |
1089 | // MakeWritable remounts a path with read and write permissions. |
1090 | func MakeWritable(c *check.C, path string) { |
1091 | - ExecCommand(c, "sudo", "mount", "-o", "remount,rw", path) |
1092 | + cli.ExecCommand(c, "sudo", "mount", "-o", "remount,rw", path) |
1093 | } |
1094 | |
1095 | // MakeReadonly remounts a path with only read permissions. |
1096 | func MakeReadonly(c *check.C, path string) { |
1097 | - ExecCommand(c, "sudo", "mount", "-o", "remount,ro", path) |
1098 | + cli.ExecCommand(c, "sudo", "mount", "-o", "remount,ro", path) |
1099 | } |
1100 | |
1101 | // Reboot requests a reboot using the test name as the mark. |
1102 | @@ -346,10 +320,10 @@ |
1103 | |
1104 | // InstallSnap executes the required command to install the specified snap |
1105 | func InstallSnap(c *check.C, packageName string) string { |
1106 | - return ExecCommand(c, "sudo", "snappy", "install", packageName, "--allow-unauthenticated") |
1107 | + return cli.ExecCommand(c, "sudo", "snappy", "install", packageName, "--allow-unauthenticated") |
1108 | } |
1109 | |
1110 | // RemoveSnap executes the required command to remove the specified snap |
1111 | func RemoveSnap(c *check.C, packageName string) string { |
1112 | - return ExecCommand(c, "sudo", "snappy", "remove", packageName) |
1113 | + return cli.ExecCommand(c, "sudo", "snappy", "remove", packageName) |
1114 | } |
1115 | |
1116 | === modified file '_integration-tests/testutils/common/info.go' |
1117 | --- _integration-tests/testutils/common/info.go 2015-09-24 21:06:01 +0000 |
1118 | +++ _integration-tests/testutils/common/info.go 2015-10-02 10:23:57 +0000 |
1119 | @@ -24,10 +24,11 @@ |
1120 | "strings" |
1121 | |
1122 | "gopkg.in/check.v1" |
1123 | + "launchpad.net/snappy/_integration-tests/testutils/cli" |
1124 | ) |
1125 | |
1126 | // dependency aliasing |
1127 | -var execCommand = ExecCommand |
1128 | +var execCommand = cli.ExecCommand |
1129 | |
1130 | // Release returns the release of the current snappy image |
1131 | func Release(c *check.C) string { |
1132 | |
1133 | === modified file '_integration-tests/testutils/runner/runner.go' |
1134 | --- _integration-tests/testutils/runner/runner.go 2015-08-12 15:50:33 +0000 |
1135 | +++ _integration-tests/testutils/runner/runner.go 2015-10-02 10:23:57 +0000 |
1136 | @@ -25,7 +25,7 @@ |
1137 | "strings" |
1138 | "testing" |
1139 | |
1140 | - check "gopkg.in/check.v1" |
1141 | + "gopkg.in/check.v1" |
1142 | ) |
1143 | |
1144 | var ( |
1145 | |
1146 | === modified file '_integration-tests/testutils/wait/wait.go' |
1147 | --- _integration-tests/testutils/wait/wait.go 2015-09-28 10:54:40 +0000 |
1148 | +++ _integration-tests/testutils/wait/wait.go 2015-10-02 10:23:57 +0000 |
1149 | @@ -24,14 +24,14 @@ |
1150 | "regexp" |
1151 | "time" |
1152 | |
1153 | - check "gopkg.in/check.v1" |
1154 | + "gopkg.in/check.v1" |
1155 | |
1156 | - "launchpad.net/snappy/_integration-tests/testutils/common" |
1157 | + "launchpad.net/snappy/_integration-tests/testutils/cli" |
1158 | ) |
1159 | |
1160 | var ( |
1161 | // dependency aliasing |
1162 | - execCommand = common.ExecCommand |
1163 | + execCommand = cli.ExecCommand |
1164 | // ForCommand dep alias |
1165 | ForCommand = forCommand |
1166 | // ForFunction dep alias |
needs a merge with trunk.
Feel free to top approve it after you get a full successful run.
Thanks!