diff_test.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. "gotest.tools/assert"
  11. "gotest.tools/poll"
  12. "gotest.tools/skip"
  13. )
  14. func TestDiff(t *testing.T) {
  15. skip.If(t, testEnv.OSType == "windows", "FIXME")
  16. defer setupTest(t)()
  17. client := request.NewAPIClient(t)
  18. ctx := context.Background()
  19. cID := container.Run(t, ctx, client, container.WithCmd("sh", "-c", `mkdir /foo; echo xyzzy > /foo/bar`))
  20. // Wait for it to exit as cannot diff a running container on Windows, and
  21. // it will take a few seconds to exit. Also there's no way in Windows to
  22. // differentiate between an Add or a Modify, and all files are under
  23. // a "Files/" prefix.
  24. expected := []containertypes.ContainerChangeResponseItem{
  25. {Kind: archive.ChangeAdd, Path: "/foo"},
  26. {Kind: archive.ChangeAdd, Path: "/foo/bar"},
  27. }
  28. if testEnv.OSType == "windows" {
  29. poll.WaitOn(t, container.IsInState(ctx, client, cID, "exited"), poll.WithDelay(100*time.Millisecond), poll.WithTimeout(60*time.Second))
  30. expected = []containertypes.ContainerChangeResponseItem{
  31. {Kind: archive.ChangeModify, Path: "Files/foo"},
  32. {Kind: archive.ChangeModify, Path: "Files/foo/bar"},
  33. }
  34. }
  35. items, err := client.ContainerDiff(ctx, cID)
  36. assert.NilError(t, err)
  37. assert.DeepEqual(t, expected, items)
  38. }