2018-02-05 16:05:59 -05:00
|
|
|
package image // import "github.com/docker/docker/integration/image"
|
2017-11-22 16:31:26 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
2018-05-04 17:15:00 -04:00
|
|
|
"github.com/docker/docker/api/types/versions"
|
2018-03-02 14:02:50 -05:00
|
|
|
"github.com/docker/docker/integration/internal/container"
|
2018-04-17 04:22:04 -04:00
|
|
|
"github.com/docker/docker/internal/test/request"
|
2018-03-13 15:28:34 -04:00
|
|
|
"github.com/gotestyourself/gotestyourself/assert"
|
|
|
|
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
2018-05-04 17:15:00 -04:00
|
|
|
"github.com/gotestyourself/gotestyourself/skip"
|
2017-11-22 16:31:26 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCommitInheritsEnv(t *testing.T) {
|
2018-05-04 17:15:00 -04:00
|
|
|
skip.If(t, versions.LessThan(testEnv.DaemonAPIVersion(), "1.36"), "broken in earlier versions")
|
2017-11-22 16:31:26 -05:00
|
|
|
defer setupTest(t)()
|
|
|
|
client := request.NewAPIClient(t)
|
|
|
|
ctx := context.Background()
|
|
|
|
|
2018-03-02 14:02:50 -05:00
|
|
|
cID1 := container.Create(t, ctx, client)
|
2017-11-22 16:31:26 -05:00
|
|
|
|
2018-03-02 14:02:50 -05:00
|
|
|
commitResp1, err := client.ContainerCommit(ctx, cID1, types.ContainerCommitOptions{
|
2017-11-22 16:31:26 -05:00
|
|
|
Changes: []string{"ENV PATH=/bin"},
|
|
|
|
Reference: "test-commit-image",
|
|
|
|
})
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2017-11-22 16:31:26 -05:00
|
|
|
|
|
|
|
image1, _, err := client.ImageInspectWithRaw(ctx, commitResp1.ID)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2017-11-22 16:31:26 -05:00
|
|
|
|
|
|
|
expectedEnv1 := []string{"PATH=/bin"}
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.Check(t, is.DeepEqual(expectedEnv1, image1.Config.Env))
|
2017-11-22 16:31:26 -05:00
|
|
|
|
2018-03-02 14:02:50 -05:00
|
|
|
cID2 := container.Create(t, ctx, client, container.WithImage(image1.ID))
|
2017-11-22 16:31:26 -05:00
|
|
|
|
2018-03-02 14:02:50 -05:00
|
|
|
commitResp2, err := client.ContainerCommit(ctx, cID2, types.ContainerCommitOptions{
|
2017-11-22 16:31:26 -05:00
|
|
|
Changes: []string{"ENV PATH=/usr/bin:$PATH"},
|
|
|
|
Reference: "test-commit-image",
|
|
|
|
})
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2017-11-22 16:31:26 -05:00
|
|
|
|
|
|
|
image2, _, err := client.ImageInspectWithRaw(ctx, commitResp2.ID)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2017-11-22 16:31:26 -05:00
|
|
|
expectedEnv2 := []string{"PATH=/usr/bin:/bin"}
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.Check(t, is.DeepEqual(expectedEnv2, image2.Config.Env))
|
2017-11-22 16:31:26 -05:00
|
|
|
}
|