2018-02-15 04:02:27 -05:00
|
|
|
package container // import "github.com/docker/docker/integration/container"
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
containertypes "github.com/docker/docker/api/types/container"
|
|
|
|
"github.com/docker/docker/integration/internal/container"
|
|
|
|
"github.com/docker/docker/pkg/archive"
|
2018-06-11 09:32:11 -04:00
|
|
|
"gotest.tools/assert"
|
|
|
|
"gotest.tools/poll"
|
2018-04-19 05:14:15 -04:00
|
|
|
"gotest.tools/skip"
|
2018-02-15 04:02:27 -05:00
|
|
|
)
|
|
|
|
|
2018-03-09 12:27:47 -05:00
|
|
|
func TestDiff(t *testing.T) {
|
2018-04-19 05:14:15 -04:00
|
|
|
skip.If(t, testEnv.OSType == "windows", "FIXME")
|
2018-02-15 04:02:27 -05:00
|
|
|
defer setupTest(t)()
|
2019-01-02 08:16:25 -05:00
|
|
|
client := testEnv.APIClient()
|
2018-02-15 04:02:27 -05:00
|
|
|
ctx := context.Background()
|
|
|
|
|
2019-06-06 07:15:31 -04:00
|
|
|
cID := container.Run(ctx, t, client, container.WithCmd("sh", "-c", `mkdir /foo; echo xyzzy > /foo/bar`))
|
2018-02-15 04:02:27 -05:00
|
|
|
|
|
|
|
// Wait for it to exit as cannot diff a running container on Windows, and
|
|
|
|
// it will take a few seconds to exit. Also there's no way in Windows to
|
|
|
|
// differentiate between an Add or a Modify, and all files are under
|
|
|
|
// a "Files/" prefix.
|
2018-03-09 12:27:47 -05:00
|
|
|
expected := []containertypes.ContainerChangeResponseItem{
|
|
|
|
{Kind: archive.ChangeAdd, Path: "/foo"},
|
|
|
|
{Kind: archive.ChangeAdd, Path: "/foo/bar"},
|
|
|
|
}
|
2018-02-15 04:02:27 -05:00
|
|
|
if testEnv.OSType == "windows" {
|
2018-02-22 05:30:51 -05:00
|
|
|
poll.WaitOn(t, container.IsInState(ctx, client, cID, "exited"), poll.WithDelay(100*time.Millisecond), poll.WithTimeout(60*time.Second))
|
2018-03-09 12:27:47 -05:00
|
|
|
expected = []containertypes.ContainerChangeResponseItem{
|
|
|
|
{Kind: archive.ChangeModify, Path: "Files/foo"},
|
|
|
|
{Kind: archive.ChangeModify, Path: "Files/foo/bar"},
|
2018-02-15 04:02:27 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
items, err := client.ContainerDiff(ctx, cID)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2017-12-22 16:30:49 -05:00
|
|
|
assert.DeepEqual(t, expected, items)
|
2018-02-15 04:02:27 -05:00
|
|
|
}
|