github.com/resin-io/docker@v1.13.1/image/v1/imagev1_test.go (about)

     1  package v1
     2  
     3  import (
     4  	"encoding/json"
     5  	"testing"
     6  
     7  	"github.com/docker/docker/image"
     8  )
     9  
    10  func TestMakeV1ConfigFromConfig(t *testing.T) {
    11  	img := &image.Image{
    12  		V1Image: image.V1Image{
    13  			ID:     "v2id",
    14  			Parent: "v2parent",
    15  			OS:     "os",
    16  		},
    17  		OSVersion: "osversion",
    18  		RootFS: &image.RootFS{
    19  			Type: "layers",
    20  		},
    21  	}
    22  	v2js, err := json.Marshal(img)
    23  	if err != nil {
    24  		t.Fatal(err)
    25  	}
    26  
    27  	// Convert the image back in order to get RawJSON() support.
    28  	img, err = image.NewFromJSON(v2js)
    29  	if err != nil {
    30  		t.Fatal(err)
    31  	}
    32  
    33  	js, err := MakeV1ConfigFromConfig(img, "v1id", "v1parent", false)
    34  	if err != nil {
    35  		t.Fatal(err)
    36  	}
    37  
    38  	newimg := &image.Image{}
    39  	err = json.Unmarshal(js, newimg)
    40  	if err != nil {
    41  		t.Fatal(err)
    42  	}
    43  
    44  	if newimg.V1Image.ID != "v1id" || newimg.Parent != "v1parent" {
    45  		t.Error("ids should have changed", newimg.V1Image.ID, newimg.V1Image.Parent)
    46  	}
    47  
    48  	if newimg.RootFS != nil {
    49  		t.Error("rootfs should have been removed")
    50  	}
    51  
    52  	if newimg.V1Image.OS != "os" {
    53  		t.Error("os should have been preserved")
    54  	}
    55  }