Signed-off-by: Alexandr Morozov <lk4d4math@gmail.com>
| ... | ... |
@@ -1795,3 +1795,34 @@ func TestRunCidFileCleanupIfEmpty(t *testing.T) {
|
| 1795 | 1795 |
deleteAllContainers() |
| 1796 | 1796 |
logDone("run - cleanup empty cidfile on fail")
|
| 1797 | 1797 |
} |
| 1798 |
+ |
|
| 1799 |
+// #2098 - Docker cidFiles only contain short version of the containerId |
|
| 1800 |
+//sudo docker run --cidfile /tmp/docker_test.cid ubuntu echo "test" |
|
| 1801 |
+// TestRunCidFile tests that run --cidfile returns the longid |
|
| 1802 |
+func TestRunCidFileCheckIDLength(t *testing.T) {
|
|
| 1803 |
+ tmpDir, err := ioutil.TempDir("", "TestRunCidFile")
|
|
| 1804 |
+ if err != nil {
|
|
| 1805 |
+ t.Fatal(err) |
|
| 1806 |
+ } |
|
| 1807 |
+ tmpCidFile := path.Join(tmpDir, "cid") |
|
| 1808 |
+ defer os.RemoveAll(tmpDir) |
|
| 1809 |
+ cmd := exec.Command(dockerBinary, "run", "-d", "--cidfile", tmpCidFile, "busybox", "true") |
|
| 1810 |
+ out, _, err := runCommandWithOutput(cmd) |
|
| 1811 |
+ if err != nil {
|
|
| 1812 |
+ t.Fatal(err) |
|
| 1813 |
+ } |
|
| 1814 |
+ id := strings.TrimSpace(out) |
|
| 1815 |
+ buffer, err := ioutil.ReadFile(tmpCidFile) |
|
| 1816 |
+ if err != nil {
|
|
| 1817 |
+ t.Fatal(err) |
|
| 1818 |
+ } |
|
| 1819 |
+ cid := string(buffer) |
|
| 1820 |
+ if len(cid) != 64 {
|
|
| 1821 |
+ t.Fatalf("--cidfile should be a long id, not '%s'", id)
|
|
| 1822 |
+ } |
|
| 1823 |
+ if cid != id {
|
|
| 1824 |
+ t.Fatalf("cid must be equal to %s, got %s", id, cid)
|
|
| 1825 |
+ } |
|
| 1826 |
+ deleteAllContainers() |
|
| 1827 |
+ logDone("run - cidfile contains long id")
|
|
| 1828 |
+} |
| ... | ... |
@@ -5,8 +5,6 @@ import ( |
| 5 | 5 |
"fmt" |
| 6 | 6 |
"io" |
| 7 | 7 |
"io/ioutil" |
| 8 |
- "os" |
|
| 9 |
- "path" |
|
| 10 | 8 |
"strings" |
| 11 | 9 |
"testing" |
| 12 | 10 |
"time" |
| ... | ... |
@@ -531,55 +529,3 @@ func TestRunErrorBindNonExistingSource(t *testing.T) {
|
| 531 | 531 |
<-c |
| 532 | 532 |
}) |
| 533 | 533 |
} |
| 534 |
- |
|
| 535 |
-// #2098 - Docker cidFiles only contain short version of the containerId |
|
| 536 |
-//sudo docker run --cidfile /tmp/docker_test.cid ubuntu echo "test" |
|
| 537 |
-// TestRunCidFile tests that run --cidfile returns the longid |
|
| 538 |
-func TestRunCidFileCheckIDLength(t *testing.T) {
|
|
| 539 |
- stdout, stdoutPipe := io.Pipe() |
|
| 540 |
- |
|
| 541 |
- tmpDir, err := ioutil.TempDir("", "TestRunCidFile")
|
|
| 542 |
- if err != nil {
|
|
| 543 |
- t.Fatal(err) |
|
| 544 |
- } |
|
| 545 |
- tmpCidFile := path.Join(tmpDir, "cid") |
|
| 546 |
- |
|
| 547 |
- cli := client.NewDockerCli(nil, stdoutPipe, ioutil.Discard, testDaemonProto, testDaemonAddr, nil) |
|
| 548 |
- defer cleanup(globalEngine, t) |
|
| 549 |
- |
|
| 550 |
- c := make(chan struct{})
|
|
| 551 |
- go func() {
|
|
| 552 |
- defer close(c) |
|
| 553 |
- if err := cli.CmdRun("--cidfile", tmpCidFile, unitTestImageID, "ls"); err != nil {
|
|
| 554 |
- t.Fatal(err) |
|
| 555 |
- } |
|
| 556 |
- }() |
|
| 557 |
- |
|
| 558 |
- defer os.RemoveAll(tmpDir) |
|
| 559 |
- setTimeout(t, "Reading command output time out", 2*time.Second, func() {
|
|
| 560 |
- cmdOutput, err := bufio.NewReader(stdout).ReadString('\n')
|
|
| 561 |
- if err != nil {
|
|
| 562 |
- t.Fatal(err) |
|
| 563 |
- } |
|
| 564 |
- if len(cmdOutput) < 1 {
|
|
| 565 |
- t.Fatalf("'ls' should return something , not '%s'", cmdOutput)
|
|
| 566 |
- } |
|
| 567 |
- //read the tmpCidFile |
|
| 568 |
- buffer, err := ioutil.ReadFile(tmpCidFile) |
|
| 569 |
- if err != nil {
|
|
| 570 |
- t.Fatal(err) |
|
| 571 |
- } |
|
| 572 |
- id := string(buffer) |
|
| 573 |
- |
|
| 574 |
- if len(id) != len("2bf44ea18873287bd9ace8a4cb536a7cbe134bed67e805fdf2f58a57f69b320c") {
|
|
| 575 |
- t.Fatalf("--cidfile should be a long id, not '%s'", id)
|
|
| 576 |
- } |
|
| 577 |
- //test that its a valid cid? (though the container is gone..) |
|
| 578 |
- //remove the file and dir. |
|
| 579 |
- }) |
|
| 580 |
- |
|
| 581 |
- setTimeout(t, "CmdRun timed out", 5*time.Second, func() {
|
|
| 582 |
- <-c |
|
| 583 |
- }) |
|
| 584 |
- |
|
| 585 |
-} |