Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 43d1c20

Browse files
committed
Move links exec test & exec dir test.
Docker-DCO-1.1-Signed-off-by: Jessica Frazelle <[email protected]> (github: jfrazelle)
1 parent 547c959 commit 43d1c20

3 files changed

Lines changed: 133 additions & 132 deletions

File tree

integration-cli/docker_cli_exec_test.go

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"os"
99
"os/exec"
10+
"path/filepath"
1011
"reflect"
1112
"sort"
1213
"strings"
@@ -490,3 +491,135 @@ func TestInspectExecID(t *testing.T) {
490491

491492
logDone("inspect - inspect a container with ExecIDs")
492493
}
494+
495+
func TestLinksPingLinkedContainersOnRename(t *testing.T) {
496+
var out string
497+
out, _, _ = dockerCmd(t, "run", "-d", "--name", "container1", "busybox", "sleep", "10")
498+
idA := stripTrailingCharacters(out)
499+
if idA == "" {
500+
t.Fatal(out, "id should not be nil")
501+
}
502+
out, _, _ = dockerCmd(t, "run", "-d", "--link", "container1:alias1", "--name", "container2", "busybox", "sleep", "10")
503+
idB := stripTrailingCharacters(out)
504+
if idB == "" {
505+
t.Fatal(out, "id should not be nil")
506+
}
507+
508+
execCmd := exec.Command(dockerBinary, "exec", "container2", "ping", "-c", "1", "alias1", "-W", "1")
509+
out, _, err := runCommandWithOutput(execCmd)
510+
if err != nil {
511+
t.Fatal(out, err)
512+
}
513+
514+
dockerCmd(t, "rename", "container1", "container_new")
515+
516+
execCmd = exec.Command(dockerBinary, "exec", "container2", "ping", "-c", "1", "alias1", "-W", "1")
517+
out, _, err = runCommandWithOutput(execCmd)
518+
if err != nil {
519+
t.Fatal(out, err)
520+
}
521+
522+
deleteAllContainers()
523+
524+
logDone("links - ping linked container upon rename")
525+
}
526+
527+
func TestRunExecDir(t *testing.T) {
528+
cmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
529+
out, _, err := runCommandWithOutput(cmd)
530+
if err != nil {
531+
t.Fatal(err, out)
532+
}
533+
id := strings.TrimSpace(out)
534+
execDir := filepath.Join(execDriverPath, id)
535+
stateFile := filepath.Join(execDir, "state.json")
536+
contFile := filepath.Join(execDir, "container.json")
537+
538+
{
539+
fi, err := os.Stat(execDir)
540+
if err != nil {
541+
t.Fatal(err)
542+
}
543+
if !fi.IsDir() {
544+
t.Fatalf("%q must be a directory", execDir)
545+
}
546+
fi, err = os.Stat(stateFile)
547+
if err != nil {
548+
t.Fatal(err)
549+
}
550+
fi, err = os.Stat(contFile)
551+
if err != nil {
552+
t.Fatal(err)
553+
}
554+
}
555+
556+
stopCmd := exec.Command(dockerBinary, "stop", id)
557+
out, _, err = runCommandWithOutput(stopCmd)
558+
if err != nil {
559+
t.Fatal(err, out)
560+
}
561+
{
562+
fi, err := os.Stat(execDir)
563+
if err != nil {
564+
t.Fatal(err)
565+
}
566+
if !fi.IsDir() {
567+
t.Fatalf("%q must be a directory", execDir)
568+
}
569+
fi, err = os.Stat(stateFile)
570+
if err == nil {
571+
t.Fatalf("Statefile %q is exists for stopped container!", stateFile)
572+
}
573+
if !os.IsNotExist(err) {
574+
t.Fatalf("Error should be about non-existing, got %s", err)
575+
}
576+
fi, err = os.Stat(contFile)
577+
if err == nil {
578+
t.Fatalf("Container file %q is exists for stopped container!", contFile)
579+
}
580+
if !os.IsNotExist(err) {
581+
t.Fatalf("Error should be about non-existing, got %s", err)
582+
}
583+
}
584+
startCmd := exec.Command(dockerBinary, "start", id)
585+
out, _, err = runCommandWithOutput(startCmd)
586+
if err != nil {
587+
t.Fatal(err, out)
588+
}
589+
{
590+
fi, err := os.Stat(execDir)
591+
if err != nil {
592+
t.Fatal(err)
593+
}
594+
if !fi.IsDir() {
595+
t.Fatalf("%q must be a directory", execDir)
596+
}
597+
fi, err = os.Stat(stateFile)
598+
if err != nil {
599+
t.Fatal(err)
600+
}
601+
fi, err = os.Stat(contFile)
602+
if err != nil {
603+
t.Fatal(err)
604+
}
605+
}
606+
rmCmd := exec.Command(dockerBinary, "rm", "-f", id)
607+
out, _, err = runCommandWithOutput(rmCmd)
608+
if err != nil {
609+
t.Fatal(err, out)
610+
}
611+
{
612+
_, err := os.Stat(execDir)
613+
if err == nil {
614+
t.Fatal(err)
615+
}
616+
if err == nil {
617+
t.Fatalf("Exec directory %q is exists for removed container!", execDir)
618+
}
619+
if !os.IsNotExist(err) {
620+
t.Fatalf("Error should be about non-existing, got %s", err)
621+
}
622+
}
623+
624+
logDone("run - check execdriver dir behavior")
625+
}

