summaryrefslogtreecommitdiffhomepage
path: root/runsc/test/testutil
diff options
context:
space:
mode:
authorKevin Krakauer <krakauer@google.com>2018-06-06 16:12:58 -0700
committerShentubot <shentubot@google.com>2018-06-06 16:13:53 -0700
commit206e90d057211f2ac53174907b2ff04801f9a481 (patch)
tree8f4ff7b6847838a3d2c8e2a872bc0b599ac11de2 /runsc/test/testutil
parent79fef54eb1b9e941e2c910f90b65f3cfe94e18c4 (diff)
runsc: Support abbreviated container IDs.
Just a UI/usability addition. It's a lot easier to type "60" than "60185c721d7e10c00489f1fa210ee0d35c594873d6376b457fb1815e4fdbfc2c". PiperOrigin-RevId: 199547932 Change-Id: I19011b5061a88aba48a9ad7f8cf954a6782de854
Diffstat (limited to 'runsc/test/testutil')
-rw-r--r--runsc/test/testutil/testutil.go25
1 files changed, 20 insertions, 5 deletions
diff --git a/runsc/test/testutil/testutil.go b/runsc/test/testutil/testutil.go
index 87db0a170..1c8fd3ba2 100644
--- a/runsc/test/testutil/testutil.go
+++ b/runsc/test/testutil/testutil.go
@@ -84,21 +84,36 @@ func NewSpecWithArgs(args ...string) *specs.Spec {
return spec
}
+// SetupRootDir creates a root directory for containers.
+func SetupRootDir() (string, error) {
+ rootDir, err := ioutil.TempDir("", "containers")
+ if err != nil {
+ return "", fmt.Errorf("error creating root dir: %v", err)
+ }
+ return rootDir, nil
+}
+
// SetupContainer creates a bundle and root dir for the container, generates a
// test config, and writes the spec to config.json in the bundle dir.
func SetupContainer(spec *specs.Spec) (rootDir, bundleDir string, conf *boot.Config, err error) {
- rootDir, err = ioutil.TempDir("", "containers")
+ rootDir, err = SetupRootDir()
if err != nil {
- return "", "", nil, fmt.Errorf("error creating root dir: %v", err)
+ return "", "", nil, err
}
+ bundleDir, conf, err = SetupContainerInRoot(rootDir, spec)
+ return rootDir, bundleDir, conf, err
+}
+// SetupContainerInRoot creates a bundle for the container, generates a test
+// config, and writes the spec to config.json in the bundle dir.
+func SetupContainerInRoot(rootDir string, spec *specs.Spec) (bundleDir string, conf *boot.Config, err error) {
bundleDir, err = ioutil.TempDir("", "bundle")
if err != nil {
- return "", "", nil, fmt.Errorf("error creating bundle dir: %v", err)
+ return "", nil, fmt.Errorf("error creating bundle dir: %v", err)
}
if err = writeSpec(bundleDir, spec); err != nil {
- return "", "", nil, fmt.Errorf("error writing spec: %v", err)
+ return "", nil, fmt.Errorf("error writing spec: %v", err)
}
conf = &boot.Config{
@@ -110,7 +125,7 @@ func SetupContainer(spec *specs.Spec) (rootDir, bundleDir string, conf *boot.Con
TestModeNoFlags: true,
}
- return rootDir, bundleDir, conf, nil
+ return bundleDir, conf, nil
}
// writeSpec writes the spec to disk in the given directory.