ronantakizawa/codereview-bench huggingface dataset:
Repository: moby/moby
File: integration/network/network_test.go (Go)

Code before:

func TestAPINetworkFilter(t *testing.T) {
	networkName := "bridge"
	if testEnv.DaemonInfo.OSType == "windows" {
		networkName = "nat"
	}

	ctx := setupTest(t)
	apiClient := testEnv.APIClient()

	res, err := apiClient.NetworkList(ctx, client.NetworkListOptions{
		Filters: make(client.Filters).Add("name", networkName),
	})

	assert.NilError(t, err)

	found := false
	for _, nw := range res.Items {
		if nw.Name == networkName {
			found = true
		}
	}
	assert.Assert(t, found, fmt.Sprintf("%s is not found", networkName))
}

func TestAPINetworkInspectWithScope(t *testing.T) {
	ctx := setupTest(t)
	apiClient := testEnv.APIClient()

	_, err := apiClient.SwarmInit(ctx, client.SwarmInitOptions{
		ListenAddr: "0.0.0.0:2377",
	})
	assert.NilError(t, err)

	name := "test-scoped-network"
	create, err := apiClient.NetworkCreate(ctx, name, client.NetworkCreateOptions{Driver: "overlay"})
	assert.NilError(t, err)

	inspect, err := apiClient.NetworkInspect(ctx, name, client.NetworkInspectOptions{})
	assert.NilError(t, err)
	assert.Check(t, is.Equal("swarm", inspect.Network.Scope))
	assert.Check(t, is.Equal(create.ID, inspect.Network.ID))

	_, err = apiClient.NetworkInspect(ctx, name, client.NetworkInspectOptions{Scope: "local"})
	assert.Check(t, is.ErrorType(err, cerrdefs.IsNotFound))

}


Review comment (suggestion):
`integration/service` has some Swarm tests - this test probably belongs in there (with a name consistent with tests already there, if that's possible - maybe just drop the `API`).

Code after:
}

func TestAPINetworkFilter(t *testing.T) {
	networkName := "bridge"
	if testEnv.DaemonInfo.OSType == "windows" {
		networkName = "nat"
	}

	ctx := setupTest(t)
	apiClient := testEnv.APIClient()

	res, err := apiClient.NetworkList(ctx, client.NetworkListOptions{
		Filters: make(client.Filters).Add("name", networkName),
	})

	assert.NilError(t, err)

	found := false
	for _, nw := range res.Items {
		if nw.Name == networkName {
			found = true
		}
	}
	assert.Assert(t, found, fmt.Sprintf("%s is not found", networkName))
}

func TestNetworkInspectWithScope(t *testing.T) {
	ctx := setupTest(t)

	d := swarm.NewSwarm(ctx, t, testEnv)
	defer d.Stop(t)

	cli := d.NewClientT(t) // IMPORTANT: talk to swarm daemon

	name := "test-scoped-network"
	create, err := cli.NetworkCreate(ctx, name, client.NetworkCreateOptions{Driver: "overlay"})
	assert.NilError(t, err)

	inspect, err := cli.NetworkInspect(ctx, name, client.NetworkInspectOptions{})
	assert.NilError(t, err)
	assert.Check(t, is.Equal("swarm", inspect.Network.Scope))
	assert.Check(t, is.Equal(create.ID, inspect.Network.ID))

	_, err = cli.NetworkInspect(ctx, name, client.NetworkInspectOptions{Scope: "local"})
	assert.Check(t, is.ErrorType(err, cerrdefs.IsNotFound))
}
Repository: moby/moby
File: integration/network/network_test.go (Go)

Code before:
	ctx := setupTest(t)
	apiClient := testEnv.APIClient()

	res, err := apiClient.NetworkList(ctx, client.NetworkListOptions{
		Filters: make(client.Filters).Add("name", networkName),
	})

	assert.NilError(t, err)

	found := false
	for _, nw := range res.Items {
		if nw.Name == networkName {
			found = true
		}
	}
	assert.Assert(t, found, fmt.Sprintf("%s is not found", networkName))
}

