|
@@ -6,6 +6,8 @@ import (
|
|
|
"strings"
|
|
|
"testing"
|
|
|
|
|
|
+ "github.com/docker/docker/api/types/container"
|
|
|
+ "github.com/docker/docker/layer"
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
"github.com/stretchr/testify/require"
|
|
|
)
|
|
@@ -51,3 +53,38 @@ func TestMarshalKeyOrder(t *testing.T) {
|
|
|
t.Fatal("invalid key order in JSON: ", string(b))
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+func TestNewChildImageFromImageWithRootFS(t *testing.T) {
|
|
|
+ rootFS := NewRootFS()
|
|
|
+ rootFS.Append(layer.DiffID("ba5e"))
|
|
|
+ parent := &Image{
|
|
|
+ RootFS: rootFS,
|
|
|
+ History: []History{
|
|
|
+ NewHistory("a", "c", "r", false),
|
|
|
+ },
|
|
|
+ }
|
|
|
+ childConfig := ChildConfig{
|
|
|
+ DiffID: layer.DiffID("abcdef"),
|
|
|
+ Author: "author",
|
|
|
+ Comment: "comment",
|
|
|
+ ContainerConfig: &container.Config{
|
|
|
+ Cmd: []string{"echo", "foo"},
|
|
|
+ },
|
|
|
+ Config: &container.Config{},
|
|
|
+ }
|
|
|
+
|
|
|
+ newImage := NewChildImage(parent, childConfig, "platform")
|
|
|
+ expectedDiffIDs := []layer.DiffID{layer.DiffID("ba5e"), layer.DiffID("abcdef")}
|
|
|
+ assert.Equal(t, expectedDiffIDs, newImage.RootFS.DiffIDs)
|
|
|
+ assert.Equal(t, childConfig.Author, newImage.Author)
|
|
|
+ assert.Equal(t, childConfig.Config, newImage.Config)
|
|
|
+ assert.Equal(t, *childConfig.ContainerConfig, newImage.ContainerConfig)
|
|
|
+ assert.Equal(t, "platform", newImage.OS)
|
|
|
+ assert.Equal(t, childConfig.Config, newImage.Config)
|
|
|
+
|
|
|
+ assert.Len(t, newImage.History, 2)
|
|
|
+ assert.Equal(t, childConfig.Comment, newImage.History[1].Comment)
|
|
|
+
|
|
|
+ // RootFS should be copied not mutated
|
|
|
+ assert.NotEqual(t, parent.RootFS.DiffIDs, newImage.RootFS.DiffIDs)
|
|
|
+}
|