summaryrefslogtreecommitdiffhomepage
path: root/runsc/container/container_test.go
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/container/container_test.go
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/container/container_test.go')
-rw-r--r--runsc/container/container_test.go59
1 files changed, 58 insertions, 1 deletions
diff --git a/runsc/container/container_test.go b/runsc/container/container_test.go
index da59c0331..43cd177ce 100644
--- a/runsc/container/container_test.go
+++ b/runsc/container/container_test.go
@@ -634,7 +634,7 @@ func TestRunNonRoot(t *testing.T) {
}
}
-// TestMountNewDir check that runsc will create destination directory if it
+// TestMountNewDir checks that runsc will create destination directory if it
// doesn't exit.
func TestMountNewDir(t *testing.T) {
srcDir := path.Join(os.TempDir(), "src", "newdir", "anotherdir")
@@ -660,3 +660,60 @@ func TestMountNewDir(t *testing.T) {
t.Fatalf("error running sadbox: %v", err)
}
}
+
+// TestAbbreviatedIDs checks that runsc supports using abbreviated container
+// IDs in place of full IDs.
+func TestAbbreviatedIDs(t *testing.T) {
+ cids := []string{
+ "foo-" + testutil.UniqueContainerID(),
+ "bar-" + testutil.UniqueContainerID(),
+ "baz-" + testutil.UniqueContainerID(),
+ }
+
+ rootDir, err := testutil.SetupRootDir()
+ if err != nil {
+ t.Fatalf("error creating root dir: %v", err)
+ }
+ for _, cid := range cids {
+ spec := testutil.NewSpecWithArgs("sleep", "100")
+ bundleDir, conf, err := testutil.SetupContainerInRoot(rootDir, spec)
+ if err != nil {
+ t.Fatalf("error setting up container: %v", err)
+ }
+ defer os.RemoveAll(rootDir)
+ defer os.RemoveAll(bundleDir)
+
+ // Create and start the container.
+ cont, err := container.Create(cid, spec, conf, bundleDir, "", "")
+ if err != nil {
+ t.Fatalf("error creating container: %v", err)
+ }
+ defer cont.Destroy()
+ }
+
+ // These should all be unambigious.
+ unambiguous := map[string]string{
+ "f": cids[0],
+ cids[0]: cids[0],
+ "bar": cids[1],
+ cids[1]: cids[1],
+ "baz": cids[2],
+ cids[2]: cids[2],
+ }
+ for shortid, longid := range unambiguous {
+ if _, err := container.Load(rootDir, shortid); err != nil {
+ t.Errorf("%q should resolve to %q: %v", shortid, longid, err)
+ }
+ }
+
+ // These should be ambiguous.
+ ambiguous := []string{
+ "b",
+ "ba",
+ }
+ for _, shortid := range ambiguous {
+ if s, err := container.Load(rootDir, shortid); err == nil {
+ t.Errorf("%q should be ambiguous, but resolved to %q", shortid, s.ID)
+ }
+ }
+}