-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial version of cli integration tests
Docker-DCO-1.1-Signed-off-by: Cristian Staretu <[email protected]> (github: unclejack)
- Loading branch information
Showing
22 changed files
with
1,117 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/bin/bash | ||
|
||
DEST=$1 | ||
DOCKERBIN=$DEST/../binary/docker-$VERSION | ||
DYNDOCKERBIN=$DEST/../dynbinary/docker-$VERSION | ||
DOCKERINITBIN=$DEST/../dynbinary/dockerinit-$VERSION | ||
|
||
set -e | ||
|
||
bundle_test_integration_cli() { | ||
go_test_dir ./integration-cli | ||
} | ||
|
||
if [ -x "/usr/bin/docker" ]; then | ||
echo "docker found at /usr/bin/docker" | ||
elif [ -x "$DOCKERBIN" ]; then | ||
ln -s $DOCKERBIN /usr/bin/docker | ||
elif [ -x "$DYNDOCKERBIN" ]; then | ||
ln -s $DYNDOCKERBIN /usr/bin/docker | ||
ln -s $DOCKERINITBIN /usr/bin/dockerinit | ||
else | ||
echo >&2 'error: binary or dynbinary must be run before test-integration-cli' | ||
false | ||
fi | ||
|
||
|
||
docker -d -D -p $DEST/docker.pid &> $DEST/docker.log & | ||
sleep 2 | ||
docker info | ||
DOCKERD_PID=`cat $DEST/docker.pid` | ||
|
||
bundle_test_integration_cli 2>&1 \ | ||
| tee $DEST/test.log | ||
|
||
kill $DOCKERD_PID | ||
wait $DOCKERD_PID | ||
|
60 changes: 60 additions & 0 deletions
60
integration-cli/build_tests/TestBuildSixtySteps/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
FROM busybox | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" | ||
RUN echo "foo" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
"path/filepath" | ||
"testing" | ||
) | ||
|
||
func TestBuildSixtySteps(t *testing.T) { | ||
buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestBuildSixtySteps") | ||
buildCmd := exec.Command(dockerBinary, "build", "-t", "foobuildsixtysteps", ".") | ||
buildCmd.Dir = buildDirectory | ||
out, exitCode, err := runCommandWithOutput(buildCmd) | ||
errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out, err)) | ||
|
||
if err != nil || exitCode != 0 { | ||
t.Fatal("failed to build the image") | ||
} | ||
|
||
go deleteImages("foobuildsixtysteps") | ||
|
||
logDone("build - build an image with sixty build steps") | ||
} | ||
|
||
// TODO: TestCaching | ||
|
||
// TODO: TestADDCacheInvalidation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
"testing" | ||
) | ||
|
||
func TestCommitAfterContainerIsDone(t *testing.T) { | ||
runCmd := exec.Command(dockerBinary, "run", "-i", "-a", "stdin", "busybox", "echo", "foo") | ||
out, _, _, err := runCommandWithStdoutStderr(runCmd) | ||
errorOut(err, t, fmt.Sprintf("failed to run container: %v %v", out, err)) | ||
|
||
cleanedContainerID := stripTrailingCharacters(out) | ||
|
||
waitCmd := exec.Command(dockerBinary, "wait", cleanedContainerID) | ||
_, _, err = runCommandWithOutput(waitCmd) | ||
errorOut(err, t, fmt.Sprintf("error thrown while waiting for container: %s", out)) | ||
|
||
commitCmd := exec.Command(dockerBinary, "commit", cleanedContainerID) | ||
out, _, err = runCommandWithOutput(commitCmd) | ||
errorOut(err, t, fmt.Sprintf("failed to commit container to image: %v %v", out, err)) | ||
|
||
cleanedImageID := stripTrailingCharacters(out) | ||
|
||
inspectCmd := exec.Command(dockerBinary, "inspect", cleanedImageID) | ||
out, _, err = runCommandWithOutput(inspectCmd) | ||
errorOut(err, t, fmt.Sprintf("failed to inspect image: %v %v", out, err)) | ||
|
||
go deleteContainer(cleanedContainerID) | ||
go deleteImages(cleanedImageID) | ||
|
||
logDone("commit - echo foo and commit the image") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
// ensure that an added file shows up in docker diff | ||
func TestDiffFilenameShownInOutput(t *testing.T) { | ||
containerCmd := `echo foo > /root/bar` | ||
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", containerCmd) | ||
cid, _, err := runCommandWithOutput(runCmd) | ||
errorOut(err, t, fmt.Sprintf("failed to start the container: %v", err)) | ||
|
||
cleanCID := stripTrailingCharacters(cid) | ||
|
||
diffCmd := exec.Command(dockerBinary, "diff", cleanCID) | ||
out, _, err := runCommandWithOutput(diffCmd) | ||
errorOut(err, t, fmt.Sprintf("failed to run diff: %v %v", out, err)) | ||
|
||
found := false | ||
for _, line := range strings.Split(out, "\n") { | ||
if strings.Contains("A /root/bar", line) { | ||
found = true | ||
break | ||
} | ||
} | ||
if !found { | ||
t.Errorf("couldn't find the new file in docker diff's output: %v", out) | ||
} | ||
go deleteContainer(cleanCID) | ||
|
||
logDone("diff - check if created file shows up") | ||
} | ||
|
||
// test to ensure GH #3840 doesn't occur any more | ||
func TestDiffEnsureDockerinitFilesAreIgnored(t *testing.T) { | ||
// this is a list of files which shouldn't show up in `docker diff` | ||
dockerinitFiles := []string{"/etc/resolv.conf", "/etc/hostname", "/etc/hosts", "/.dockerinit", "/.dockerenv"} | ||
|
||
// we might not run into this problem from the first run, so start a few containers | ||
for i := 0; i < 20; i++ { | ||
containerCmd := `echo foo > /root/bar` | ||
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", containerCmd) | ||
cid, _, err := runCommandWithOutput(runCmd) | ||
errorOut(err, t, fmt.Sprintf("%s", err)) | ||
|
||
cleanCID := stripTrailingCharacters(cid) | ||
|
||
diffCmd := exec.Command(dockerBinary, "diff", cleanCID) | ||
out, _, err := runCommandWithOutput(diffCmd) | ||
errorOut(err, t, fmt.Sprintf("failed to run diff: %v %v", out, err)) | ||
|
||
go deleteContainer(cleanCID) | ||
|
||
for _, filename := range dockerinitFiles { | ||
if strings.Contains(out, filename) { | ||
t.Errorf("found file which should've been ignored %v in diff output", filename) | ||
} | ||
} | ||
} | ||
|
||
logDone("diff - check if ignored files show up in diff") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"testing" | ||
) | ||
|
||
// export an image and try to import it into a new one | ||
func TestExportContainerAndImportImage(t *testing.T) { | ||
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true") | ||
out, _, err := runCommandWithOutput(runCmd) | ||
if err != nil { | ||
t.Fatal("failed to create a container", out, err) | ||
} | ||
|
||
cleanedContainerID := stripTrailingCharacters(out) | ||
|
||
inspectCmd := exec.Command(dockerBinary, "inspect", cleanedContainerID) | ||
out, _, err = runCommandWithOutput(inspectCmd) | ||
if err != nil { | ||
t.Fatalf("output should've been a container id: %s %s ", cleanedContainerID, err) | ||
} | ||
|
||
exportCmdTemplate := `%v export %v > /tmp/testexp.tar` | ||
exportCmdFinal := fmt.Sprintf(exportCmdTemplate, dockerBinary, cleanedContainerID) | ||
exportCmd := exec.Command("bash", "-c", exportCmdFinal) | ||
out, _, err = runCommandWithOutput(exportCmd) | ||
errorOut(err, t, fmt.Sprintf("failed to export container: %v %v", out, err)) | ||
|
||
importCmdFinal := `cat /tmp/testexp.tar | docker import - testexp` | ||
importCmd := exec.Command("bash", "-c", importCmdFinal) | ||
out, _, err = runCommandWithOutput(importCmd) | ||
errorOut(err, t, fmt.Sprintf("failed to import image: %v %v", out, err)) | ||
|
||
cleanedImageID := stripTrailingCharacters(out) | ||
|
||
inspectCmd = exec.Command(dockerBinary, "inspect", cleanedImageID) | ||
out, _, err = runCommandWithOutput(inspectCmd) | ||
errorOut(err, t, fmt.Sprintf("output should've been an image id: %v %v", out, err)) | ||
|
||
go deleteImages("testexp") | ||
go deleteContainer(cleanedContainerID) | ||
|
||
os.Remove("/tmp/testexp.tar") | ||
|
||
logDone("export - export a container") | ||
logDone("import - import an image") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestImagesEnsureImageIsListed(t *testing.T) { | ||
imagesCmd := exec.Command(dockerBinary, "images") | ||
out, _, err := runCommandWithOutput(imagesCmd) | ||
errorOut(err, t, fmt.Sprintf("listing images failed with errors: %v", err)) | ||
|
||
if !strings.Contains(out, "busybox") { | ||
t.Fatal("images should've listed busybox") | ||
} | ||
|
||
logDone("images - busybox should be listed") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
// ensure docker info succeeds | ||
func TestInfoEnsureSucceeds(t *testing.T) { | ||
versionCmd := exec.Command(dockerBinary, "info") | ||
out, exitCode, err := runCommandWithOutput(versionCmd) | ||
errorOut(err, t, fmt.Sprintf("encountered error while running docker info: %v", err)) | ||
|
||
if err != nil || exitCode != 0 { | ||
t.Fatal("failed to execute docker info") | ||
} | ||
|
||
stringsToCheck := []string{"Containers:", "Execution Driver:", "Kernel Version:"} | ||
|
||
for _, linePrefix := range stringsToCheck { | ||
if !strings.Contains(out, linePrefix) { | ||
t.Errorf("couldn't find string %v in output", linePrefix) | ||
} | ||
} | ||
|
||
logDone("info - verify that it works") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestKillContainer(t *testing.T) { | ||
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", "sleep 10") | ||
out, _, err := runCommandWithOutput(runCmd) | ||
errorOut(err, t, fmt.Sprintf("run failed with errors: %v", err)) | ||
|
||
cleanedContainerID := stripTrailingCharacters(out) | ||
|
||
inspectCmd := exec.Command(dockerBinary, "inspect", cleanedContainerID) | ||
inspectOut, _, err := runCommandWithOutput(inspectCmd) | ||
errorOut(err, t, fmt.Sprintf("out should've been a container id: %v %v", inspectOut, err)) | ||
|
||
killCmd := exec.Command(dockerBinary, "kill", cleanedContainerID) | ||
out, _, err = runCommandWithOutput(killCmd) | ||
errorOut(err, t, fmt.Sprintf("failed to kill container: %v %v", out, err)) | ||
|
||
listRunningContainersCmd := exec.Command(dockerBinary, "ps", "-q") | ||
out, _, err = runCommandWithOutput(listRunningContainersCmd) | ||
errorOut(err, t, fmt.Sprintf("failed to list running containers: %v", err)) | ||
|
||
if strings.Contains(out, cleanedContainerID) { | ||
t.Fatal("killed container is still running") | ||
} | ||
|
||
go deleteContainer(cleanedContainerID) | ||
|
||
logDone("kill - kill container running sleep 10") | ||
} |
Oops, something went wrong.