github.com/rawahars/moby@v24.0.4+incompatible/daemon/graphdriver/proxy_test.go (about)

     1  package graphdriver // import "github.com/docker/docker/daemon/graphdriver"
     2  
     3  import (
     4  	"encoding/json"
     5  	"testing"
     6  
     7  	"github.com/docker/docker/pkg/idtools"
     8  	"gotest.tools/v3/assert"
     9  )
    10  
    11  func TestGraphDriverInitRequestIsCompatible(t *testing.T) {
    12  	// Graph driver plugins may unmarshal into this version of the init
    13  	// request struct. Verify that the serialization of
    14  	// graphDriverInitRequest is fully backwards compatible.
    15  
    16  	type graphDriverInitRequestV1 struct {
    17  		Home    string
    18  		Opts    []string        `json:"Opts"`
    19  		UIDMaps []idtools.IDMap `json:"UIDMaps"`
    20  		GIDMaps []idtools.IDMap `json:"GIDMaps"`
    21  	}
    22  
    23  	args := graphDriverInitRequest{
    24  		Home: "homedir",
    25  		Opts: []string{"option1", "option2"},
    26  		IdentityMapping: idtools.IdentityMapping{
    27  			UIDMaps: []idtools.IDMap{{ContainerID: 123, HostID: 456, Size: 42}},
    28  			GIDMaps: []idtools.IDMap{{ContainerID: 789, HostID: 1011, Size: 16}},
    29  		},
    30  	}
    31  	v, err := json.Marshal(&args)
    32  	assert.NilError(t, err)
    33  
    34  	var got graphDriverInitRequestV1
    35  	assert.NilError(t, json.Unmarshal(v, &got))
    36  	want := graphDriverInitRequestV1{
    37  		Home:    args.Home,
    38  		Opts:    args.Opts,
    39  		UIDMaps: args.UIDMaps,
    40  		GIDMaps: args.GIDMaps,
    41  	}
    42  	assert.DeepEqual(t, got, want)
    43  }