summaryrefslogtreecommitdiffhomepage
path: root/runsc/test/testutil
diff options
context:
space:
mode:
authorFabricio Voznika <fvoznika@google.com>2018-09-28 17:47:22 -0700
committerShentubot <shentubot@google.com>2018-09-28 17:48:14 -0700
commitcfdd418fe23880cad88639596c1171cbe7ad6ffb (patch)
treef060daffa70d7b2733a6a59214850d1c4321a67c /runsc/test/testutil
parentf21dde566641ee9d80730cc04f16d75df8b05036 (diff)
Made a few changes to make testutil.Docker easier to use
PiperOrigin-RevId: 215023376 Change-Id: I139569bd15c013e5dd0f60d0c98a64eaa0ba9e8e
Diffstat (limited to 'runsc/test/testutil')
-rw-r--r--runsc/test/testutil/docker.go35
1 files changed, 29 insertions, 6 deletions
diff --git a/runsc/test/testutil/docker.go b/runsc/test/testutil/docker.go
index d0446df4e..7f5909987 100644
--- a/runsc/test/testutil/docker.go
+++ b/runsc/test/testutil/docker.go
@@ -65,14 +65,35 @@ func EnsureSupportedDockerVersion() {
}
}
+// MountMode describes if the mount should be ro or rw.
+type MountMode int
+
+const (
+ // ReadOnly is what the name says.
+ ReadOnly MountMode = iota
+ // ReadWrite is what the name says.
+ ReadWrite
+)
+
+// String returns the mount mode argument for this MountMode.
+func (m MountMode) String() string {
+ switch m {
+ case ReadOnly:
+ return "ro"
+ case ReadWrite:
+ return "rw"
+ }
+ panic(fmt.Sprintf("invalid mode: %d", m))
+}
+
// MountArg formats the volume argument to mount in the container.
-func MountArg(source, target string) string {
- return fmt.Sprintf("%s:%s", source, target)
+func MountArg(source, target string, mode MountMode) string {
+ return fmt.Sprintf("-v=%s:%s:%v", source, target, mode)
}
// LinkArg formats the link argument.
func LinkArg(source *Docker, target string) string {
- return fmt.Sprintf("%s:%s", source.Name, target)
+ return fmt.Sprintf("--link=%s:%s", source.Name, target)
}
// PrepareFiles creates temp directory to copy files there. The sandbox doesn't
@@ -155,11 +176,13 @@ func (d *Docker) Stop() error {
return nil
}
-// Run calls 'docker run' with the arguments provided.
-func (d *Docker) Run(args ...string) (string, error) {
+// Run calls 'docker run' with the arguments provided. The container starts
+// running in the backgroud and the call returns immediately.
+func (d *Docker) Run(args ...string) error {
a := []string{"run", "--runtime", d.Runtime, "--name", d.Name, "-d"}
a = append(a, args...)
- return do(a...)
+ _, err := do(a...)
+ return err
}
// Logs calls 'docker logs'.