소스 검색

docker save: more integration tests

Docker-DCO-1.1-Signed-off-by: Vincent Batts <vbatts@redhat.com> (github: vbatts)
Vincent Batts 11 년 전
부모
커밋
600f65b247
1개의 변경된 파일57개의 추가작업 그리고 0개의 파일을 삭제
  1. 57 0
      integration-cli/docker_cli_save_load_test.go

+ 57 - 0
integration-cli/docker_cli_save_load_test.go

@@ -59,6 +59,63 @@ func TestSaveAndLoadRepoStdout(t *testing.T) {
 	logDone("load - load a repo using stdout")
 }
 
+func TestSaveSingleTag(t *testing.T) {
+	repoName := "foobar-save-single-tag-test"
+
+	tagCmdFinal := fmt.Sprintf("%v tag busybox:latest %v:latest", dockerBinary, repoName)
+	tagCmd := exec.Command("bash", "-c", tagCmdFinal)
+	out, _, err := runCommandWithOutput(tagCmd)
+	errorOut(err, t, fmt.Sprintf("failed to tag repo: %v %v", out, err))
+
+	idCmdFinal := fmt.Sprintf("%v images -q --no-trunc %v", dockerBinary, repoName)
+	idCmd := exec.Command("bash", "-c", idCmdFinal)
+	out, _, err = runCommandWithOutput(idCmd)
+	errorOut(err, t, fmt.Sprintf("failed to get repo ID: %v %v", out, err))
+
+	cleanedImageID := stripTrailingCharacters(out)
+
+	saveCmdFinal := fmt.Sprintf("%v save %v:latest | tar t | grep -E '(^repositories$|%v)'", dockerBinary, repoName, cleanedImageID)
+	saveCmd := exec.Command("bash", "-c", saveCmdFinal)
+	out, _, err = runCommandWithOutput(saveCmd)
+	errorOut(err, t, fmt.Sprintf("failed to save repo with image ID and 'repositories' file: %v %v", out, err))
+
+	deleteImages(repoName)
+
+	logDone("save - save a specific image:tag")
+}
+
+func TestSaveImageId(t *testing.T) {
+	repoName := "foobar-save-image-id-test"
+
+	tagCmdFinal := fmt.Sprintf("%v tag scratch:latest %v:latest", dockerBinary, repoName)
+	tagCmd := exec.Command("bash", "-c", tagCmdFinal)
+	out, _, err := runCommandWithOutput(tagCmd)
+	errorOut(err, t, fmt.Sprintf("failed to tag repo: %v %v", out, err))
+
+	idLongCmdFinal := fmt.Sprintf("%v images -q --no-trunc %v", dockerBinary, repoName)
+	idLongCmd := exec.Command("bash", "-c", idLongCmdFinal)
+	out, _, err = runCommandWithOutput(idLongCmd)
+	errorOut(err, t, fmt.Sprintf("failed to get repo ID: %v %v", out, err))
+
+	cleanedLongImageID := stripTrailingCharacters(out)
+
+	idShortCmdFinal := fmt.Sprintf("%v images -q %v", dockerBinary, repoName)
+	idShortCmd := exec.Command("bash", "-c", idShortCmdFinal)
+	out, _, err = runCommandWithOutput(idShortCmd)
+	errorOut(err, t, fmt.Sprintf("failed to get repo short ID: %v %v", out, err))
+
+	cleanedShortImageID := stripTrailingCharacters(out)
+
+	saveCmdFinal := fmt.Sprintf("%v save %v | tar t | grep %v", dockerBinary, cleanedShortImageID, cleanedLongImageID)
+	saveCmd := exec.Command("bash", "-c", saveCmdFinal)
+	out, _, err = runCommandWithOutput(saveCmd)
+	errorOut(err, t, fmt.Sprintf("failed to save repo with image ID: %v %v", out, err))
+
+	deleteImages(repoName)
+
+	logDone("save - save a image by ID")
+}
+
 // save a repo and try to load it using flags
 func TestSaveAndLoadRepoFlags(t *testing.T) {
 	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")