integration-cli/docker_cli_links_test.go

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -92,38 +92,6 @@ func TestLinksPingLinkedContainersAfterRename(t *testing.T) {
9292
logDone("links - ping linked container after rename")
9393
}
9494

95-
func TestLinksPingLinkedContainersOnRename(t *testing.T) {
96-
var out string
97-
out, _, _ = dockerCmd(t, "run", "-d", "--name", "container1", "busybox", "sleep", "10")
98-
idA := stripTrailingCharacters(out)
99-
if idA == "" {
100-
t.Fatal(out, "id should not be nil")
101-
}
102-
out, _, _ = dockerCmd(t, "run", "-d", "--link", "container1:alias1", "--name", "container2", "busybox", "sleep", "10")
103-
idB := stripTrailingCharacters(out)
104-
if idB == "" {
105-
t.Fatal(out, "id should not be nil")
106-
}
107-
108-
execCmd := exec.Command(dockerBinary, "exec", "container2", "ping", "-c", "1", "alias1", "-W", "1")
109-
out, _, err := runCommandWithOutput(execCmd)
110-
if err != nil {
111-
t.Fatal(out, err)
112-
}
113-
114-
dockerCmd(t, "rename", "container1", "container_new")
115-
116-
execCmd = exec.Command(dockerBinary, "exec", "container2", "ping", "-c", "1", "alias1", "-W", "1")
117-
out, _, err = runCommandWithOutput(execCmd)
118-
if err != nil {
119-
t.Fatal(out, err)
120-
}
121-
122-
deleteAllContainers()
123-
124-
logDone("links - ping linked container upon rename")
125-
}
126-
12795
func TestLinksIpTablesRulesWhenLinkAndUnlink(t *testing.T) {
12896
dockerCmd(t, "run", "-d", "--name", "child", "--publish", "8080:80", "busybox", "sleep", "10")
12997
dockerCmd(t, "run", "-d", "--name", "parent", "--link", "child:http", "busybox", "sleep", "10")

integration-cli/docker_cli_run_test.go

Lines changed: 0 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -2404,106 +2404,6 @@ func TestRunMountOrdering(t *testing.T) {
24042404
logDone("run - volumes are mounted in the correct order")
24052405
}
24062406

2407-
func TestRunExecDir(t *testing.T) {
2408-
cmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")
2409-
out, _, err := runCommandWithOutput(cmd)
2410-
if err != nil {
2411-
t.Fatal(err, out)
2412-
}
2413-
id := strings.TrimSpace(out)
2414-
execDir := filepath.Join(execDriverPath, id)
2415-
stateFile := filepath.Join(execDir, "state.json")
2416-
contFile := filepath.Join(execDir, "container.json")
2417-
2418-
{
2419-
fi, err := os.Stat(execDir)
2420-
if err != nil {
2421-
t.Fatal(err)
2422-
}
2423-
if !fi.IsDir() {
2424-
t.Fatalf("%q must be a directory", execDir)
2425-
}
2426-
fi, err = os.Stat(stateFile)
2427-
if err != nil {
2428-
t.Fatal(err)
2429-
}
2430-
fi, err = os.Stat(contFile)
2431-
if err != nil {
2432-
t.Fatal(err)
2433-
}
2434-
}
2435-
2436-
stopCmd := exec.Command(dockerBinary, "stop", id)
2437-
out, _, err = runCommandWithOutput(stopCmd)
2438-
if err != nil {
2439-
t.Fatal(err, out)
2440-
}
2441-
{
2442-
fi, err := os.Stat(execDir)
2443-
if err != nil {
2444-
t.Fatal(err)
2445-
}
2446-
if !fi.IsDir() {
2447-
t.Fatalf("%q must be a directory", execDir)
2448-
}
2449-
fi, err = os.Stat(stateFile)
2450-
if err == nil {
2451-
t.Fatalf("Statefile %q is exists for stopped container!", stateFile)
2452-
}
2453-
if !os.IsNotExist(err) {
2454-
t.Fatalf("Error should be about non-existing, got %s", err)
2455-
}
2456-
fi, err = os.Stat(contFile)
2457-
if err == nil {
2458-
t.Fatalf("Container file %q is exists for stopped container!", contFile)
2459-
}
2460-
if !os.IsNotExist(err) {
2461-
t.Fatalf("Error should be about non-existing, got %s", err)
2462-
}
2463-
}
2464-
startCmd := exec.Command(dockerBinary, "start", id)
2465-
out, _, err = runCommandWithOutput(startCmd)
2466-
if err != nil {
2467-
t.Fatal(err, out)
2468-
}
2469-
{
2470-
fi, err := os.Stat(execDir)
2471-
if err != nil {
2472-
t.Fatal(err)
2473-
}
2474-
if !fi.IsDir() {
2475-
t.Fatalf("%q must be a directory", execDir)
2476-
}
2477-
fi, err = os.Stat(stateFile)
2478-
if err != nil {
2479-
t.Fatal(err)
2480-
}
2481-
fi, err = os.Stat(contFile)
2482-
if err != nil {
2483-
t.Fatal(err)
2484-
}
2485-
}
2486-
rmCmd := exec.Command(dockerBinary, "rm", "-f", id)
2487-
out, _, err = runCommandWithOutput(rmCmd)
2488-
if err != nil {
2489-
t.Fatal(err, out)
2490-
}
2491-
{
2492-
_, err := os.Stat(execDir)
2493-
if err == nil {
2494-
t.Fatal(err)
2495-
}
2496-
if err == nil {
2497-
t.Fatalf("Exec directory %q is exists for removed container!", execDir)
2498-
}
2499-
if !os.IsNotExist(err) {
2500-
t.Fatalf("Error should be about non-existing, got %s", err)
2501-
}
2502-
}
2503-
2504-
logDone("run - check execdriver dir behavior")
2505-
}
2506-
25072407
// Regression test for https://github.com/docker/docker/issues/8259
25082408
func TestRunReuseBindVolumeThatIsSymlink(t *testing.T) {
25092409
tmpDir, err := ioutil.TempDir(os.TempDir(), "testlink")

0 commit comments

Comments
 (0)