moby/image/v1/imagev1_test.go
John Starks 194eaa5c0f Add os_version and os_features to Image
These fields are needed to specify the exact version of Windows that an
image can run on. They may be useful for other platforms in the future.

This also changes image.store.Create to validate that the loaded image is
supported on the current machine. This change affects Linux as well, since
it now validates the architecture and OS fields.

Signed-off-by: John Starks <jostarks@microsoft.com>
2016-04-04 13:14:57 -07:00

55 lines
1 KiB
Go

package v1
import (
"encoding/json"
"testing"
"github.com/docker/docker/image"
)
func TestMakeV1ConfigFromConfig(t *testing.T) {
img := &image.Image{
V1Image: image.V1Image{
ID: "v2id",
Parent: "v2parent",
OS: "os",
},
OSVersion: "osversion",
RootFS: &image.RootFS{
Type: "layers",
},
}
v2js, err := json.Marshal(img)
if err != nil {
t.Fatal(err)
}
// Convert the image back in order to get RawJSON() support.
img, err = image.NewFromJSON(v2js)
if err != nil {
t.Fatal(err)
}
js, err := MakeV1ConfigFromConfig(img, "v1id", "v1parent", false)
if err != nil {
t.Fatal(err)
}
newimg := &image.Image{}
err = json.Unmarshal(js, newimg)
if err != nil {
t.Fatal(err)
}
if newimg.V1Image.ID != "v1id" || newimg.Parent != "v1parent" {
t.Error("ids should have changed", newimg.V1Image.ID, newimg.V1Image.Parent)
}
if newimg.RootFS != nil {
t.Error("rootfs should have been removed")
}
if newimg.V1Image.OS != "os" {
t.Error("os should have been preserved")
}
}