github.com/rita33cool1/iot-system-gateway@v0.0.0-20200911033302-e65bde238cc5/docker-engine/integration/container/diff_test.go (about)

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