func TestAPINetworkInspectWithScope(t *testing.T) {
	ctx := setupTest(t)
	apiClient := testEnv.APIClient()

	_, err := apiClient.SwarmInit(ctx, client.SwarmInitOptions{
		ListenAddr: "0.0.0.0:2377",
	})
	assert.NilError(t, err)

	name := "test-scoped-network"
	create, err := apiClient.NetworkCreate(ctx, name, client.NetworkCreateOptions{Driver: "overlay"})
	assert.NilError(t, err)

	inspect, err := apiClient.NetworkInspect(ctx, name, client.NetworkInspectOptions{})
	assert.NilError(t, err)
	assert.Check(t, is.Equal("swarm", inspect.Network.Scope))
	assert.Check(t, is.Equal(create.ID, inspect.Network.ID))

	_, err = apiClient.NetworkInspect(ctx, name, client.NetworkInspectOptions{Scope: "local"})
	assert.Check(t, is.ErrorType(err, cerrdefs.IsNotFound))

}


Review comment (bug):
Tests are failing with ...

```
=== FAIL: arm64.docker.docker.integration.network TestAPINetworkInspectWithScope (0.06s)
    network_test.go:156: assertion failed: error is not nil: Error response from daemon: could not choose an IP address to advertise since this system has multiple addresses on different interfaces (172.17.0.3 on eth0 and 172.19.0.1 on docker_gwbridge)
```

Using `swarm.NewSwarm` should sort it out (it also disables iptables, so multiple Swarm nodes don't clash.)

Code after:

	ctx := setupTest(t)
	apiClient := testEnv.APIClient()

	res, err := apiClient.NetworkList(ctx, client.NetworkListOptions{
		Filters: make(client.Filters).Add("name", networkName),
	})

	assert.NilError(t, err)

	found := false
	for _, nw := range res.Items {
		if nw.Name == networkName {
			found = true
		}
	}
	assert.Assert(t, found, fmt.Sprintf("%s is not found", networkName))
}

func TestNetworkInspectWithScope(t *testing.T) {
	ctx := setupTest(t)

	d := swarm.NewSwarm(ctx, t, testEnv)
	defer d.Stop(t)

	cli := d.NewClientT(t) // IMPORTANT: talk to swarm daemon

	name := "test-scoped-network"
	create, err := cli.NetworkCreate(ctx, name, client.NetworkCreateOptions{Driver: "overlay"})
	assert.NilError(t, err)

	inspect, err := cli.NetworkInspect(ctx, name, client.NetworkInspectOptions{})
	assert.NilError(t, err)
	assert.Check(t, is.Equal("swarm", inspect.Network.Scope))
	assert.Check(t, is.Equal(create.ID, inspect.Network.ID))

	_, err = cli.NetworkInspect(ctx, name, client.NetworkInspectOptions{Scope: "local"})
	assert.Check(t, is.ErrorType(err, cerrdefs.IsNotFound))
}
Repository: moby/moby
File: daemon/network.go (Go)

Code before:
				EndpointID: t.EndpointID,
				EndpointIP: eip.Unmap(),
				Info:       t.Info,
			})
		}
		vip, _ := netip.ParseAddr(service.VIP)
		services[name] = networktypes.ServiceInfo{
			VIP:          vip.Unmap(),
			Ports:        service.Ports,
			Tasks:        tasks,
			LocalLBIndex: service.LocalLBIndex,
		}
	}
	return services
}

// buildPeerInfoResources converts a list of [networkdb.PeerInfo] to a
// [network.PeerInfo] for inclusion in API responses. It returns nil if
// the list of peers is empty.
func buildPeerInfoResources(peers []networkdb.PeerInfo) []networktypes.PeerInfo {
	if len(peers) == 0 {
		return nil
	}
	peerInfo := make([]networktypes.PeerInfo, 0, len(peers))
	for _, peer := range peers {
		peerInfo = append(peerInfo, networktypes.PeerInfo{
			IP:   peer.IP,
			Name: peer.Name,
		})
	}
	return peerInfo
}

