github.com/jwhonce/docker@v0.6.7-0.20190327063223-da823cf3a5a3/integration/image/commit_test.go (about)

     1  package image // import "github.com/docker/docker/integration/image"
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/docker/docker/api/types"
     8  	"github.com/docker/docker/api/types/versions"
     9  	"github.com/docker/docker/integration/internal/container"
    10  	"gotest.tools/assert"
    11  	is "gotest.tools/assert/cmp"
    12  	"gotest.tools/skip"
    13  )
    14  
    15  func TestCommitInheritsEnv(t *testing.T) {
    16  	skip.If(t, versions.LessThan(testEnv.DaemonAPIVersion(), "1.36"), "broken in earlier versions")
    17  	skip.If(t, testEnv.DaemonInfo.OSType == "windows", "FIXME")
    18  	defer setupTest(t)()
    19  	client := testEnv.APIClient()
    20  	ctx := context.Background()
    21  
    22  	cID1 := container.Create(t, ctx, client)
    23  
    24  	commitResp1, err := client.ContainerCommit(ctx, cID1, types.ContainerCommitOptions{
    25  		Changes:   []string{"ENV PATH=/bin"},
    26  		Reference: "test-commit-image",
    27  	})
    28  	assert.NilError(t, err)
    29  
    30  	image1, _, err := client.ImageInspectWithRaw(ctx, commitResp1.ID)
    31  	assert.NilError(t, err)
    32  
    33  	expectedEnv1 := []string{"PATH=/bin"}
    34  	assert.Check(t, is.DeepEqual(expectedEnv1, image1.Config.Env))
    35  
    36  	cID2 := container.Create(t, ctx, client, container.WithImage(image1.ID))
    37  
    38  	commitResp2, err := client.ContainerCommit(ctx, cID2, types.ContainerCommitOptions{
    39  		Changes:   []string{"ENV PATH=/usr/bin:$PATH"},
    40  		Reference: "test-commit-image",
    41  	})
    42  	assert.NilError(t, err)
    43  
    44  	image2, _, err := client.ImageInspectWithRaw(ctx, commitResp2.ID)
    45  	assert.NilError(t, err)
    46  	expectedEnv2 := []string{"PATH=/usr/bin:/bin"}
    47  	assert.Check(t, is.DeepEqual(expectedEnv2, image2.Config.Env))
    48  }