diff_test.go 1.4 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. "gotest.tools/v3/assert"
  9. "gotest.tools/v3/poll"
  10. "gotest.tools/v3/skip"
  11. )
  12. func TestDiff(t *testing.T) {
  13. skip.If(t, testEnv.DaemonInfo.OSType == "windows", "FIXME")
  14. defer setupTest(t)()
  15. apiClient := testEnv.APIClient()
  16. ctx := context.Background()
  17. cID := container.Run(ctx, t, apiClient, 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.FilesystemChange{
  23. {Kind: containertypes.ChangeAdd, Path: "/foo"},
  24. {Kind: containertypes.ChangeAdd, Path: "/foo/bar"},
  25. }
  26. if testEnv.DaemonInfo.OSType == "windows" {
  27. poll.WaitOn(t, container.IsInState(ctx, apiClient, cID, "exited"), poll.WithDelay(100*time.Millisecond), poll.WithTimeout(60*time.Second))
  28. expected = []containertypes.FilesystemChange{
  29. {Kind: containertypes.ChangeModify, Path: "Files/foo"},
  30. {Kind: containertypes.ChangeModify, Path: "Files/foo/bar"},
  31. }
  32. }
  33. items, err := apiClient.ContainerDiff(ctx, cID)
  34. assert.NilError(t, err)
  35. assert.DeepEqual(t, expected, items)
  36. }