// buildIPAMResources constructs a [network.IPAM] from the network's
// IPAM information for inclusion in API responses.
func buildIPAMResources(nw *libnetwork.Network) networktypes.IPAM {
	var ipamConfig []networktypes.IPAMConfig

	ipamDriver, ipamOptions, ipv4Conf, ipv6Conf := nw.IpamConfig()
	ipv4Info, ipv6Info := nw.IpamInfo()

	hasIPv4Config := false
	if len(ipv4Info) > 0 {
		// Only check ipv4 networks if there were any allocated
		for i, cfg := range ipv4Conf {
			if cfg.PreferredPool == "" {
				continue
			}
			hasIPv4Config = true
			subnet := ipv4Info[i].IPAMData.Pool
			if subnet != nil {

Review comment (suggestion):
the other option is to change `networkdb.PeerInfo` fields order, but I don't know the impacts
(I didn't know such a cast was valid in go!)

Code after:
				EndpointID: t.EndpointID,
				EndpointIP: eip.Unmap(),
				Info:       t.Info,
			})
		}
		vip, _ := netip.ParseAddr(service.VIP)
		services[name] = networktypes.ServiceInfo{
			VIP:          vip.Unmap(),
			Ports:        service.Ports,
			Tasks:        tasks,
			LocalLBIndex: service.LocalLBIndex,
		}
	}
	return services
}

// buildPeerInfoResources converts a list of [networkdb.PeerInfo] to a
// [network.PeerInfo] for inclusion in API responses. It returns nil if
// the list of peers is empty.
func buildPeerInfoResources(peers []networkdb.PeerInfo) []networktypes.PeerInfo {
	if len(peers) == 0 {
		return nil
	}
	peerInfo := make([]networktypes.PeerInfo, 0, len(peers))
	for _, peer := range peers {
		peerInfo = append(peerInfo, networktypes.PeerInfo(peer))
	}
	return peerInfo
}

