소스 검색

Merge pull request #46536 from vvoland/integration-cli-saveload-repoflags

integration-cli/TestSaveAndLoadRepoFlags: Ignore LastTagTime difference
Paweł Gronowski 1 년 전
부모
커밋
3d62ab9585
1개의 변경된 파일30개의 추가작업 그리고 3개의 파일을 삭제
  1. 30 3
      integration-cli/docker_cli_save_load_test.go

+ 30 - 3
integration-cli/docker_cli_save_load_test.go

@@ -2,6 +2,7 @@ package main
 
 
 import (
 import (
 	"context"
 	"context"
+	"encoding/json"
 	"fmt"
 	"fmt"
 	"os"
 	"os"
 	"os/exec"
 	"os/exec"
@@ -9,8 +10,10 @@ import (
 	"strings"
 	"strings"
 	"testing"
 	"testing"
 
 
+	"github.com/docker/docker/api/types"
 	"github.com/docker/docker/integration-cli/cli/build"
 	"github.com/docker/docker/integration-cli/cli/build"
 	"gotest.tools/v3/assert"
 	"gotest.tools/v3/assert"
+	is "gotest.tools/v3/assert/cmp"
 	"gotest.tools/v3/icmd"
 	"gotest.tools/v3/icmd"
 	"gotest.tools/v3/skip"
 	"gotest.tools/v3/skip"
 )
 )
@@ -150,15 +153,39 @@ func (s *DockerCLISaveLoadSuite) TestSaveAndLoadRepoFlags(c *testing.T) {
 	deleteImages(repoName)
 	deleteImages(repoName)
 	dockerCmd(c, "commit", name, repoName)
 	dockerCmd(c, "commit", name, repoName)
 
 
-	before, _ := dockerCmd(c, "inspect", repoName)
+	beforeStr, _, err := dockerCmdWithError("inspect", repoName)
+	assert.NilError(c, err, "failed to inspect before save")
 
 
 	out, err := RunCommandPipelineWithOutput(
 	out, err := RunCommandPipelineWithOutput(
 		exec.Command(dockerBinary, "save", repoName),
 		exec.Command(dockerBinary, "save", repoName),
 		exec.Command(dockerBinary, "load"))
 		exec.Command(dockerBinary, "load"))
 	assert.NilError(c, err, "failed to save and load repo: %s, %v", out, err)
 	assert.NilError(c, err, "failed to save and load repo: %s, %v", out, err)
 
 
-	after, _ := dockerCmd(c, "inspect", repoName)
-	assert.Equal(c, before, after, "inspect is not the same after a save / load")
+	afterStr, _, err := dockerCmdWithError("inspect", repoName)
+	assert.NilError(c, err, "failed to inspect after load")
+
+	var before, after []types.ImageInspect
+	err = json.Unmarshal([]byte(beforeStr), &before)
+	assert.NilError(c, err, "failed to parse inspect 'before' output")
+	err = json.Unmarshal([]byte(afterStr), &after)
+	assert.NilError(c, err, "failed to parse inspect 'after' output")
+
+	assert.Assert(c, is.Len(before, 1))
+	assert.Assert(c, is.Len(after, 1))
+
+	if testEnv.UsingSnapshotter() {
+		// Ignore LastTagTime difference with c8d.
+		// It is not stored in the image archive, but in the imageStore
+		// which is a graphdrivers implementation detail.
+		//
+		// It works because we load the image into the same daemon which saved
+		// the image. It would still fail with the graphdrivers if the image
+		// was loaded into a different daemon (which should be the case in a
+		// real-world scenario).
+		before[0].Metadata.LastTagTime = after[0].Metadata.LastTagTime
+	}
+
+	assert.Check(c, is.DeepEqual(before, after), "inspect is not the same after a save / load")
 }
 }
 
 
 func (s *DockerCLISaveLoadSuite) TestSaveWithNoExistImage(c *testing.T) {
 func (s *DockerCLISaveLoadSuite) TestSaveWithNoExistImage(c *testing.T) {