Skip to content

Commit

Permalink
test: fix image label test
Browse files Browse the repository at this point in the history
Fix test for image label setting which could fail if the volume already
existed.
  • Loading branch information
stevenh committed Aug 6, 2024
1 parent 8b42143 commit 708d410
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions mounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,19 +217,24 @@ func TestMountsReceiveRyukLabels(t *testing.T) {
}

ctx := context.Background()
client, err := testcontainers.NewDockerClientWithOpts(ctx)
require.NoError(t, err)
defer client.Close()

// Ensure the volume is removed before creating the container
// otherwise the volume will be reused and the labels won't be set.
err = client.VolumeRemove(ctx, "app-data", true)
require.NoError(t, err)

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

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

// Check if volume is created with the expected labels.
volume, err := client.VolumeInspect(ctx, "app-data")
require.NoError(t, err)
assert.Equal(t, testcontainers.GenericLabels(), volume.Labels)
require.Equal(t, testcontainers.GenericLabels(), volume.Labels)
}

0 comments on commit 708d410

Please sign in to comment.