// buildIPAMResources constructs a [network.IPAM] from the network's
// IPAM information for inclusion in API responses.
func buildIPAMResources(nw *libnetwork.Network) networktypes.IPAM {
	var ipamConfig []networktypes.IPAMConfig

	ipamDriver, ipamOptions, ipv4Conf, ipv6Conf := nw.IpamConfig()
	ipv4Info, ipv6Info := nw.IpamInfo()

	hasIPv4Config := false
	if len(ipv4Info) > 0 {
		// Only check ipv4 networks if there were any allocated
		for i, cfg := range ipv4Conf {
			if cfg.PreferredPool == "" {
				continue
			}
			hasIPv4Config = true
			subnet := ipv4Info[i].IPAMData.Pool
			if subnet != nil {
				cfg.PreferredPool = subnet.String()
			}
			if ipv4Info[i].IPAMData.Gateway != nil && cfg.Gateway == "" {
Repository: moby/moby
File: daemon/internal/nri/nri.go (Go)

Code before:
	if adj == nil {
		return nil
	}
	if err := applyEnvVars(ctx, ctr, adj.Env); err != nil {
		return fmt.Errorf("applying environment variable adjustments: %w", err)
	}
	return nil
}

func applyEnvVars(ctx context.Context, ctr *container.Container, envVars []*adaptation.KeyValue) error {
	if len(envVars) == 0 {
		return nil
	}
	existing := make(map[string]int, len(ctr.Config.Env))
	for i, e := range ctr.Config.Env {
		k, _, _ := strings.Cut(e, "=")
		existing[k] = i
	}
	for _, kv := range envVars {
		if kv.Key == "" {
			return errors.New("empty environment variable key")
		}
		val := kv.Key + "=" + kv.Value
		log.G(ctx).Debugf("Applying NRI env var adjustment to %s", kv.Key)
		if i, found := existing[kv.Key]; found {
			ctr.Config.Env[i] = val
		} else {
			ctr.Config.Env = append(ctr.Config.Env, val)
		}
	}
	return nil
}


Review comment (suggestion):
Also not relevant, but thinking out loud; if the list grows, we could make all these adjustments accept `*adaptation.ContainerAdjustment`, so that they have the same signature and we could just loop over them.

Code after:

func stateToNRI(state *container.State) adaptation.ContainerState {
	log.G(context.TODO()).Errorf("Mapping container state %q to NRI", state.State())
	switch state.State() {
	case containertypes.StateCreated:
		// CONTAINER_CREATED will be used before the container is started, including for the
		// CreateContainer hook (during container creation).
		return adaptation.ContainerState_CONTAINER_CREATED
	case containertypes.StateRunning:
		return adaptation.ContainerState_CONTAINER_RUNNING
	case containertypes.StatePaused, containertypes.StateRestarting:
		return adaptation.ContainerState_CONTAINER_PAUSED
	case containertypes.StateRemoving, containertypes.StateExited, containertypes.StateDead:
		return adaptation.ContainerState_CONTAINER_STOPPED
	}
	return adaptation.ContainerState_CONTAINER_UNKNOWN
}

func applyAdjustments(ctx context.Context, ctr *container.Container, adj *adaptation.ContainerAdjustment) error {
	if adj == nil {
		return nil
	}
	if err := applyEnvVars(ctx, ctr, adj.Env); err != nil {
		return fmt.Errorf("applying environment variable adjustments: %w", err)
	}
	if err := applyMounts(ctx, ctr, adj.Mounts); err != nil {
		return fmt.Errorf("applying mount adjustments: %w", err)
	}
	return nil
}

func applyEnvVars(ctx context.Context, ctr *container.Container, envVars []*adaptation.KeyValue) error {
	if len(envVars) == 0 {
		return nil
	}
	existing := make(map[string]int, len(ctr.Config.Env))
	for i, e := range ctr.Config.Env {
		k, _, _ := strings.Cut(e, "=")
		existing[k] = i
	}
	for _, kv := range envVars {
		if kv.Key == "" {
			return errors.New("empty environment variable key")
		}
		val := kv.Key + "=" + kv.Value
		log.G(ctx).Debugf("Applying NRI env var adjustment to %s", kv.Key)
		if i, found := existing[kv.Key]; found {
			ctr.Config.Env[i] = val
		} else {
			ctr.Config.Env = append(ctr.Config.Env, val)
		}
Repository: moby/moby
File: daemon/libnetwork/libnetwork_linux_test.go (Go)

Code before:
		netlabel.GenericData: map[string]string{
			bridge.BridgeName: "network",
		},
	}

	net1 := makeTesthostNetwork(t, controller)
	defer net1.Delete()
	net2, err := createTestNetwork(controller, "bridge", "network2", netOption, nil, nil)
	assert.NilError(t, err)
	defer net2.Delete()

	_, err = net1.CreateEndpoint(context.Background(), "pep1")
	assert.NilError(t, err)

	_, err = net2.CreateEndpoint(context.Background(), "pep2")
	assert.NilError(t, err)

	_, err = net2.CreateEndpoint(context.Background(), "pep3")
	assert.NilError(t, err)

	sboxes := make([]*libnetwork.Sandbox, numThreads)
	sboxes[0], err = controller.NewSandbox(context.Background(), fmt.Sprintf("%drace", 1), libnetwork.OptionUseDefaultSandbox())
	assert.NilError(t, err)

	for i := range numThreads {
		sboxes[i], err = controller.NewSandbox(context.Background(), fmt.Sprintf("%drace", i+1))
		assert.NilError(t, err)
	}

	pt := parallelTester{
		osctx:      osctx,
		controller: controller,
		net1:       net1,
		net2:       net2,
		iterCnt:    iterCnt,
	}

	var eg errgroup.Group
	for i := range numThreads {
		eg.Go(func() error { return pt.Do(t, i+1) })
	}
	err = eg.Wait()
	assert.NilError(t, err)
}

func TestBridge(t *testing.T) {
	defer netnsutils.SetupTestOSContext(t)()
	controller := newController(t)

	netOption := options.Generic{
		netlabel.EnableIPv4: true,

Review comment (suggestion):
Previously `thd` would start with `first + 1 => 1 +1 => 2`.

Then `sboxes[thd-1] => sboxes[2-1] => sboxes[1]`

Now `for i := range numThreads {` will start with `i = 0`, which would mean `sboxes[0]` instead of `sboxes[1]`.



Code after:
	netOption := options.Generic{
		netlabel.EnableIPv4: true,
		netlabel.GenericData: map[string]string{
			bridge.BridgeName: "network",
		},
	}

	net1 := makeTesthostNetwork(t, controller)
	defer net1.Delete()
	net2, err := createTestNetwork(controller, "bridge", "network2", netOption, nil, nil)
	assert.NilError(t, err)
	defer net2.Delete()

	_, err = net1.CreateEndpoint(context.Background(), "pep1")
	assert.NilError(t, err)

	_, err = net2.CreateEndpoint(context.Background(), "pep2")
	assert.NilError(t, err)

	_, err = net2.CreateEndpoint(context.Background(), "pep3")
	assert.NilError(t, err)

	sboxes := make([]*libnetwork.Sandbox, numThreads)
	sboxes[first-1], err = controller.NewSandbox(context.Background(), fmt.Sprintf("%drace", first), libnetwork.OptionUseDefaultSandbox())
	assert.NilError(t, err)

	for thd := first + 1; thd <= last; thd++ {
		sboxes[thd-1], err = controller.NewSandbox(context.Background(), fmt.Sprintf("%drace", thd))
		assert.NilError(t, err)
	}

	pt := parallelTester{
		osctx:      osctx,
		controller: controller,
		net1:       net1,
		net2:       net2,
		iterCnt:    iterCnt,
	}

	var eg errgroup.Group
	for i := first; i <= last; i++ {
		eg.Go(func() error { return pt.Do(t, i) })
	}
	err = eg.Wait()
	assert.NilError(t, err)
}

func TestBridge(t *testing.T) {
	defer netnsutils.SetupTestOSContext(t)()
	controller := newController(t)
Repository: moby/moby
File: daemon/volume/mounts/linux_parser_test.go (Go)

Code before:

	parser := NewLinuxParser()
	if p, ok := parser.(*linuxParser); ok {
		p.fi = mockFiProvider{}
	}

	for _, tc := range tests {
		t.Run(tc.bind, func(t *testing.T) {
			m, err := parser.ParseMountRaw(tc.bind, tc.driver)
			if tc.expErr != "" {
				assert.Check(t, is.Nil(m))
				assert.Check(t, is.Error(err, tc.expErr))
				return
			}

			assert.NilError(t, err)
			assert.Check(t, is.DeepEqual(*m, *tc.expected, cmpopts.IgnoreUnexported(MountPoint{})))
		})
	}
}

func TestLinuxValidateMounts(t *testing.T) {
	tests := []struct {
		mount    mount.Mount
		expected *MountPoint
		expErr   string
	}{
		{
			mount: mount.Mount{
				Source: "/tmp",
				Target: "/tmp1",
				Type:   mount.TypeBind,
			},
			expected: &MountPoint{
				Source:      "/tmp",
				Destination: "/tmp1",
				RW:          true,
				Type:        mount.TypeBind,
				Propagation: "rprivate",
				Spec: mount.Mount{
					Source: "/tmp",
					Target: "/tmp1",
					Type:   mount.TypeBind,
				},
			},
		},
		{
			mount: mount.Mount{
				Target:   "/data/anonymous-read-only-volume",
				ReadOnly: true,
				Type:     mount.TypeVolume,

Review comment (suggestion):
Perhaps adding a `tmpDir` to make sure the host-path exists would work;


```suggestion
	tmpDir := t.TempDir()

	tests := []struct {
```

Code after:
	}

	parser := NewLinuxParser()
	if p, ok := parser.(*linuxParser); ok {
		p.fi = mockFiProvider{}
	}

	for _, tc := range tests {
		t.Run(tc.bind, func(t *testing.T) {
			m, err := parser.ParseMountRaw(tc.bind, tc.driver)
			if tc.expErr != "" {
				assert.Check(t, is.Nil(m))
				assert.Check(t, is.Error(err, tc.expErr))
				return
			}

			assert.NilError(t, err)
			assert.Check(t, is.DeepEqual(*m, *tc.expected, cmpopts.IgnoreUnexported(MountPoint{})))
		})
	}
}

func TestLinuxValidateMounts(t *testing.T) {
	tmpDir := t.TempDir()

	tests := []struct {
		doc         string
		mount       mount.Mount
		expected    *MountPoint
		expErr      string
		skipWindows bool
	}{
		{
			doc: "read-write",
			// Skip Windows tests because the source path won't be a valid Windows path.
			skipWindows: true,
			mount: mount.Mount{
				Source: tmpDir,
				Target: "/tmp1",
				Type:   mount.TypeBind,
			},
			expected: &MountPoint{
				Source:      tmpDir,
				Destination: "/tmp1",
				RW:          true,
				Type:        mount.TypeBind,
				Propagation: "rprivate",
				Spec: mount.Mount{
					Source: tmpDir,
					Target: "/tmp1",
					Type:   mount.TypeBind,
Repository: moby/moby
File: daemon/volume/mounts/linux_parser_test.go (Go)

Code before:
	}

	for _, tc := range tests {
		t.Run(tc.bind, func(t *testing.T) {
			m, err := parser.ParseMountRaw(tc.bind, tc.driver)
			if tc.expErr != "" {
				assert.Check(t, is.Nil(m))
				assert.Check(t, is.Error(err, tc.expErr))
				return
			}

			assert.NilError(t, err)
			assert.Check(t, is.DeepEqual(*m, *tc.expected, cmpopts.IgnoreUnexported(MountPoint{})))
		})
	}
}

func TestLinuxValidateMounts(t *testing.T) {
	tests := []struct {
		mount    mount.Mount
		expected *MountPoint
		expErr   string
	}{
		{
			mount: mount.Mount{
				Source: "/tmp",
				Target: "/tmp1",
				Type:   mount.TypeBind,
			},
			expected: &MountPoint{
				Source:      "/tmp",
				Destination: "/tmp1",
				RW:          true,
				Type:        mount.TypeBind,
				Propagation: "rprivate",
				Spec: mount.Mount{
					Source: "/tmp",
					Target: "/tmp1",
					Type:   mount.TypeBind,
				},
			},
		},
		{
			mount: mount.Mount{
				Target:   "/data/anonymous-read-only-volume",
				ReadOnly: true,
				Type:     mount.TypeVolume,
			},
			expected: &MountPoint{
				Destination: "/data/anonymous-read-only-volume",
				Type:        mount.TypeVolume,

Review comment (suggestion):
Then use that here;


```suggestion
				Source: tmpDir,
```

Code after:
		p.fi = mockFiProvider{}
	}

	for _, tc := range tests {
		t.Run(tc.bind, func(t *testing.T) {
			m, err := parser.ParseMountRaw(tc.bind, tc.driver)
			if tc.expErr != "" {
				assert.Check(t, is.Nil(m))
				assert.Check(t, is.Error(err, tc.expErr))
				return
			}

			assert.NilError(t, err)
			assert.Check(t, is.DeepEqual(*m, *tc.expected, cmpopts.IgnoreUnexported(MountPoint{})))
		})
	}
}

func TestLinuxValidateMounts(t *testing.T) {
	tmpDir := t.TempDir()

	tests := []struct {
		doc         string
		mount       mount.Mount
		expected    *MountPoint
		expErr      string
		skipWindows bool
	}{
		{
			doc: "read-write",
			// Skip Windows tests because the source path won't be a valid Windows path.
			skipWindows: true,
			mount: mount.Mount{
				Source: tmpDir,
				Target: "/tmp1",
				Type:   mount.TypeBind,
			},
			expected: &MountPoint{
				Source:      tmpDir,
				Destination: "/tmp1",
				RW:          true,
				Type:        mount.TypeBind,
				Propagation: "rprivate",
				Spec: mount.Mount{
					Source: tmpDir,
					Target: "/tmp1",
					Type:   mount.TypeBind,
				},
			},
		},
		{
Repository: moby/moby
File: daemon/volume/mounts/linux_parser_test.go (Go)

Code before:
			if tc.expErr != "" {
				assert.Check(t, is.Nil(m))
				assert.Check(t, is.Error(err, tc.expErr))
				return
			}

			assert.NilError(t, err)
			assert.Check(t, is.DeepEqual(*m, *tc.expected, cmpopts.IgnoreUnexported(MountPoint{})))
		})
	}
}

func TestLinuxValidateMounts(t *testing.T) {
	tests := []struct {
		mount    mount.Mount
		expected *MountPoint
		expErr   string
	}{
		{
			mount: mount.Mount{
				Source: "/tmp",
				Target: "/tmp1",
				Type:   mount.TypeBind,
			},
			expected: &MountPoint{
				Source:      "/tmp",
				Destination: "/tmp1",
				RW:          true,
				Type:        mount.TypeBind,
				Propagation: "rprivate",
				Spec: mount.Mount{
					Source: "/tmp",
					Target: "/tmp1",
					Type:   mount.TypeBind,
				},
			},
		},
		{
			mount: mount.Mount{
				Target:   "/data/anonymous-read-only-volume",
				ReadOnly: true,
				Type:     mount.TypeVolume,
			},
			expected: &MountPoint{
				Destination: "/data/anonymous-read-only-volume",
				Type:        mount.TypeVolume,
				CopyData:    true,
				Spec: mount.Mount{
					Target:   "/data/anonymous-read-only-volume",
					ReadOnly: true,
					Type:     mount.TypeVolume,

Review comment (suggestion):
And here;


```suggestion
				Source:      tmpDir,
```

Code after:
			m, err := parser.ParseMountRaw(tc.bind, tc.driver)
			if tc.expErr != "" {
				assert.Check(t, is.Nil(m))
				assert.Check(t, is.Error(err, tc.expErr))
				return
			}

			assert.NilError(t, err)
			assert.Check(t, is.DeepEqual(*m, *tc.expected, cmpopts.IgnoreUnexported(MountPoint{})))
		})
	}
}

func TestLinuxValidateMounts(t *testing.T) {
	tmpDir := t.TempDir()

	tests := []struct {
		doc         string
		mount       mount.Mount
		expected    *MountPoint
		expErr      string
		skipWindows bool
	}{
		{
			doc: "read-write",
			// Skip Windows tests because the source path won't be a valid Windows path.
			skipWindows: true,
			mount: mount.Mount{
				Source: tmpDir,
				Target: "/tmp1",
				Type:   mount.TypeBind,
			},
			expected: &MountPoint{
				Source:      tmpDir,
				Destination: "/tmp1",
				RW:          true,
				Type:        mount.TypeBind,
				Propagation: "rprivate",
				Spec: mount.Mount{
					Source: tmpDir,
					Target: "/tmp1",
					Type:   mount.TypeBind,
				},
			},
		},
		{
			doc: "read-only",
			mount: mount.Mount{
				Target:   "/data/anonymous-read-only-volume",
				ReadOnly: true,
				Type:     mount.TypeVolume,