diff_test.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package container // import "github.com/docker/docker/integration/container"
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. containertypes "github.com/docker/docker/api/types/container"
  7. "github.com/docker/docker/integration/internal/container"
  8. "github.com/docker/docker/internal/test/request"
  9. "github.com/docker/docker/pkg/archive"
  10. "github.com/gotestyourself/gotestyourself/assert"
  11. "github.com/gotestyourself/gotestyourself/poll"
  12. )
  13. func TestDiff(t *testing.T) {
  14. defer setupTest(t)()
  15. client := request.NewAPIClient(t)
  16. ctx := context.Background()
  17. cID := container.Run(t, ctx, client, container.WithCmd("sh", "-c", `mkdir /foo; echo xyzzy > /foo/bar`))
  18. // Wait for it to exit as cannot diff a running container on Windows, and
  19. // it will take a few seconds to exit. Also there's no way in Windows to
  20. // differentiate between an Add or a Modify, and all files are under
  21. // a "Files/" prefix.
  22. expected := []containertypes.ContainerChangeResponseItem{
  23. {Kind: archive.ChangeAdd, Path: "/foo"},
  24. {Kind: archive.ChangeAdd, Path: "/foo/bar"},
  25. }
  26. if testEnv.OSType == "windows" {
  27. poll.WaitOn(t, container.IsInState(ctx, client, cID, "exited"), poll.WithDelay(100*time.Millisecond), poll.WithTimeout(60*time.Second))
  28. expected = []containertypes.ContainerChangeResponseItem{
  29. {Kind: archive.ChangeModify, Path: "Files/foo"},
  30. {Kind: archive.ChangeModify, Path: "Files/foo/bar"},
  31. }
  32. }
  33. items, err := client.ContainerDiff(ctx, cID)
  34. assert.NilError(t, err)
  35. assert.DeepEqual(t, expected, items)
  36. }