Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: all mounts should contain the testcontainers labels #2191

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docker_mounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ func mapToDockerMounts(containerMounts ContainerMounts) []mount.Mount {
Source: m.Source.Source(),
ReadOnly: m.ReadOnly,
Target: m.Target.Target(),
VolumeOptions: &mount.VolumeOptions{
Labels: GenericLabels(),
},
}

switch typedMounter := m.Source.(type) {
Expand Down
64 changes: 52 additions & 12 deletions mounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ func TestVolumeMount(t *testing.T) {
}

func TestContainerMounts_PrepareMounts(t *testing.T) {
volumeOptions := &mount.VolumeOptions{
Labels: GenericLabels(),
}

t.Parallel()
tests := []struct {
name string
Expand All @@ -57,9 +61,10 @@ func TestContainerMounts_PrepareMounts(t *testing.T) {
mounts: ContainerMounts{{Source: GenericVolumeMountSource{Name: "app-data"}, Target: "/data"}},
want: []mount.Mount{
{
Type: mount.TypeVolume,
Source: "app-data",
Target: "/data",
Type: mount.TypeVolume,
Source: "app-data",
Target: "/data",
VolumeOptions: volumeOptions,
},
},
},
Expand All @@ -68,10 +73,11 @@ func TestContainerMounts_PrepareMounts(t *testing.T) {
mounts: ContainerMounts{{Source: GenericVolumeMountSource{Name: "app-data"}, Target: "/data", ReadOnly: true}},
want: []mount.Mount{
{
Type: mount.TypeVolume,
Source: "app-data",
Target: "/data",
ReadOnly: true,
Type: mount.TypeVolume,
Source: "app-data",
Target: "/data",
ReadOnly: true,
VolumeOptions: volumeOptions,
},
},
},
Expand Down Expand Up @@ -111,8 +117,9 @@ func TestContainerMounts_PrepareMounts(t *testing.T) {
mounts: ContainerMounts{{Source: GenericTmpfsMountSource{}, Target: "/data"}},
want: []mount.Mount{
{
Type: mount.TypeTmpfs,
Target: "/data",
Type: mount.TypeTmpfs,
Target: "/data",
VolumeOptions: volumeOptions,
},
},
},
Expand All @@ -121,9 +128,10 @@ func TestContainerMounts_PrepareMounts(t *testing.T) {
mounts: ContainerMounts{{Source: GenericTmpfsMountSource{}, Target: "/data", ReadOnly: true}},
want: []mount.Mount{
{
Type: mount.TypeTmpfs,
Target: "/data",
ReadOnly: true,
Type: mount.TypeTmpfs,
Target: "/data",
ReadOnly: true,
VolumeOptions: volumeOptions,
},
},
},
Expand All @@ -148,6 +156,7 @@ func TestContainerMounts_PrepareMounts(t *testing.T) {
SizeBytes: 50 * 1024 * 1024,
Mode: 0o644,
},
VolumeOptions: volumeOptions,
},
},
},
Expand Down Expand Up @@ -193,3 +202,34 @@ func TestCreateContainerWithVolume(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, "test-volume", volume.Name)
}

func TestMountsReceiveRyukLabels(t *testing.T) {
req := ContainerRequest{
Image: "alpine",
Mounts: ContainerMounts{
{
Source: GenericVolumeMountSource{
Name: "app-data",
},
Target: "/data",
},
},
}

ctx := context.Background()
c, err := GenericContainer(ctx, GenericContainerRequest{
ContainerRequest: req,
Started: true,
})
require.NoError(t, err)
terminateContainerOnEnd(t, ctx, c)

// Check if volume is created with the expected labels
client, err := NewDockerClientWithOpts(ctx)
require.NoError(t, err)
defer client.Close()

volume, err := client.VolumeInspect(ctx, "app-data")
require.NoError(t, err)
assert.Equal(t, GenericLabels(), volume.Labels)
}
Loading