Merge lp:~fgimenez/snappy/cli-pkg into lp:~snappy-dev/snappy/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
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.

[1] http://npf.io/2015/06/testing-exec-command/

To post a comment you must log in.
Revision history for this message
Leo Arias (elopio) wrote :

needs a merge with trunk.
Feel free to top approve it after you get a full successful run.

Thanks!

review: Needs Fixing
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
=== modified file '_integration-tests/tests/apt_test.go'
--- _integration-tests/tests/apt_test.go 2015-07-28 04:03:52 +0000
+++ _integration-tests/tests/apt_test.go 2015-10-02 10:23:57 +0000
@@ -20,19 +20,20 @@
20package tests20package tests
2121
22import (22import (
23 . "launchpad.net/snappy/_integration-tests/testutils/common"23 "launchpad.net/snappy/_integration-tests/testutils/cli"
24 "launchpad.net/snappy/_integration-tests/testutils/common"
2425
25 check "gopkg.in/check.v1"26 "gopkg.in/check.v1"
26)27)
2728
28var _ = check.Suite(&aptSuite{})29var _ = check.Suite(&aptSuite{})
2930
30type aptSuite struct {31type aptSuite struct {
31 SnappySuite32 common.SnappySuite
32}33}
3334
34func (s *aptSuite) TestAptGetMustPrintError(c *check.C) {35func (s *aptSuite) TestAptGetMustPrintError(c *check.C) {
35 aptOutput := ExecCommand(c, "apt-get", "update")36 aptOutput := cli.ExecCommand(c, "apt-get", "update")
3637
37 expected := "Ubuntu Core does not use apt-get, see 'snappy --help'!\n"38 expected := "Ubuntu Core does not use apt-get, see 'snappy --help'!\n"
38 c.Assert(aptOutput, check.Equals, expected)39 c.Assert(aptOutput, check.Equals, expected)
3940
=== modified file '_integration-tests/tests/config_test.go'
--- _integration-tests/tests/config_test.go 2015-09-30 08:07:52 +0000
+++ _integration-tests/tests/config_test.go 2015-10-02 10:23:57 +0000
@@ -24,6 +24,7 @@
24 "os"24 "os"
25 "strings"25 "strings"
2626
27 "launchpad.net/snappy/_integration-tests/testutils/cli"
27 "launchpad.net/snappy/_integration-tests/testutils/common"28 "launchpad.net/snappy/_integration-tests/testutils/common"
2829
29 "gopkg.in/check.v1"30 "gopkg.in/check.v1"
@@ -97,13 +98,13 @@
97 }98 }
98 _, err = configFile.Write([]byte(config))99 _, err = configFile.Write([]byte(config))
99100
100 common.ExecCommand(c, "sudo", "snappy", "config", "ubuntu-core", configFile.Name())101 cli.ExecCommand(c, "sudo", "snappy", "config", "ubuntu-core", configFile.Name())
101102
102 return103 return
103}104}
104105
105func currentConfig(c *check.C) string {106func currentConfig(c *check.C) string {
106 return common.ExecCommand(c, "sudo", "snappy", "config", "ubuntu-core")107 return cli.ExecCommand(c, "sudo", "snappy", "config", "ubuntu-core")
107}108}
108109
109func configString(cfg string) string {110func configString(cfg string) string {
110111
=== modified file '_integration-tests/tests/failover_rclocal_crash_test.go'
--- _integration-tests/tests/failover_rclocal_crash_test.go 2015-09-09 06:56:19 +0000
+++ _integration-tests/tests/failover_rclocal_crash_test.go 2015-10-02 10:23:57 +0000
@@ -22,26 +22,28 @@
22import (22import (
23 "fmt"23 "fmt"
2424
25 . "launchpad.net/snappy/_integration-tests/testutils/common"25 "launchpad.net/snappy/_integration-tests/testutils/cli"
26 "launchpad.net/snappy/_integration-tests/testutils/common"
2627
27 check "gopkg.in/check.v1"28 "gopkg.in/check.v1"
28)29)
2930
30type rcLocalCrash struct{}31type rcLocalCrash struct{}
3132
32func (rcLocalCrash) set(c *check.C) {33func (rcLocalCrash) set(c *check.C) {
33 MakeWritable(c, BaseAltPartitionPath)34 common.MakeWritable(c, common.BaseAltPartitionPath)
34 defer MakeReadonly(c, BaseAltPartitionPath)35 defer common.MakeReadonly(c, common.BaseAltPartitionPath)
35 targetFile := fmt.Sprintf("%s/etc/rc.local", BaseAltPartitionPath)36 targetFile := fmt.Sprintf("%s/etc/rc.local", common.BaseAltPartitionPath)
36 ExecCommand(c, "sudo", "chmod", "a+xw", targetFile)37 cli.ExecCommand(c, "sudo", "chmod", "a+xw", targetFile)
37 ExecCommandToFile(c, targetFile,38
39 cli.ExecCommandToFile(c, targetFile,
38 "sudo", "echo", "#!bin/sh\nprintf c > /proc/sysrq-trigger")40 "sudo", "echo", "#!bin/sh\nprintf c > /proc/sysrq-trigger")
39}41}
4042
41func (rcLocalCrash) unset(c *check.C) {43func (rcLocalCrash) unset(c *check.C) {
42 MakeWritable(c, BaseAltPartitionPath)44 common.MakeWritable(c, common.BaseAltPartitionPath)
43 defer MakeReadonly(c, BaseAltPartitionPath)45 defer common.MakeReadonly(c, common.BaseAltPartitionPath)
44 ExecCommand(c, "sudo", "rm", fmt.Sprintf("%s/etc/rc.local", BaseAltPartitionPath))46 cli.ExecCommand(c, "sudo", "rm", fmt.Sprintf("%s/etc/rc.local", common.BaseAltPartitionPath))
45}47}
4648
47/*49/*
4850
=== modified file '_integration-tests/tests/failover_systemd_loop_test.go'
--- _integration-tests/tests/failover_systemd_loop_test.go 2015-07-30 16:22:30 +0000
+++ _integration-tests/tests/failover_systemd_loop_test.go 2015-10-02 10:23:57 +0000
@@ -22,9 +22,10 @@
22import (22import (
23 "fmt"23 "fmt"
2424
25 . "launchpad.net/snappy/_integration-tests/testutils/common"25 "launchpad.net/snappy/_integration-tests/testutils/cli"
26 "launchpad.net/snappy/_integration-tests/testutils/common"
2627
27 check "gopkg.in/check.v1"28 "gopkg.in/check.v1"
28)29)
2930
30const (31const (
@@ -61,51 +62,51 @@
61type systemdDependencyLoop struct{}62type systemdDependencyLoop struct{}
6263
63func (systemdDependencyLoop) set(c *check.C) {64func (systemdDependencyLoop) set(c *check.C) {
64 installService(c, "deadlock", deadlockService, BaseAltPartitionPath)65 installService(c, "deadlock", deadlockService, common.BaseAltPartitionPath)
65 installService(c, "emerg-reboot", rebootService, BaseAltPartitionPath)66 installService(c, "emerg-reboot", rebootService, common.BaseAltPartitionPath)
66}67}
6768
68func (systemdDependencyLoop) unset(c *check.C) {69func (systemdDependencyLoop) unset(c *check.C) {
69 unInstallService(c, "deadlock", BaseAltPartitionPath)70 unInstallService(c, "deadlock", common.BaseAltPartitionPath)
70 unInstallService(c, "emerg-reboot", BaseAltPartitionPath)71 unInstallService(c, "emerg-reboot", common.BaseAltPartitionPath)
71}72}
7273
73func installService(c *check.C, serviceName, serviceCfg, basePath string) {74func installService(c *check.C, serviceName, serviceCfg, basePath string) {
74 MakeWritable(c, basePath)75 common.MakeWritable(c, basePath)
75 defer MakeReadonly(c, basePath)76 defer common.MakeReadonly(c, basePath)
7677
77 // Create service file78 // Create service file
78 serviceFile := fmt.Sprintf("%s%s/%s.service", basePath, baseSystemdPath, serviceName)79 serviceFile := fmt.Sprintf("%s%s/%s.service", basePath, baseSystemdPath, serviceName)
79 ExecCommand(c, "sudo", "chmod", "a+w", fmt.Sprintf("%s%s", basePath, baseSystemdPath))80 cli.ExecCommand(c, "sudo", "chmod", "a+w", fmt.Sprintf("%s%s", basePath, baseSystemdPath))
80 ExecCommandToFile(c, serviceFile, "sudo", "echo", serviceCfg)81 cli.ExecCommandToFile(c, serviceFile, "sudo", "echo", serviceCfg)
8182
82 // Create requires directory83 // Create requires directory
83 requiresDirPart := fmt.Sprintf("%s/%s", baseSystemdPath, systemdTargetRequiresDir)84 requiresDirPart := fmt.Sprintf("%s/%s", baseSystemdPath, systemdTargetRequiresDir)
84 requiresDir := fmt.Sprintf("%s%s", basePath, requiresDirPart)85 requiresDir := fmt.Sprintf("%s%s", basePath, requiresDirPart)
85 ExecCommand(c, "sudo", "mkdir", "-p", requiresDir)86 cli.ExecCommand(c, "sudo", "mkdir", "-p", requiresDir)
8687
87 // Symlink from the requires dir to the service file (with chroot for being88 // Symlink from the requires dir to the service file (with chroot for being
88 // usable in the other partition)89 // usable in the other partition)
89 ExecCommand(c, "sudo", "chroot", basePath, "ln", "-s",90 cli.ExecCommand(c, "sudo", "chroot", basePath, "ln", "-s",
90 fmt.Sprintf("%s/%s.service", baseSystemdPath, serviceName),91 fmt.Sprintf("%s/%s.service", baseSystemdPath, serviceName),
91 fmt.Sprintf("%s/%s.service", requiresDirPart, serviceName),92 fmt.Sprintf("%s/%s.service", requiresDirPart, serviceName),
92 )93 )
93}94}
9495
95func unInstallService(c *check.C, serviceName, basePath string) {96func unInstallService(c *check.C, serviceName, basePath string) {
96 MakeWritable(c, basePath)97 common.MakeWritable(c, basePath)
97 defer MakeReadonly(c, basePath)98 defer common.MakeReadonly(c, basePath)
9899
99 // Disable the service100 // Disable the service
100 ExecCommand(c, "sudo", "chroot", basePath,101 cli.ExecCommand(c, "sudo", "chroot", basePath,
101 "systemctl", "disable", fmt.Sprintf("%s.service", serviceName))102 "systemctl", "disable", fmt.Sprintf("%s.service", serviceName))
102103
103 // Remove the service file104 // Remove the service file
104 ExecCommand(c, "sudo", "rm",105 cli.ExecCommand(c, "sudo", "rm",
105 fmt.Sprintf("%s%s/%s.service", basePath, baseSystemdPath, serviceName))106 fmt.Sprintf("%s%s/%s.service", basePath, baseSystemdPath, serviceName))
106107
107 // Remove the requires symlink108 // Remove the requires symlink
108 ExecCommand(c, "sudo", "rm",109 cli.ExecCommand(c, "sudo", "rm",
109 fmt.Sprintf("%s%s/%s/%s.service", basePath, baseSystemdPath, systemdTargetRequiresDir, serviceName))110 fmt.Sprintf("%s%s/%s/%s.service", basePath, baseSystemdPath, systemdTargetRequiresDir, serviceName))
110}111}
111112
112113
=== modified file '_integration-tests/tests/failover_test.go'
--- _integration-tests/tests/failover_test.go 2015-07-28 04:03:52 +0000
+++ _integration-tests/tests/failover_test.go 2015-10-02 10:23:57 +0000
@@ -20,15 +20,15 @@
20package tests20package tests
2121
22import (22import (
23 check "gopkg.in/check.v1"23 "gopkg.in/check.v1"
2424
25 . "launchpad.net/snappy/_integration-tests/testutils/common"25 "launchpad.net/snappy/_integration-tests/testutils/common"
26)26)
2727
28var _ = check.Suite(&failoverSuite{})28var _ = check.Suite(&failoverSuite{})
2929
30type failoverSuite struct {30type failoverSuite struct {
31 SnappySuite31 common.SnappySuite
32}32}
3333
34// The types that implement this interface can be used in the test logic34// The types that implement this interface can be used in the test logic
@@ -43,16 +43,16 @@
43// type implementing the failer interface and call this function with an instance43// type implementing the failer interface and call this function with an instance
44// of it44// of it
45func commonFailoverTest(c *check.C, f failer) {45func commonFailoverTest(c *check.C, f failer) {
46 currentVersion := GetCurrentUbuntuCoreVersion(c)46 currentVersion := common.GetCurrentUbuntuCoreVersion(c)
4747
48 if AfterReboot(c) {48 if common.AfterReboot(c) {
49 RemoveRebootMark(c)49 common.RemoveRebootMark(c)
50 f.unset(c)50 f.unset(c)
51 c.Assert(GetSavedVersion(c), check.Equals, currentVersion)51 c.Assert(common.GetSavedVersion(c), check.Equals, currentVersion)
52 } else {52 } else {
53 SetSavedVersion(c, currentVersion-1)53 common.SetSavedVersion(c, currentVersion-1)
54 CallFakeUpdate(c)54 common.CallFakeUpdate(c)
55 f.set(c)55 f.set(c)
56 Reboot(c)56 common.Reboot(c)
57 }57 }
58}58}
5959
=== modified file '_integration-tests/tests/failover_zero_size_file_test.go'
--- _integration-tests/tests/failover_zero_size_file_test.go 2015-09-25 14:35:29 +0000
+++ _integration-tests/tests/failover_zero_size_file_test.go 2015-10-02 10:23:57 +0000
@@ -25,7 +25,8 @@
25 "path/filepath"25 "path/filepath"
26 "strings"26 "strings"
2727
28 . "launchpad.net/snappy/_integration-tests/testutils/common"28 "launchpad.net/snappy/_integration-tests/testutils/cli"
29 "launchpad.net/snappy/_integration-tests/testutils/common"
29 "launchpad.net/snappy/_integration-tests/testutils/partition"30 "launchpad.net/snappy/_integration-tests/testutils/partition"
3031
31 "gopkg.in/check.v1"32 "gopkg.in/check.v1"
@@ -45,11 +46,11 @@
45type zeroSizeSystemd struct{}46type zeroSizeSystemd struct{}
4647
47func (zeroSizeKernel) set(c *check.C) {48func (zeroSizeKernel) set(c *check.C) {
48 commonSet(c, BaseAltPartitionPath, origBootFilenamePattern, kernelFilename)49 commonSet(c, common.BaseAltPartitionPath, origBootFilenamePattern, kernelFilename)
49}50}
5051
51func (zeroSizeKernel) unset(c *check.C) {52func (zeroSizeKernel) unset(c *check.C) {
52 commonUnset(c, BaseAltPartitionPath, origBootFilenamePattern, kernelFilename)53 commonUnset(c, common.BaseAltPartitionPath, origBootFilenamePattern, kernelFilename)
53}54}
5455
55func (zeroSizeInitrd) set(c *check.C) {56func (zeroSizeInitrd) set(c *check.C) {
@@ -71,11 +72,11 @@
71}72}
7273
73func (zeroSizeSystemd) set(c *check.C) {74func (zeroSizeSystemd) set(c *check.C) {
74 commonSet(c, BaseAltPartitionPath, origSystemdFilenamePattern, systemdFilename)75 commonSet(c, common.BaseAltPartitionPath, origSystemdFilenamePattern, systemdFilename)
75}76}
7677
77func (zeroSizeSystemd) unset(c *check.C) {78func (zeroSizeSystemd) unset(c *check.C) {
78 commonUnset(c, BaseAltPartitionPath, origSystemdFilenamePattern, systemdFilename)79 commonUnset(c, common.BaseAltPartitionPath, origSystemdFilenamePattern, systemdFilename)
79}80}
8081
81func commonSet(c *check.C, baseOtherPath, origPattern, filename string) {82func commonSet(c *check.C, baseOtherPath, origPattern, filename string) {
@@ -105,17 +106,17 @@
105func renameFile(c *check.C, basePath, oldFilename, newFilename string, keepOld bool) {106func renameFile(c *check.C, basePath, oldFilename, newFilename string, keepOld bool) {
106 // Only need to make writable and revert for BaseAltPartitionPath,107 // Only need to make writable and revert for BaseAltPartitionPath,
107 // kernel files' boot directory is writable108 // kernel files' boot directory is writable
108 if basePath == BaseAltPartitionPath {109 if basePath == common.BaseAltPartitionPath {
109 MakeWritable(c, basePath)110 common.MakeWritable(c, basePath)
110 defer MakeReadonly(c, basePath)111 defer common.MakeReadonly(c, basePath)
111 }112 }
112113
113 ExecCommand(c, "sudo", "mv", oldFilename, newFilename)114 cli.ExecCommand(c, "sudo", "mv", oldFilename, newFilename)
114115
115 if keepOld {116 if keepOld {
116 ExecCommand(c, "sudo", "touch", oldFilename)117 cli.ExecCommand(c, "sudo", "touch", oldFilename)
117 mode := getFileMode(c, newFilename)118 mode := getFileMode(c, newFilename)
118 ExecCommand(c, "sudo", "chmod", fmt.Sprintf("%o", mode), oldFilename)119 cli.ExecCommand(c, "sudo", "chmod", fmt.Sprintf("%o", mode), oldFilename)
119 }120 }
120}121}
121122
122123
=== modified file '_integration-tests/tests/helloDbus_test.go'
--- _integration-tests/tests/helloDbus_test.go 2015-09-11 08:47:39 +0000
+++ _integration-tests/tests/helloDbus_test.go 2015-10-02 10:23:57 +0000
@@ -20,6 +20,7 @@
20package tests20package tests
2121
22import (22import (
23 "launchpad.net/snappy/_integration-tests/testutils/cli"
23 "launchpad.net/snappy/_integration-tests/testutils/common"24 "launchpad.net/snappy/_integration-tests/testutils/common"
2425
25 "gopkg.in/check.v1"26 "gopkg.in/check.v1"
@@ -38,7 +39,7 @@
38 common.InstallSnap(c, "hello-dbus-app.canonical")39 common.InstallSnap(c, "hello-dbus-app.canonical")
39 defer common.RemoveSnap(c, "hello-dbus-app.canonical")40 defer common.RemoveSnap(c, "hello-dbus-app.canonical")
4041
41 output := common.ExecCommand(c, "hello-dbus-app.client")42 output := cli.ExecCommand(c, "hello-dbus-app.client")
4243
43 expected := "PASS\n"44 expected := "PASS\n"
4445
4546
=== modified file '_integration-tests/tests/info_test.go'
--- _integration-tests/tests/info_test.go 2015-07-31 07:55:33 +0000
+++ _integration-tests/tests/info_test.go 2015-10-02 10:23:57 +0000
@@ -22,41 +22,42 @@
22import (22import (
23 "fmt"23 "fmt"
2424
25 . "launchpad.net/snappy/_integration-tests/testutils/common"25 "launchpad.net/snappy/_integration-tests/testutils/cli"
26 "launchpad.net/snappy/_integration-tests/testutils/common"
2627
27 check "gopkg.in/check.v1"28 "gopkg.in/check.v1"
28)29)
2930
30var _ = check.Suite(&infoSuite{})31var _ = check.Suite(&infoSuite{})
3132
32type infoSuite struct {33type infoSuite struct {
33 SnappySuite34 common.SnappySuite
34}35}
3536
36func (s *infoSuite) TestInfoMustPrintReleaseAndChannel(c *check.C) {37func (s *infoSuite) TestInfoMustPrintReleaseAndChannel(c *check.C) {
37 // skip test when having a remote testbed (we can't know which the38 // skip test when having a remote testbed (we can't know which the
38 // release and channels are)39 // release and channels are)
39 if Cfg.RemoteTestbed {40 if common.Cfg.RemoteTestbed {
40 c.Skip(fmt.Sprintf(41 c.Skip(fmt.Sprintf(
41 "Skipping %s while testing in remote testbed",42 "Skipping %s while testing in remote testbed",
42 c.TestName()))43 c.TestName()))
43 }44 }
4445
45 infoOutput := ExecCommand(c, "snappy", "info")46 infoOutput := cli.ExecCommand(c, "snappy", "info")
4647
47 expected := "(?ms)" +48 expected := "(?ms)" +
48 fmt.Sprintf("^release: ubuntu-core/%s/%s\n", Cfg.Release, Cfg.Channel) +49 fmt.Sprintf("^release: ubuntu-core/%s/%s\n", common.Cfg.Release, common.Cfg.Channel) +
49 ".*"50 ".*"
5051
51 c.Assert(infoOutput, check.Matches, expected)52 c.Assert(infoOutput, check.Matches, expected)
52}53}
5354
54func (s *infoSuite) TestInfoMustPrintInstalledApps(c *check.C) {55func (s *infoSuite) TestInfoMustPrintInstalledApps(c *check.C) {
55 InstallSnap(c, "hello-world")56 common.InstallSnap(c, "hello-world")
56 s.AddCleanup(func() {57 s.AddCleanup(func() {
57 RemoveSnap(c, "hello-world")58 common.RemoveSnap(c, "hello-world")
58 })59 })
59 infoOutput := ExecCommand(c, "snappy", "info")60 infoOutput := cli.ExecCommand(c, "snappy", "info")
6061
61 expected := "(?ms)" +62 expected := "(?ms)" +
62 ".*" +63 ".*" +
@@ -65,11 +66,11 @@
65}66}
6667
67func (s *infoSuite) TestInfoMustPrintInstalledFrameworks(c *check.C) {68func (s *infoSuite) TestInfoMustPrintInstalledFrameworks(c *check.C) {
68 InstallSnap(c, "hello-dbus-fwk.canonical")69 common.InstallSnap(c, "hello-dbus-fwk.canonical")
69 s.AddCleanup(func() {70 s.AddCleanup(func() {
70 RemoveSnap(c, "hello-dbus-fwk.canonical")71 common.RemoveSnap(c, "hello-dbus-fwk.canonical")
71 })72 })
72 infoOutput := ExecCommand(c, "snappy", "info")73 infoOutput := cli.ExecCommand(c, "snappy", "info")
7374
74 expected := "(?ms)" +75 expected := "(?ms)" +
75 ".*" +76 ".*" +
7677
=== modified file '_integration-tests/tests/installApp_test.go'
--- _integration-tests/tests/installApp_test.go 2015-09-24 19:51:26 +0000
+++ _integration-tests/tests/installApp_test.go 2015-10-02 10:23:57 +0000
@@ -23,10 +23,11 @@
23 "net/http"23 "net/http"
24 "os/exec"24 "os/exec"
2525
26 "launchpad.net/snappy/_integration-tests/testutils/cli"
26 "launchpad.net/snappy/_integration-tests/testutils/common"27 "launchpad.net/snappy/_integration-tests/testutils/common"
27 "launchpad.net/snappy/_integration-tests/testutils/wait"28 "launchpad.net/snappy/_integration-tests/testutils/wait"
2829
29 check "gopkg.in/check.v1"30 "gopkg.in/check.v1"
30)31)
3132
32var _ = check.Suite(&installAppSuite{})33var _ = check.Suite(&installAppSuite{})
@@ -57,7 +58,7 @@
57 common.RemoveSnap(c, "hello-world")58 common.RemoveSnap(c, "hello-world")
58 })59 })
5960
60 echoOutput := common.ExecCommand(c, "hello-world.echo")61 echoOutput := cli.ExecCommand(c, "hello-world.echo")
6162
62 c.Assert(echoOutput, check.Equals, "Hello World!\n")63 c.Assert(echoOutput, check.Equals, "Hello World!\n")
63}64}
@@ -89,7 +90,7 @@
89 common.RemoveSnap(c, "hello-world")90 common.RemoveSnap(c, "hello-world")
90 })91 })
9192
92 infoOutput := common.ExecCommand(c, "snappy", "info")93 infoOutput := cli.ExecCommand(c, "snappy", "info")
9394
94 expected := "(?ms).*^apps: hello-world.canonical\n"95 expected := "(?ms).*^apps: hello-world.canonical\n"
95 c.Assert(infoOutput, check.Matches, expected)96 c.Assert(infoOutput, check.Matches, expected)
9697
=== modified file '_integration-tests/tests/installFramework_test.go'
--- _integration-tests/tests/installFramework_test.go 2015-09-03 10:46:21 +0000
+++ _integration-tests/tests/installFramework_test.go 2015-10-02 10:23:57 +0000
@@ -23,10 +23,11 @@
23 "fmt"23 "fmt"
24 "regexp"24 "regexp"
2525
26 "launchpad.net/snappy/_integration-tests/testutils/cli"
26 "launchpad.net/snappy/_integration-tests/testutils/common"27 "launchpad.net/snappy/_integration-tests/testutils/common"
27 "launchpad.net/snappy/_integration-tests/testutils/wait"28 "launchpad.net/snappy/_integration-tests/testutils/wait"
2829
29 check "gopkg.in/check.v1"30 "gopkg.in/check.v1"
30)31)
3132
32var _ = check.Suite(&installFrameworkSuite{})33var _ = check.Suite(&installFrameworkSuite{})
@@ -50,7 +51,7 @@
50 err := wait.ForActiveService(c, dockerService)51 err := wait.ForActiveService(c, dockerService)
51 c.Assert(err, check.IsNil)52 c.Assert(err, check.IsNil)
5253
53 statusOutput := common.ExecCommand(54 statusOutput := cli.ExecCommand(
54 c, "systemctl", "status",55 c, "systemctl", "status",
55 dockerService)56 dockerService)
5657
5758
=== modified file '_integration-tests/tests/list_test.go'
--- _integration-tests/tests/list_test.go 2015-07-28 04:03:52 +0000
+++ _integration-tests/tests/list_test.go 2015-10-02 10:23:57 +0000
@@ -23,16 +23,17 @@
23 "fmt"23 "fmt"
24 "os"24 "os"
2525
26 . "launchpad.net/snappy/_integration-tests/testutils/common"26 "launchpad.net/snappy/_integration-tests/testutils/cli"
27 "launchpad.net/snappy/_integration-tests/testutils/common"
2728
28 "github.com/mvo5/goconfigparser"29 "github.com/mvo5/goconfigparser"
29 check "gopkg.in/check.v1"30 "gopkg.in/check.v1"
30)31)
3132
32var _ = check.Suite(&listSuite{})33var _ = check.Suite(&listSuite{})
3334
34type listSuite struct {35type listSuite struct {
35 SnappySuite36 common.SnappySuite
36}37}
3738
38func getVersionFromConfig(c *check.C) string {39func getVersionFromConfig(c *check.C) string {
@@ -51,7 +52,7 @@
51}52}
5253
53func (s *listSuite) TestListMustPrintCoreVersion(c *check.C) {54func (s *listSuite) TestListMustPrintCoreVersion(c *check.C) {
54 listOutput := ExecCommand(c, "snappy", "list")55 listOutput := cli.ExecCommand(c, "snappy", "list")
5556
56 expected := "(?ms)" +57 expected := "(?ms)" +
57 "Name +Date +Version +Developer *\n" +58 "Name +Date +Version +Developer *\n" +
@@ -62,12 +63,12 @@
62}63}
6364
64func (s *listSuite) TestListMustPrintAppVersion(c *check.C) {65func (s *listSuite) TestListMustPrintAppVersion(c *check.C) {
65 InstallSnap(c, "hello-world")66 common.InstallSnap(c, "hello-world")
66 s.AddCleanup(func() {67 s.AddCleanup(func() {
67 RemoveSnap(c, "hello-world")68 common.RemoveSnap(c, "hello-world")
68 })69 })
6970
70 listOutput := ExecCommand(c, "snappy", "list")71 listOutput := cli.ExecCommand(c, "snappy", "list")
71 expected := "(?ms)" +72 expected := "(?ms)" +
72 "Name +Date +Version +Developer *\n" +73 "Name +Date +Version +Developer *\n" +
73 ".*" +74 ".*" +
7475
=== modified file '_integration-tests/tests/rollback_test.go'
--- _integration-tests/tests/rollback_test.go 2015-10-01 14:40:47 +0000
+++ _integration-tests/tests/rollback_test.go 2015-10-02 10:23:57 +0000
@@ -22,37 +22,38 @@
22import (22import (
23 "strconv"23 "strconv"
2424
25 . "launchpad.net/snappy/_integration-tests/testutils/common"25 "launchpad.net/snappy/_integration-tests/testutils/cli"
26 "launchpad.net/snappy/_integration-tests/testutils/common"
26 "launchpad.net/snappy/_integration-tests/testutils/partition"27 "launchpad.net/snappy/_integration-tests/testutils/partition"
27 "launchpad.net/snappy/_integration-tests/testutils/wait"28 "launchpad.net/snappy/_integration-tests/testutils/wait"
2829
29 check "gopkg.in/check.v1"30 "gopkg.in/check.v1"
30)31)
3132
32var _ = check.Suite(&rollbackSuite{})33var _ = check.Suite(&rollbackSuite{})
3334
34type rollbackSuite struct {35type rollbackSuite struct {
35 SnappySuite36 common.SnappySuite
36}37}
3738
38func (s *rollbackSuite) TestRollbackMustRebootToOtherVersion(c *check.C) {39func (s *rollbackSuite) TestRollbackMustRebootToOtherVersion(c *check.C) {
39 if BeforeReboot() {40 if common.BeforeReboot() {
40 CallFakeUpdate(c)41 common.CallFakeUpdate(c)
41 Reboot(c)42 common.Reboot(c)
42 } else if CheckRebootMark(c.TestName()) {43 } else if common.CheckRebootMark(c.TestName()) {
43 RemoveRebootMark(c)44 common.RemoveRebootMark(c)
44 // Workaround for bug https://bugs.launchpad.net/snappy/+bug/149829345 // Workaround for bug https://bugs.launchpad.net/snappy/+bug/1498293
45 // TODO remove once the bug is fixed. --elopio - 2015-09-3046 // TODO remove once the bug is fixed. --elopio - 2015-09-30
46 wait.ForFunction(c, "regular", partition.Mode)47 wait.ForFunction(c, "regular", partition.Mode)
47 currentVersion := GetCurrentUbuntuCoreVersion(c)48 currentVersion := common.GetCurrentUbuntuCoreVersion(c)
48 c.Assert(currentVersion > GetSavedVersion(c), check.Equals, true)49 c.Assert(currentVersion > common.GetSavedVersion(c), check.Equals, true)
49 ExecCommand(c, "sudo", "snappy", "rollback", "ubuntu-core",50 cli.ExecCommand(c, "sudo", "snappy", "rollback", "ubuntu-core",
50 strconv.Itoa(GetSavedVersion(c)))51 strconv.Itoa(common.GetSavedVersion(c)))
51 SetSavedVersion(c, currentVersion)52 common.SetSavedVersion(c, currentVersion)
52 RebootWithMark(c, c.TestName()+"-rollback")53 common.RebootWithMark(c, c.TestName()+"-rollback")
53 } else if CheckRebootMark(c.TestName() + "-rollback") {54 } else if common.CheckRebootMark(c.TestName() + "-rollback") {
54 RemoveRebootMark(c)55 common.RemoveRebootMark(c)
55 c.Assert(56 c.Assert(
56 GetCurrentUbuntuCoreVersion(c) < GetSavedVersion(c), check.Equals, true)57 common.GetCurrentUbuntuCoreVersion(c) < common.GetSavedVersion(c), check.Equals, true)
57 }58 }
58}59}
5960
=== modified file '_integration-tests/tests/search_test.go'
--- _integration-tests/tests/search_test.go 2015-07-28 04:03:52 +0000
+++ _integration-tests/tests/search_test.go 2015-10-02 10:23:57 +0000
@@ -20,19 +20,20 @@
20package tests20package tests
2121
22import (22import (
23 . "launchpad.net/snappy/_integration-tests/testutils/common"23 "launchpad.net/snappy/_integration-tests/testutils/cli"
24 "launchpad.net/snappy/_integration-tests/testutils/common"
2425
25 . "gopkg.in/check.v1"26 "gopkg.in/check.v1"
26)27)
2728
28var _ = Suite(&searchSuite{})29var _ = check.Suite(&searchSuite{})
2930
30type searchSuite struct {31type searchSuite struct {
31 SnappySuite32 common.SnappySuite
32}33}
3334
34func (s *searchSuite) TestSearchFrameworkMustPrintMatch(c *C) {35func (s *searchSuite) TestSearchFrameworkMustPrintMatch(c *check.C) {
35 searchOutput := ExecCommand(c, "snappy", "search", "hello-dbus-fwk")36 searchOutput := cli.ExecCommand(c, "snappy", "search", "hello-dbus-fwk")
3637
37 expected := "(?ms)" +38 expected := "(?ms)" +
38 "Name +Version +Summary *\n" +39 "Name +Version +Summary *\n" +
@@ -40,5 +41,5 @@
40 "^hello-dbus-fwk +.* +hello-dbus-fwk *\n" +41 "^hello-dbus-fwk +.* +hello-dbus-fwk *\n" +
41 ".*"42 ".*"
4243
43 c.Assert(searchOutput, Matches, expected)44 c.Assert(searchOutput, check.Matches, expected)
44}45}
4546
=== modified file '_integration-tests/tests/ubuntuFan_test.go'
--- _integration-tests/tests/ubuntuFan_test.go 2015-09-24 21:06:01 +0000
+++ _integration-tests/tests/ubuntuFan_test.go 2015-10-02 10:23:57 +0000
@@ -25,6 +25,7 @@
25 "os/exec"25 "os/exec"
26 "strings"26 "strings"
2727
28 "launchpad.net/snappy/_integration-tests/testutils/cli"
28 "launchpad.net/snappy/_integration-tests/testutils/common"29 "launchpad.net/snappy/_integration-tests/testutils/common"
29 "launchpad.net/snappy/_integration-tests/testutils/wait"30 "launchpad.net/snappy/_integration-tests/testutils/wait"
3031
@@ -75,7 +76,7 @@
75}76}
7677
77func (s *fanTestSuite) TestFanCommandCreatesFanBridge(c *check.C) {78func (s *fanTestSuite) TestFanCommandCreatesFanBridge(c *check.C) {
78 output := common.ExecCommand(c, "ifconfig")79 output := cli.ExecCommand(c, "ifconfig")
7980
80 expectedPattern := fmt.Sprintf("(?msi).*%s.*%s.*", s.fanName(), s.bridgeIP)81 expectedPattern := fmt.Sprintf("(?msi).*%s.*%s.*", s.fanName(), s.bridgeIP)
8182
@@ -89,7 +90,7 @@
89 s.configureDockerToUseBridge(c)90 s.configureDockerToUseBridge(c)
90 defer s.removeBridgeFromDockerConf(c)91 defer s.removeBridgeFromDockerConf(c)
9192
92 output := common.ExecCommand(c, "docker", "run", "-t", baseContainer, "ifconfig")93 output := cli.ExecCommand(c, "docker", "run", "-t", baseContainer, "ifconfig")
9394
94 expectedIP := strings.TrimRight(s.bridgeIP, ".1") + ".2"95 expectedIP := strings.TrimRight(s.bridgeIP, ".1") + ".2"
95 expectedPattern := fmt.Sprintf("(?ms).*inet addr:%s.*", expectedIP)96 expectedPattern := fmt.Sprintf("(?ms).*inet addr:%s.*", expectedIP)
@@ -105,12 +106,12 @@
105 defer s.removeBridgeFromDockerConf(c)106 defer s.removeBridgeFromDockerConf(c)
106107
107 // spin up first container108 // spin up first container
108 common.ExecCommand(c, "docker", "run", "-d", "-t", baseContainer)109 cli.ExecCommand(c, "docker", "run", "-d", "-t", baseContainer)
109 // the first assigned IP in the fan will end with ".2"110 // the first assigned IP in the fan will end with ".2"
110 firstIPAddr := strings.TrimRight(s.bridgeIP, ".1") + ".2"111 firstIPAddr := strings.TrimRight(s.bridgeIP, ".1") + ".2"
111112
112 // ping from a second container113 // ping from a second container
113 output := common.ExecCommand(c, "docker", "run", "-t", baseContainer, "ping", firstIPAddr, "-c", "1")114 output := cli.ExecCommand(c, "docker", "run", "-t", baseContainer, "ping", firstIPAddr, "-c", "1")
114115
115 expectedPattern := "(?ms).*1 packets transmitted, 1 packets received, 0% packet loss.*"116 expectedPattern := "(?ms).*1 packets transmitted, 1 packets received, 0% packet loss.*"
116117
@@ -142,14 +143,14 @@
142}143}
143144
144func (s *fanTestSuite) fanCtl(c *check.C, cmd string) string {145func (s *fanTestSuite) fanCtl(c *check.C, cmd string) string {
145 return common.ExecCommand(c,146 return cli.ExecCommand(c,
146 "sudo", "fanctl", cmd, firstOverlaySegment+".0.0.0/8", s.subjectIP+"/16")147 "sudo", "fanctl", cmd, firstOverlaySegment+".0.0.0/8", s.subjectIP+"/16")
147}148}
148149
149func (s *fanTestSuite) configureDockerToUseBridge(c *check.C) {150func (s *fanTestSuite) configureDockerToUseBridge(c *check.C) {
150 cfgFile := dockerCfgFile(c)151 cfgFile := dockerCfgFile(c)
151152
152 common.ExecCommand(c, "sudo", "sed", "-i",153 cli.ExecCommand(c, "sudo", "sed", "-i",
153 fmt.Sprintf(`s/DOCKER_OPTIONS=\"\"/DOCKER_OPTIONS=\"%s\"/`, s.dockerOptions()),154 fmt.Sprintf(`s/DOCKER_OPTIONS=\"\"/DOCKER_OPTIONS=\"%s\"/`, s.dockerOptions()),
154 cfgFile)155 cfgFile)
155156
@@ -159,7 +160,7 @@
159func (s *fanTestSuite) removeBridgeFromDockerConf(c *check.C) {160func (s *fanTestSuite) removeBridgeFromDockerConf(c *check.C) {
160 cfgFile := dockerCfgFile(c)161 cfgFile := dockerCfgFile(c)
161162
162 common.ExecCommand(c, "sudo", "sed", "-i",163 cli.ExecCommand(c, "sudo", "sed", "-i",
163 `s/DOCKER_OPTIONS=\".*\"/DOCKER_OPTIONS=\"\"/`,164 `s/DOCKER_OPTIONS=\".*\"/DOCKER_OPTIONS=\"\"/`,
164 cfgFile)165 cfgFile)
165166
@@ -175,7 +176,7 @@
175 dockerVersion := common.GetCurrentVersion(c, "docker")176 dockerVersion := common.GetCurrentVersion(c, "docker")
176 dockerService := fmt.Sprintf("docker_docker-daemon_%s.service", dockerVersion)177 dockerService := fmt.Sprintf("docker_docker-daemon_%s.service", dockerVersion)
177178
178 common.ExecCommand(c, "sudo", "systemctl", "restart", dockerService)179 cli.ExecCommand(c, "sudo", "systemctl", "restart", dockerService)
179180
180 // we need to wait until the socket is ready, an active systemctl status is not enough181 // we need to wait until the socket is ready, an active systemctl status is not enough
181 err := wait.ForCommand(c, `(?ms).*docker\.sock\s.*`, "ls", "/run")182 err := wait.ForCommand(c, `(?ms).*docker\.sock\s.*`, "ls", "/run")
@@ -199,7 +200,7 @@
199 err := wait.ForActiveService(c, dockerService)200 err := wait.ForActiveService(c, dockerService)
200 c.Assert(err, check.IsNil)201 c.Assert(err, check.IsNil)
201202
202 common.ExecCommand(c, "docker", "pull", baseContainer)203 cli.ExecCommand(c, "docker", "pull", baseContainer)
203}204}
204205
205func tearDownDocker(c *check.C) {206func tearDownDocker(c *check.C) {
206207
=== modified file '_integration-tests/tests/update_test.go'
--- _integration-tests/tests/update_test.go 2015-09-10 15:55:23 +0000
+++ _integration-tests/tests/update_test.go 2015-10-02 10:23:57 +0000
@@ -23,7 +23,7 @@
23 "io/ioutil"23 "io/ioutil"
24 "path"24 "path"
2525
26 . "launchpad.net/snappy/_integration-tests/testutils/common"26 "launchpad.net/snappy/_integration-tests/testutils/common"
27 "launchpad.net/snappy/_integration-tests/testutils/partition"27 "launchpad.net/snappy/_integration-tests/testutils/partition"
2828
29 "gopkg.in/check.v1"29 "gopkg.in/check.v1"
@@ -32,7 +32,7 @@
32var _ = check.Suite(&updateSuite{})32var _ = check.Suite(&updateSuite{})
3333
34type updateSuite struct {34type updateSuite struct {
35 SnappySuite35 common.SnappySuite
36}36}
3737
38func (s *updateSuite) assertBootDirContents(c *check.C) {38func (s *updateSuite) assertBootDirContents(c *check.C) {
@@ -62,17 +62,17 @@
62// modified to fake an update. If there is a version available, the image will62// modified to fake an update. If there is a version available, the image will
63// be up-to-date after running this test.63// be up-to-date after running this test.
64func (s *updateSuite) TestUpdateToSameReleaseAndChannel(c *check.C) {64func (s *updateSuite) TestUpdateToSameReleaseAndChannel(c *check.C) {
65 if BeforeReboot() {65 if common.BeforeReboot() {
66 updateOutput := CallFakeUpdate(c)66 updateOutput := common.CallFakeUpdate(c)
67 expected := "(?ms)" +67 expected := "(?ms)" +
68 ".*" +68 ".*" +
69 "^Reboot to use .*ubuntu-core.\n"69 "^Reboot to use .*ubuntu-core.\n"
70 c.Assert(updateOutput, check.Matches, expected)70 c.Assert(updateOutput, check.Matches, expected)
71 s.assertBootDirContents(c)71 s.assertBootDirContents(c)
72 Reboot(c)72 common.Reboot(c)
73 } else if AfterReboot(c) {73 } else if common.AfterReboot(c) {
74 RemoveRebootMark(c)74 common.RemoveRebootMark(c)
75 c.Assert(GetCurrentUbuntuCoreVersion(c) > GetSavedVersion(c),75 c.Assert(common.GetCurrentUbuntuCoreVersion(c) > common.GetSavedVersion(c),
76 check.Equals, true)76 check.Equals, true)
77 }77 }
78}78}
7979
=== modified file '_integration-tests/tests/writablePaths_test.go'
--- _integration-tests/tests/writablePaths_test.go 2015-07-28 04:03:52 +0000
+++ _integration-tests/tests/writablePaths_test.go 2015-10-02 10:23:57 +0000
@@ -27,9 +27,9 @@
27 "path/filepath"27 "path/filepath"
28 "strings"28 "strings"
2929
30 . "launchpad.net/snappy/_integration-tests/testutils/common"30 "launchpad.net/snappy/_integration-tests/testutils/common"
3131
32 check "gopkg.in/check.v1"32 "gopkg.in/check.v1"
33)33)
3434
35const writablePathsListFile = "/etc/system-image/writable-paths"35const writablePathsListFile = "/etc/system-image/writable-paths"
@@ -37,7 +37,7 @@
37var _ = check.Suite(&writablePathsSuite{})37var _ = check.Suite(&writablePathsSuite{})
3838
39type writablePathsSuite struct {39type writablePathsSuite struct {
40 SnappySuite40 common.SnappySuite
41}41}
4242
43var IsWritable check.Checker = &isWritable{}43var IsWritable check.Checker = &isWritable{}
4444
=== modified file '_integration-tests/testutils/build/snap.go'
--- _integration-tests/testutils/build/snap.go 2015-09-28 10:35:06 +0000
+++ _integration-tests/testutils/build/snap.go 2015-10-02 10:23:57 +0000
@@ -24,7 +24,7 @@
24 "path/filepath"24 "path/filepath"
2525
26 "gopkg.in/check.v1"26 "gopkg.in/check.v1"
27 "launchpad.net/snappy/_integration-tests/testutils/common"27 "launchpad.net/snappy/_integration-tests/testutils/cli"
28)28)
2929
30const (30const (
@@ -42,11 +42,11 @@
4242
43var (43var (
44 // dependency aliasing44 // dependency aliasing
45 commonExecCommand = common.ExecCommand45 cliExecCommand = cli.ExecCommand
46)46)
4747
48func buildSnap(c *check.C, snapPath string) string {48func buildSnap(c *check.C, snapPath string) string {
49 return commonExecCommand(c, "snappy", "build", snapPath, "-o", snapPath)49 return cliExecCommand(c, "snappy", "build", snapPath, "-o", snapPath)
50}50}
5151
52// LocalSnap issues the command to build a snap and returns the path of the generated file52// LocalSnap issues the command to build a snap and returns the path of the generated file
5353
=== modified file '_integration-tests/testutils/build/snap_test.go'
--- _integration-tests/testutils/build/snap_test.go 2015-09-28 10:44:44 +0000
+++ _integration-tests/testutils/build/snap_test.go 2015-10-02 10:23:57 +0000
@@ -37,13 +37,13 @@
37var _ = check.Suite(&snapBuildTestSuite{})37var _ = check.Suite(&snapBuildTestSuite{})
3838
39func (s *snapBuildTestSuite) SetUpSuite(c *check.C) {39func (s *snapBuildTestSuite) SetUpSuite(c *check.C) {
40 s.backExecCommand = commonExecCommand40 s.backExecCommand = cliExecCommand
41 commonExecCommand = s.fakeExecCommand41 cliExecCommand = s.fakeExecCommand
42 s.defaultSnapName = "mySnapName"42 s.defaultSnapName = "mySnapName"
43}43}
4444
45func (s *snapBuildTestSuite) TearDownSuite(c *check.C) {45func (s *snapBuildTestSuite) TearDownSuite(c *check.C) {
46 commonExecCommand = s.backExecCommand46 cliExecCommand = s.backExecCommand
47}47}
4848
49func (s *snapBuildTestSuite) SetUpTest(c *check.C) {49func (s *snapBuildTestSuite) SetUpTest(c *check.C) {
5050
=== added directory '_integration-tests/testutils/cli'
=== added file '_integration-tests/testutils/cli/cli.go'
--- _integration-tests/testutils/cli/cli.go 1970-01-01 00:00:00 +0000
+++ _integration-tests/testutils/cli/cli.go 2015-10-02 10:23:57 +0000
@@ -0,0 +1,57 @@
1// -*- Mode: Go; indent-tabs-mode: t -*-
2
3/*
4 * Copyright (C) 2015 Canonical Ltd
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 3 as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 */
19
20package cli
21
22import (
23 "fmt"
24 "os"
25 "os/exec"
26 "strings"
27
28 "gopkg.in/check.v1"
29)
30
31var execCommand = exec.Command
32
33// ExecCommand executes a shell command and returns a string with the output
34// of the command. In case of error, it will fail the test.
35func ExecCommand(c *check.C, cmds ...string) string {
36 fmt.Println(strings.Join(cmds, " "))
37 cmd := execCommand(cmds[0], cmds[1:len(cmds)]...)
38 output, err := cmd.CombinedOutput()
39 stringOutput := string(output)
40 fmt.Print(stringOutput)
41 c.Assert(err, check.IsNil, check.Commentf("Error: %v", stringOutput))
42 return stringOutput
43}
44
45// ExecCommandToFile executes a shell command and saves the output of the
46// command to a file. In case of error, it will fail the test.
47func ExecCommandToFile(c *check.C, filename string, cmds ...string) {
48 cmd := execCommand(cmds[0], cmds[1:len(cmds)]...)
49 outfile, err := os.Create(filename)
50 c.Assert(err, check.IsNil, check.Commentf("Error creating output file %s", filename))
51
52 defer outfile.Close()
53 cmd.Stdout = outfile
54
55 err = cmd.Run()
56 c.Assert(err, check.IsNil, check.Commentf("Error executing command '%v': %v", cmds, err))
57}
058
=== added file '_integration-tests/testutils/cli/cli_test.go'
--- _integration-tests/testutils/cli/cli_test.go 1970-01-01 00:00:00 +0000
+++ _integration-tests/testutils/cli/cli_test.go 2015-10-02 10:23:57 +0000
@@ -0,0 +1,85 @@
1// -*- Mode: Go; indent-tabs-mode: t -*-
2
3/*
4 * Copyright (C) 2015 Canonical Ltd
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 3 as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 */
19
20package cli
21
22import (
23 "fmt"
24 "io/ioutil"
25 "os"
26 "os/exec"
27 "testing"
28
29 "gopkg.in/check.v1"
30)
31
32const execOutput = "myoutput"
33
34// Hook up check.v1 into the "go test" runner
35func Test(t *testing.T) { check.TestingT(t) }
36
37type cliTestSuite struct {
38 backExecCommand func(string, ...string) *exec.Cmd
39}
40
41var _ = check.Suite(&cliTestSuite{})
42
43func (s *cliTestSuite) SetUpSuite(c *check.C) {
44 s.backExecCommand = execCommand
45 execCommand = s.fakeExecCommand
46}
47
48func (s *cliTestSuite) TearDownSuite(c *check.C) {
49 execCommand = s.backExecCommand
50}
51
52func (s *cliTestSuite) fakeExecCommand(command string, args ...string) *exec.Cmd {
53 cs := []string{"-check.f=cliTestSuite.TestHelperProcess", "--", command}
54 cs = append(cs, args...)
55 cmd := exec.Command(os.Args[0], cs...)
56 cmd.Env = []string{"GO_WANT_HELPER_PROCESS=1"}
57 return cmd
58}
59
60func (s *cliTestSuite) TestHelperProcess(c *check.C) {
61 if os.Getenv("GO_WANT_HELPER_PROCESS") != "1" {
62 return
63 }
64 fmt.Fprintf(os.Stdout, execOutput)
65 os.Exit(0)
66}
67
68func (s *cliTestSuite) TestExecCommand(c *check.C) {
69 actualOutput := ExecCommand(c, "mycmd")
70
71 c.Assert(actualOutput, check.Equals, execOutput)
72}
73
74func (s *cliTestSuite) TestExecCommandToFile(c *check.C) {
75 outputFile, err := ioutil.TempFile("", "snappy-exec")
76 c.Assert(err, check.IsNil)
77 outputFile.Close()
78 defer os.Remove(outputFile.Name())
79
80 ExecCommandToFile(c, outputFile.Name(), "mycmd")
81
82 actualFileContents, err := ioutil.ReadFile(outputFile.Name())
83 c.Assert(err, check.IsNil)
84 c.Assert(string(actualFileContents), check.Equals, execOutput)
85}
086
=== modified file '_integration-tests/testutils/common/common.go'
--- _integration-tests/testutils/common/common.go 2015-09-28 14:42:52 +0000
+++ _integration-tests/testutils/common/common.go 2015-10-02 10:23:57 +0000
@@ -23,7 +23,6 @@
23 "fmt"23 "fmt"
24 "io/ioutil"24 "io/ioutil"
25 "os"25 "os"
26 "os/exec"
27 "path/filepath"26 "path/filepath"
28 "regexp"27 "regexp"
29 "strconv"28 "strconv"
@@ -31,6 +30,7 @@
3130
32 "gopkg.in/check.v1"31 "gopkg.in/check.v1"
3332
33 "launchpad.net/snappy/_integration-tests/testutils/cli"
34 "launchpad.net/snappy/_integration-tests/testutils/config"34 "launchpad.net/snappy/_integration-tests/testutils/config"
35)35)
3636
@@ -54,8 +54,8 @@
54// SetUpSuite disables the snappy autopilot. It will run before all the54// SetUpSuite disables the snappy autopilot. It will run before all the
55// integration suites.55// integration suites.
56func (s *SnappySuite) SetUpSuite(c *check.C) {56func (s *SnappySuite) SetUpSuite(c *check.C) {
57 ExecCommand(c, "sudo", "systemctl", "stop", "snappy-autopilot.timer")57 cli.ExecCommand(c, "sudo", "systemctl", "stop", "snappy-autopilot.timer")
58 ExecCommand(c, "sudo", "systemctl", "disable", "snappy-autopilot.timer")58 cli.ExecCommand(c, "sudo", "systemctl", "disable", "snappy-autopilot.timer")
59 var err error59 var err error
60 Cfg, err = config.ReadConfig(60 Cfg, err = config.ReadConfig(
61 "_integration-tests/data/output/testconfig.json")61 "_integration-tests/data/output/testconfig.json")
@@ -66,7 +66,7 @@
66 switchSystemImageConf(c, Cfg.TargetRelease, Cfg.TargetChannel, "0")66 switchSystemImageConf(c, Cfg.TargetRelease, Cfg.TargetChannel, "0")
67 // Always use the installed snappy because we are updating from an old67 // Always use the installed snappy because we are updating from an old
68 // image, so we should not use the snappy from the branch.68 // image, so we should not use the snappy from the branch.
69 output := ExecCommand(c, "sudo", "/usr/bin/snappy", "update")69 output := cli.ExecCommand(c, "sudo", "/usr/bin/snappy", "update")
70 if output != "" {70 if output != "" {
71 RebootWithMark(c, "setupsuite-update")71 RebootWithMark(c, "setupsuite-update")
72 }72 }
@@ -77,7 +77,7 @@
77 Cfg.Update = false77 Cfg.Update = false
78 Cfg.Write()78 Cfg.Write()
79 if Cfg.Rollback {79 if Cfg.Rollback {
80 ExecCommand(c, "sudo", "snappy", "rollback", "ubuntu-core")80 cli.ExecCommand(c, "sudo", "snappy", "rollback", "ubuntu-core")
81 RebootWithMark(c, "setupsuite-rollback")81 RebootWithMark(c, "setupsuite-rollback")
82 }82 }
83 } else if CheckRebootMark("setupsuite-rollback") {83 } else if CheckRebootMark("setupsuite-rollback") {
@@ -131,7 +131,7 @@
131 defer MakeReadonly(c, target)131 defer MakeReadonly(c, target)
132 original := filepath.Join(target, channelCfgFile)132 original := filepath.Join(target, channelCfgFile)
133 c.Logf("Restoring %s...", original)133 c.Logf("Restoring %s...", original)
134 ExecCommand(c, "sudo", "mv", backup, original)134 cli.ExecCommand(c, "sudo", "mv", backup, original)
135 }135 }
136 }136 }
137 }137 }
@@ -169,12 +169,12 @@
169 }169 }
170 for value, regex := range replaceRegex {170 for value, regex := range replaceRegex {
171 if value != "" {171 if value != "" {
172 ExecCommand(c,172 cli.ExecCommand(c,
173 "sudo", "sed", "-i", fmt.Sprintf(regex, value), file)173 "sudo", "sed", "-i", fmt.Sprintf(regex, value), file)
174 }174 }
175 }175 }
176 // Leave the new file in the test log.176 // Leave the new file in the test log.
177 ExecCommand(c, "cat", file)177 cli.ExecCommand(c, "cat", file)
178}178}
179179
180func channelCfgBackupFile() string {180func channelCfgBackupFile() string {
@@ -185,35 +185,9 @@
185 return filepath.Join(os.Getenv("ADT_ARTIFACTS"), "channel.ini.other")185 return filepath.Join(os.Getenv("ADT_ARTIFACTS"), "channel.ini.other")
186}186}
187187
188// ExecCommand executes a shell command and returns a string with the output
189// of the command. In case of error, it will fail the test.
190func ExecCommand(c *check.C, cmds ...string) string {
191 fmt.Println(strings.Join(cmds, " "))
192 cmd := exec.Command(cmds[0], cmds[1:len(cmds)]...)
193 output, err := cmd.CombinedOutput()
194 stringOutput := string(output)
195 fmt.Print(stringOutput)
196 c.Assert(err, check.IsNil, check.Commentf("Error: %v", stringOutput))
197 return stringOutput
198}
199
200// ExecCommandToFile executes a shell command and saves the output of the
201// command to a file. In case of error, it will fail the test.
202func ExecCommandToFile(c *check.C, filename string, cmds ...string) {
203 cmd := exec.Command(cmds[0], cmds[1:len(cmds)]...)
204 outfile, err := os.Create(filename)
205 c.Assert(err, check.IsNil, check.Commentf("Error creating output file %s", filename))
206
207 defer outfile.Close()
208 cmd.Stdout = outfile
209
210 err = cmd.Run()
211 c.Assert(err, check.IsNil, check.Commentf("Error executing command '%v': %v", cmds, err))
212}
213
214// GetCurrentVersion returns the version of the installed and active package.188// GetCurrentVersion returns the version of the installed and active package.
215func GetCurrentVersion(c *check.C, packageName string) string {189func GetCurrentVersion(c *check.C, packageName string) string {
216 output := ExecCommand(c, "snappy", "list")190 output := cli.ExecCommand(c, "snappy", "list")
217 pattern := "(?mU)^" + packageName + " +(.*)$"191 pattern := "(?mU)^" + packageName + " +(.*)$"
218 re := regexp.MustCompile(pattern)192 re := regexp.MustCompile(pattern)
219 match := re.FindStringSubmatch(string(output))193 match := re.FindStringSubmatch(string(output))
@@ -237,7 +211,7 @@
237func CallFakeUpdate(c *check.C) string {211func CallFakeUpdate(c *check.C) string {
238 c.Log("Preparing fake and calling update.")212 c.Log("Preparing fake and calling update.")
239 fakeAvailableUpdate(c)213 fakeAvailableUpdate(c)
240 return ExecCommand(c, "sudo", "snappy", "update")214 return cli.ExecCommand(c, "sudo", "snappy", "update")
241}215}
242216
243func fakeAvailableUpdate(c *check.C) {217func fakeAvailableUpdate(c *check.C) {
@@ -257,7 +231,7 @@
257 MakeWritable(c, target)231 MakeWritable(c, target)
258 defer MakeReadonly(c, target)232 defer MakeReadonly(c, target)
259 // Back up the file. It will be restored during the test tear down.233 // Back up the file. It will be restored during the test tear down.
260 ExecCommand(c, "cp", file, backup)234 cli.ExecCommand(c, "cp", file, backup)
261 replaceSystemImageValues(c, file, "", "", strconv.Itoa(newVersion))235 replaceSystemImageValues(c, file, "", "", strconv.Itoa(newVersion))
262 }236 }
263 }237 }
@@ -265,12 +239,12 @@
265239
266// MakeWritable remounts a path with read and write permissions.240// MakeWritable remounts a path with read and write permissions.
267func MakeWritable(c *check.C, path string) {241func MakeWritable(c *check.C, path string) {
268 ExecCommand(c, "sudo", "mount", "-o", "remount,rw", path)242 cli.ExecCommand(c, "sudo", "mount", "-o", "remount,rw", path)
269}243}
270244
271// MakeReadonly remounts a path with only read permissions.245// MakeReadonly remounts a path with only read permissions.
272func MakeReadonly(c *check.C, path string) {246func MakeReadonly(c *check.C, path string) {
273 ExecCommand(c, "sudo", "mount", "-o", "remount,ro", path)247 cli.ExecCommand(c, "sudo", "mount", "-o", "remount,ro", path)
274}248}
275249
276// Reboot requests a reboot using the test name as the mark.250// Reboot requests a reboot using the test name as the mark.
@@ -346,10 +320,10 @@
346320
347// InstallSnap executes the required command to install the specified snap321// InstallSnap executes the required command to install the specified snap
348func InstallSnap(c *check.C, packageName string) string {322func InstallSnap(c *check.C, packageName string) string {
349 return ExecCommand(c, "sudo", "snappy", "install", packageName, "--allow-unauthenticated")323 return cli.ExecCommand(c, "sudo", "snappy", "install", packageName, "--allow-unauthenticated")
350}324}
351325
352// RemoveSnap executes the required command to remove the specified snap326// RemoveSnap executes the required command to remove the specified snap
353func RemoveSnap(c *check.C, packageName string) string {327func RemoveSnap(c *check.C, packageName string) string {
354 return ExecCommand(c, "sudo", "snappy", "remove", packageName)328 return cli.ExecCommand(c, "sudo", "snappy", "remove", packageName)
355}329}
356330
=== modified file '_integration-tests/testutils/common/info.go'
--- _integration-tests/testutils/common/info.go 2015-09-24 21:06:01 +0000
+++ _integration-tests/testutils/common/info.go 2015-10-02 10:23:57 +0000
@@ -24,10 +24,11 @@
24 "strings"24 "strings"
2525
26 "gopkg.in/check.v1"26 "gopkg.in/check.v1"
27 "launchpad.net/snappy/_integration-tests/testutils/cli"
27)28)
2829
29// dependency aliasing30// dependency aliasing
30var execCommand = ExecCommand31var execCommand = cli.ExecCommand
3132
32// Release returns the release of the current snappy image33// Release returns the release of the current snappy image
33func Release(c *check.C) string {34func Release(c *check.C) string {
3435
=== modified file '_integration-tests/testutils/runner/runner.go'
--- _integration-tests/testutils/runner/runner.go 2015-08-12 15:50:33 +0000
+++ _integration-tests/testutils/runner/runner.go 2015-10-02 10:23:57 +0000
@@ -25,7 +25,7 @@
25 "strings"25 "strings"
26 "testing"26 "testing"
2727
28 check "gopkg.in/check.v1"28 "gopkg.in/check.v1"
29)29)
3030
31var (31var (
3232
=== modified file '_integration-tests/testutils/wait/wait.go'
--- _integration-tests/testutils/wait/wait.go 2015-09-28 10:54:40 +0000
+++ _integration-tests/testutils/wait/wait.go 2015-10-02 10:23:57 +0000
@@ -24,14 +24,14 @@
24 "regexp"24 "regexp"
25 "time"25 "time"
2626
27 check "gopkg.in/check.v1"27 "gopkg.in/check.v1"
2828
29 "launchpad.net/snappy/_integration-tests/testutils/common"29 "launchpad.net/snappy/_integration-tests/testutils/cli"
30)30)
3131
32var (32var (
33 // dependency aliasing33 // dependency aliasing
34 execCommand = common.ExecCommand34 execCommand = cli.ExecCommand
35 // ForCommand dep alias35 // ForCommand dep alias
36 ForCommand = forCommand36 ForCommand = forCommand
37 // ForFunction dep alias37 // ForFunction dep alias

Subscribers

People subscribed via source and target branches