proxy_test.go 1.2 KB

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