diff --git a/cmd/compose/options_test.go b/cmd/compose/options_test.go index db6e8c0a8..1686dfaf7 100644 --- a/cmd/compose/options_test.go +++ b/cmd/compose/options_test.go @@ -18,7 +18,6 @@ package compose import ( "bytes" - "context" "fmt" "io" "os" @@ -244,16 +243,11 @@ services: } // Set up the context with necessary environment variables - ctx := context.Background() - _ = os.Setenv("TEST_VAR", "test-value") - _ = os.Setenv("API_KEY", "123456") - defer func() { - _ = os.Unsetenv("TEST_VAR") - _ = os.Unsetenv("API_KEY") - }() + t.Setenv("TEST_VAR", "test-value") + t.Setenv("API_KEY", "123456") // Extract variables from the model - info, noVariables, err := extractInterpolationVariablesFromModel(ctx, cli, projectOptions, []string{}) + info, noVariables, err := extractInterpolationVariablesFromModel(t.Context(), cli, projectOptions, []string{}) require.NoError(t, err) require.False(t, noVariables) diff --git a/internal/desktop/client_test.go b/internal/desktop/client_test.go index 0355dd501..abc4f3312 100644 --- a/internal/desktop/client_test.go +++ b/internal/desktop/client_test.go @@ -17,7 +17,6 @@ package desktop import ( - "context" "os" "testing" "time" @@ -34,9 +33,6 @@ func TestClientPing(t *testing.T) { t.Skip("Skipping - COMPOSE_TEST_DESKTOP_ENDPOINT not defined") } - ctx, cancel := context.WithCancel(context.Background()) - t.Cleanup(cancel) - client := NewClient(desktopEndpoint) t.Cleanup(func() { _ = client.Close() @@ -44,7 +40,7 @@ func TestClientPing(t *testing.T) { now := time.Now() - ret, err := client.Ping(ctx) + ret, err := client.Ping(t.Context()) require.NoError(t, err) serverTime := time.Unix(0, ret.ServerTime) diff --git a/pkg/compose/convergence_test.go b/pkg/compose/convergence_test.go index 920587cd3..eb4c1adfb 100644 --- a/pkg/compose/convergence_test.go +++ b/pkg/compose/convergence_test.go @@ -17,7 +17,6 @@ package compose import ( - "context" "fmt" "strings" "testing" @@ -95,7 +94,7 @@ func TestServiceLinks(t *testing.T) { c := testContainer("db", dbContainerName, false) apiClient.EXPECT().ContainerList(gomock.Any(), containerListOptions).Return([]container.Summary{c}, nil) - links, err := tested.(*composeService).getLinks(context.Background(), testProject, s, 1) + links, err := tested.(*composeService).getLinks(t.Context(), testProject, s, 1) assert.NilError(t, err) assert.Equal(t, len(links), 3) @@ -118,7 +117,7 @@ func TestServiceLinks(t *testing.T) { c := testContainer("db", dbContainerName, false) apiClient.EXPECT().ContainerList(gomock.Any(), containerListOptions).Return([]container.Summary{c}, nil) - links, err := tested.(*composeService).getLinks(context.Background(), testProject, s, 1) + links, err := tested.(*composeService).getLinks(t.Context(), testProject, s, 1) assert.NilError(t, err) assert.Equal(t, len(links), 3) @@ -141,7 +140,7 @@ func TestServiceLinks(t *testing.T) { c := testContainer("db", dbContainerName, false) apiClient.EXPECT().ContainerList(gomock.Any(), containerListOptions).Return([]container.Summary{c}, nil) - links, err := tested.(*composeService).getLinks(context.Background(), testProject, s, 1) + links, err := tested.(*composeService).getLinks(t.Context(), testProject, s, 1) assert.NilError(t, err) assert.Equal(t, len(links), 3) @@ -165,7 +164,7 @@ func TestServiceLinks(t *testing.T) { c := testContainer("db", dbContainerName, false) apiClient.EXPECT().ContainerList(gomock.Any(), containerListOptions).Return([]container.Summary{c}, nil) - links, err := tested.(*composeService).getLinks(context.Background(), testProject, s, 1) + links, err := tested.(*composeService).getLinks(t.Context(), testProject, s, 1) assert.NilError(t, err) assert.Equal(t, len(links), 4) @@ -202,7 +201,7 @@ func TestServiceLinks(t *testing.T) { } apiClient.EXPECT().ContainerList(gomock.Any(), containerListOptionsOneOff).Return([]container.Summary{c}, nil) - links, err := tested.(*composeService).getLinks(context.Background(), testProject, s, 1) + links, err := tested.(*composeService).getLinks(t.Context(), testProject, s, 1) assert.NilError(t, err) assert.Equal(t, len(links), 3) @@ -233,7 +232,7 @@ func TestWaitDependencies(t *testing.T) { "db": {Condition: ServiceConditionRunningOrHealthy}, "redis": {Condition: ServiceConditionRunningOrHealthy}, } - assert.NilError(t, tested.(*composeService).waitDependencies(context.Background(), &project, "", dependencies, nil, 0)) + assert.NilError(t, tested.(*composeService).waitDependencies(t.Context(), &project, "", dependencies, nil, 0)) }) t.Run("should skip dependencies with condition service_started", func(t *testing.T) { dbService := types.ServiceConfig{Name: "db", Scale: intPtr(1)} @@ -246,7 +245,7 @@ func TestWaitDependencies(t *testing.T) { "db": {Condition: types.ServiceConditionStarted, Required: true}, "redis": {Condition: types.ServiceConditionStarted, Required: true}, } - assert.NilError(t, tested.(*composeService).waitDependencies(context.Background(), &project, "", dependencies, nil, 0)) + assert.NilError(t, tested.(*composeService).waitDependencies(t.Context(), &project, "", dependencies, nil, 0)) }) } @@ -260,7 +259,7 @@ func TestIsServiceHealthy(t *testing.T) { assert.NilError(t, err) cli.EXPECT().Client().Return(apiClient).AnyTimes() - ctx := context.Background() + ctx := t.Context() t.Run("disabled healthcheck with fallback to running", func(t *testing.T) { containerID := "test-container-id" @@ -475,7 +474,7 @@ func TestCreateMobyContainer(t *testing.T) { Aliases: []string{"bork-test-0"}, })) - _, err = tested.(*composeService).createMobyContainer(context.Background(), &project, service, "test", 0, nil, createOptions{ + _, err = tested.(*composeService).createMobyContainer(t.Context(), &project, service, "test", 0, nil, createOptions{ Labels: make(types.Labels), }) assert.NilError(t, err) @@ -561,7 +560,7 @@ func TestCreateMobyContainer(t *testing.T) { NetworkSettings: &container.NetworkSettings{}, }, nil) - _, err = tested.(*composeService).createMobyContainer(context.Background(), &project, service, "test", 0, nil, createOptions{ + _, err = tested.(*composeService).createMobyContainer(t.Context(), &project, service, "test", 0, nil, createOptions{ Labels: make(types.Labels), }) assert.NilError(t, err) diff --git a/pkg/compose/create_test.go b/pkg/compose/create_test.go index a3cc54069..41cd3bcb8 100644 --- a/pkg/compose/create_test.go +++ b/pkg/compose/create_test.go @@ -17,7 +17,6 @@ package compose import ( - "context" "os" "path/filepath" "sort" @@ -164,7 +163,7 @@ func TestBuildContainerMountOptions(t *testing.T) { } mock.EXPECT().ImageInspect(gomock.Any(), "myProject-myService").AnyTimes().Return(image.InspectResponse{}, nil) - mounts, err := s.buildContainerMountOptions(context.TODO(), project, project.Services["myService"], inherit) + mounts, err := s.buildContainerMountOptions(t.Context(), project, project.Services["myService"], inherit) sort.Slice(mounts, func(i, j int) bool { return mounts[i].Target < mounts[j].Target }) @@ -176,7 +175,7 @@ func TestBuildContainerMountOptions(t *testing.T) { assert.Equal(t, mounts[2].VolumeOptions.Subpath, "etc") assert.Equal(t, mounts[3].Target, "\\\\.\\pipe\\docker_engine") - mounts, err = s.buildContainerMountOptions(context.TODO(), project, project.Services["myService"], inherit) + mounts, err = s.buildContainerMountOptions(t.Context(), project, project.Services["myService"], inherit) sort.Slice(mounts, func(i, j int) bool { return mounts[i].Target < mounts[j].Target }) @@ -435,7 +434,7 @@ volumes: } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - p, err := composeloader.LoadWithContext(context.TODO(), composetypes.ConfigDetails{ + p, err := composeloader.LoadWithContext(t.Context(), composetypes.ConfigDetails{ ConfigFiles: []composetypes.ConfigFile{ { Filename: "test", @@ -448,7 +447,7 @@ volumes: }) assert.NilError(t, err) s := &composeService{} - binds, mounts, err := s.buildContainerVolumes(context.TODO(), *p, p.Services["test"], nil) + binds, mounts, err := s.buildContainerVolumes(t.Context(), *p, p.Services["test"], nil) assert.NilError(t, err) assert.DeepEqual(t, tt.binds, binds) assert.DeepEqual(t, tt.mounts, mounts) diff --git a/pkg/compose/dependencies_test.go b/pkg/compose/dependencies_test.go index 56e9298b5..b22b68b99 100644 --- a/pkg/compose/dependencies_test.go +++ b/pkg/compose/dependencies_test.go @@ -71,9 +71,6 @@ func TestTraversalWithMultipleParents(t *testing.T) { project.Services[name] = svc } - ctx, cancel := context.WithCancel(context.Background()) - t.Cleanup(cancel) - svc := make(chan string, 10) seen := make(map[string]int) done := make(chan struct{}) @@ -84,7 +81,7 @@ func TestTraversalWithMultipleParents(t *testing.T) { done <- struct{}{} }() - err := InDependencyOrder(ctx, &project, func(ctx context.Context, service string) error { + err := InDependencyOrder(t.Context(), &project, func(ctx context.Context, service string) error { svc <- service return nil }) @@ -99,11 +96,8 @@ func TestTraversalWithMultipleParents(t *testing.T) { } func TestInDependencyUpCommandOrder(t *testing.T) { - ctx, cancel := context.WithCancel(context.Background()) - t.Cleanup(cancel) - var order []string - err := InDependencyOrder(ctx, createTestProject(), func(ctx context.Context, service string) error { + err := InDependencyOrder(t.Context(), createTestProject(), func(ctx context.Context, service string) error { order = append(order, service) return nil }) @@ -112,11 +106,8 @@ func TestInDependencyUpCommandOrder(t *testing.T) { } func TestInDependencyReverseDownCommandOrder(t *testing.T) { - ctx, cancel := context.WithCancel(context.Background()) - t.Cleanup(cancel) - var order []string - err := InReverseDependencyOrder(ctx, createTestProject(), func(ctx context.Context, service string) error { + err := InReverseDependencyOrder(t.Context(), createTestProject(), func(ctx context.Context, service string) error { order = append(order, service) return nil }) @@ -429,7 +420,7 @@ func TestWith_RootNodesAndUp(t *testing.T) { return nil }) WithRootNodesAndDown(tt.nodes)(gt) - err := gt.visit(context.TODO(), graph) + err := gt.visit(t.Context(), graph) assert.NilError(t, err) sort.Strings(visited) assert.DeepEqual(t, tt.want, visited) diff --git a/pkg/compose/down_test.go b/pkg/compose/down_test.go index 896661750..0b5852a2f 100644 --- a/pkg/compose/down_test.go +++ b/pkg/compose/down_test.go @@ -17,7 +17,6 @@ package compose import ( - "context" "fmt" "os" "strings" @@ -90,7 +89,7 @@ func TestDown(t *testing.T) { api.EXPECT().NetworkRemove(gomock.Any(), "abc123").Return(nil) api.EXPECT().NetworkRemove(gomock.Any(), "def456").Return(nil) - err = tested.Down(context.Background(), strings.ToLower(testProject), compose.DownOptions{}) + err = tested.Down(t.Context(), strings.ToLower(testProject), compose.DownOptions{}) assert.NilError(t, err) } @@ -139,7 +138,7 @@ func TestDownWithGivenServices(t *testing.T) { api.EXPECT().NetworkInspect(gomock.Any(), "abc123", gomock.Any()).Return(network.Inspect{ID: "abc123"}, nil) api.EXPECT().NetworkRemove(gomock.Any(), "abc123").Return(nil) - err = tested.Down(context.Background(), strings.ToLower(testProject), compose.DownOptions{ + err = tested.Down(t.Context(), strings.ToLower(testProject), compose.DownOptions{ Services: []string{"service1", "not-running-service"}, }) assert.NilError(t, err) @@ -175,7 +174,7 @@ func TestDownWithSpecifiedServiceButTheServicesAreNotRunning(t *testing.T) { {ID: "def456", Name: "myProject_default", Labels: map[string]string{compose.NetworkLabel: "default"}}, }, nil) - err = tested.Down(context.Background(), strings.ToLower(testProject), compose.DownOptions{ + err = tested.Down(t.Context(), strings.ToLower(testProject), compose.DownOptions{ Services: []string{"not-running-service1", "not-running-service2"}, }) assert.NilError(t, err) @@ -227,7 +226,7 @@ func TestDownRemoveOrphans(t *testing.T) { api.EXPECT().NetworkInspect(gomock.Any(), "abc123", gomock.Any()).Return(network.Inspect{ID: "abc123"}, nil) api.EXPECT().NetworkRemove(gomock.Any(), "abc123").Return(nil) - err = tested.Down(context.Background(), strings.ToLower(testProject), compose.DownOptions{RemoveOrphans: true}) + err = tested.Down(t.Context(), strings.ToLower(testProject), compose.DownOptions{RemoveOrphans: true}) assert.NilError(t, err) } @@ -259,7 +258,7 @@ func TestDownRemoveVolumes(t *testing.T) { api.EXPECT().VolumeRemove(gomock.Any(), "myProject_volume", true).Return(nil) - err = tested.Down(context.Background(), strings.ToLower(testProject), compose.DownOptions{Volumes: true}) + err = tested.Down(t.Context(), strings.ToLower(testProject), compose.DownOptions{Volumes: true}) assert.NilError(t, err) } @@ -346,7 +345,7 @@ func TestDownRemoveImages(t *testing.T) { t.Log("-> docker compose down --rmi=local") opts.Images = "local" - err = tested.Down(context.Background(), strings.ToLower(testProject), opts) + err = tested.Down(t.Context(), strings.ToLower(testProject), opts) assert.NilError(t, err) otherImagesToBeRemoved := []string{ @@ -361,7 +360,7 @@ func TestDownRemoveImages(t *testing.T) { t.Log("-> docker compose down --rmi=all") opts.Images = "all" - err = tested.Down(context.Background(), strings.ToLower(testProject), opts) + err = tested.Down(t.Context(), strings.ToLower(testProject), opts) assert.NilError(t, err) } @@ -406,7 +405,7 @@ func TestDownRemoveImages_NoLabel(t *testing.T) { api.EXPECT().ImageRemove(gomock.Any(), "testproject-service1:latest", image.RemoveOptions{}).Return(nil, nil) - err = tested.Down(context.Background(), strings.ToLower(testProject), compose.DownOptions{Images: "local"}) + err = tested.Down(t.Context(), strings.ToLower(testProject), compose.DownOptions{Images: "local"}) assert.NilError(t, err) } diff --git a/pkg/compose/images_test.go b/pkg/compose/images_test.go index 9c0367d8d..b6eb9cce1 100644 --- a/pkg/compose/images_test.go +++ b/pkg/compose/images_test.go @@ -17,7 +17,6 @@ package compose import ( - "context" "strings" "testing" "time" @@ -40,7 +39,6 @@ func TestImages(t *testing.T) { tested, err := NewComposeService(cli) assert.NilError(t, err) - ctx := context.Background() args := filters.NewArgs(projectFilter(strings.ToLower(testProject))) listOpts := container.ListOptions{All: true, Filters: args} api.EXPECT().ServerVersion(gomock.Any()).Return(types.Version{APIVersion: "1.96"}, nil).AnyTimes() @@ -56,9 +54,9 @@ func TestImages(t *testing.T) { c2 := containerDetail("service1", "456", "running", "bar:2") c2.Ports = []container.Port{{PublicPort: 80, PrivatePort: 90, IP: "localhost"}} c3 := containerDetail("service2", "789", "exited", "foo:1") - api.EXPECT().ContainerList(ctx, listOpts).Return([]container.Summary{c1, c2, c3}, nil) + api.EXPECT().ContainerList(t.Context(), listOpts).Return([]container.Summary{c1, c2, c3}, nil) - images, err := tested.Images(ctx, strings.ToLower(testProject), compose.ImagesOptions{}) + images, err := tested.Images(t.Context(), strings.ToLower(testProject), compose.ImagesOptions{}) expected := map[string]compose.ImageSummary{ "123": { diff --git a/pkg/compose/kill_test.go b/pkg/compose/kill_test.go index b25dc48e6..a70228a65 100644 --- a/pkg/compose/kill_test.go +++ b/pkg/compose/kill_test.go @@ -45,8 +45,7 @@ func TestKillAll(t *testing.T) { name := strings.ToLower(testProject) - ctx := context.Background() - api.EXPECT().ContainerList(ctx, container.ListOptions{ + api.EXPECT().ContainerList(t.Context(), container.ListOptions{ Filters: filters.NewArgs(projectFilter(name), hasConfigHashLabel()), }).Return( []container.Summary{testContainer("service1", "123", false), testContainer("service1", "456", false), testContainer("service2", "789", false)}, nil) @@ -64,7 +63,7 @@ func TestKillAll(t *testing.T) { api.EXPECT().ContainerKill(anyCancellableContext(), "456", "").Return(nil) api.EXPECT().ContainerKill(anyCancellableContext(), "789", "").Return(nil) - err = tested.Kill(ctx, name, compose.KillOptions{}) + err = tested.Kill(t.Context(), name, compose.KillOptions{}) assert.NilError(t, err) } @@ -82,8 +81,7 @@ func TestKillSignal(t *testing.T) { Filters: filters.NewArgs(projectFilter(name), serviceFilter(serviceName), hasConfigHashLabel()), } - ctx := context.Background() - api.EXPECT().ContainerList(ctx, listOptions).Return([]container.Summary{testContainer(serviceName, "123", false)}, nil) + api.EXPECT().ContainerList(t.Context(), listOptions).Return([]container.Summary{testContainer(serviceName, "123", false)}, nil) api.EXPECT().VolumeList( gomock.Any(), volume.ListOptions{ @@ -96,7 +94,7 @@ func TestKillSignal(t *testing.T) { }, nil) api.EXPECT().ContainerKill(anyCancellableContext(), "123", "SIGTERM").Return(nil) - err = tested.Kill(ctx, name, compose.KillOptions{Services: []string{serviceName}, Signal: "SIGTERM"}) + err = tested.Kill(t.Context(), name, compose.KillOptions{Services: []string{serviceName}, Signal: "SIGTERM"}) assert.NilError(t, err) } diff --git a/pkg/compose/logs_test.go b/pkg/compose/logs_test.go index d2292a753..b5823c908 100644 --- a/pkg/compose/logs_test.go +++ b/pkg/compose/logs_test.go @@ -17,7 +17,6 @@ package compose import ( - "context" "io" "strings" "sync" @@ -44,8 +43,7 @@ func TestComposeService_Logs_Demux(t *testing.T) { name := strings.ToLower(testProject) - ctx := context.Background() - api.EXPECT().ContainerList(ctx, containerType.ListOptions{ + api.EXPECT().ContainerList(t.Context(), containerType.ListOptions{ All: true, Filters: filters.NewArgs(oneOffFilter(false), projectFilter(name), hasConfigHashLabel()), }).Return( @@ -87,7 +85,7 @@ func TestComposeService_Logs_Demux(t *testing.T) { } consumer := &testLogConsumer{} - err = tested.Logs(ctx, name, consumer, opts) + err = tested.Logs(t.Context(), name, consumer, opts) require.NoError(t, err) require.Equal( @@ -114,8 +112,7 @@ func TestComposeService_Logs_ServiceFiltering(t *testing.T) { name := strings.ToLower(testProject) - ctx := context.Background() - api.EXPECT().ContainerList(ctx, containerType.ListOptions{ + api.EXPECT().ContainerList(t.Context(), containerType.ListOptions{ All: true, Filters: filters.NewArgs(oneOffFilter(false), projectFilter(name), hasConfigHashLabel()), }).Return( @@ -157,7 +154,7 @@ func TestComposeService_Logs_ServiceFiltering(t *testing.T) { opts := compose.LogOptions{ Project: proj, } - err = tested.Logs(ctx, name, consumer, opts) + err = tested.Logs(t.Context(), name, consumer, opts) require.NoError(t, err) require.Equal(t, []string{"hello c1"}, consumer.LogsForContainer("c1")) diff --git a/pkg/compose/ps_test.go b/pkg/compose/ps_test.go index c76bfdfd2..b006d2f57 100644 --- a/pkg/compose/ps_test.go +++ b/pkg/compose/ps_test.go @@ -17,7 +17,6 @@ package compose import ( - "context" "strings" "testing" @@ -37,7 +36,6 @@ func TestPs(t *testing.T) { tested, err := NewComposeService(cli) assert.NilError(t, err) - ctx := context.Background() args := filters.NewArgs(projectFilter(strings.ToLower(testProject)), hasConfigHashLabel()) args.Add("label", "com.docker.compose.oneoff=False") listOpts := containerType.ListOptions{Filters: args, All: false} @@ -45,12 +43,12 @@ func TestPs(t *testing.T) { c2, inspect2 := containerDetails("service1", "456", containerType.StateRunning, "", 0) c2.Ports = []containerType.Port{{PublicPort: 80, PrivatePort: 90, IP: "localhost"}} c3, inspect3 := containerDetails("service2", "789", containerType.StateExited, "", 130) - api.EXPECT().ContainerList(ctx, listOpts).Return([]containerType.Summary{c1, c2, c3}, nil) + api.EXPECT().ContainerList(t.Context(), listOpts).Return([]containerType.Summary{c1, c2, c3}, nil) api.EXPECT().ContainerInspect(anyCancellableContext(), "123").Return(inspect1, nil) api.EXPECT().ContainerInspect(anyCancellableContext(), "456").Return(inspect2, nil) api.EXPECT().ContainerInspect(anyCancellableContext(), "789").Return(inspect3, nil) - containers, err := tested.Ps(ctx, strings.ToLower(testProject), compose.PsOptions{}) + containers, err := tested.Ps(t.Context(), strings.ToLower(testProject), compose.PsOptions{}) expected := []compose.ContainerSummary{ { diff --git a/pkg/compose/publish_test.go b/pkg/compose/publish_test.go index 52398af77..8f91f663e 100644 --- a/pkg/compose/publish_test.go +++ b/pkg/compose/publish_test.go @@ -17,7 +17,6 @@ package compose import ( - "context" "slices" "testing" @@ -32,7 +31,7 @@ import ( ) func Test_createLayers(t *testing.T) { - project, err := loader.LoadWithContext(context.TODO(), types.ConfigDetails{ + project, err := loader.LoadWithContext(t.Context(), types.ConfigDetails{ WorkingDir: "testdata/publish/", Environment: types.Mapping{}, ConfigFiles: []types.ConfigFile{ @@ -45,7 +44,7 @@ func Test_createLayers(t *testing.T) { project.ComposeFiles = []string{"testdata/publish/compose.yaml"} service := &composeService{} - layers, err := service.createLayers(context.TODO(), project, api.PublishOptions{ + layers, err := service.createLayers(t.Context(), project, api.PublishOptions{ WithEnvironment: true, }) assert.NilError(t, err) diff --git a/pkg/compose/stop_test.go b/pkg/compose/stop_test.go index 2508be06b..adecd1d61 100644 --- a/pkg/compose/stop_test.go +++ b/pkg/compose/stop_test.go @@ -17,7 +17,6 @@ package compose import ( - "context" "strings" "testing" "time" @@ -41,7 +40,6 @@ func TestStopTimeout(t *testing.T) { tested, err := NewComposeService(cli) assert.NilError(t, err) - ctx := context.Background() api.EXPECT().ContainerList(gomock.Any(), projectFilterListOpt(false)).Return( []container.Summary{ testContainer("service1", "123", false), @@ -63,7 +61,7 @@ func TestStopTimeout(t *testing.T) { api.EXPECT().ContainerStop(gomock.Any(), "456", stopConfig).Return(nil) api.EXPECT().ContainerStop(gomock.Any(), "789", stopConfig).Return(nil) - err = tested.Stop(ctx, strings.ToLower(testProject), compose.StopOptions{ + err = tested.Stop(t.Context(), strings.ToLower(testProject), compose.StopOptions{ Timeout: &timeout, }) assert.NilError(t, err) diff --git a/pkg/compose/viz_test.go b/pkg/compose/viz_test.go index ae66de34f..dad8bac36 100644 --- a/pkg/compose/viz_test.go +++ b/pkg/compose/viz_test.go @@ -17,7 +17,6 @@ package compose import ( - "context" "strconv" "testing" @@ -119,10 +118,8 @@ func TestViz(t *testing.T) { tested, err := NewComposeService(cli) require.NoError(t, err) - ctx := context.Background() - t.Run("viz (no ports, networks or image)", func(t *testing.T) { - graphStr, err := tested.Viz(ctx, &project, compose.VizOptions{ + graphStr, err := tested.Viz(t.Context(), &project, compose.VizOptions{ Indentation: " ", IncludePorts: false, IncludeImageName: false, @@ -181,7 +178,7 @@ func TestViz(t *testing.T) { }) t.Run("viz (with ports, networks and image)", func(t *testing.T) { - graphStr, err := tested.Viz(ctx, &project, compose.VizOptions{ + graphStr, err := tested.Viz(t.Context(), &project, compose.VizOptions{ Indentation: "\t", IncludePorts: true, IncludeImageName: true, diff --git a/pkg/compose/volumes_test.go b/pkg/compose/volumes_test.go index 1fb99297a..85a838eae 100644 --- a/pkg/compose/volumes_test.go +++ b/pkg/compose/volumes_test.go @@ -17,7 +17,6 @@ package compose import ( - "context" "testing" "github.com/docker/docker/api/types/container" @@ -58,7 +57,6 @@ func TestVolumes(t *testing.T) { }, } - ctx := context.Background() args := filters.NewArgs(projectFilter(testProject)) listOpts := container.ListOptions{Filters: args} volumeListArgs := filters.NewArgs(projectFilter(testProject)) @@ -68,20 +66,19 @@ func TestVolumes(t *testing.T) { } containerReturn := []container.Summary{c1, c2} - // Mock API calls - mockApi.EXPECT().ContainerList(ctx, listOpts).Times(2).Return(containerReturn, nil) - mockApi.EXPECT().VolumeList(ctx, volumeListOpts).Times(2).Return(volumeReturn, nil) + mockApi.EXPECT().ContainerList(t.Context(), listOpts).Times(2).Return(containerReturn, nil) + mockApi.EXPECT().VolumeList(t.Context(), volumeListOpts).Times(2).Return(volumeReturn, nil) // Test without service filter - should return all project volumes volumeOptions := api.VolumesOptions{} - volumes, err := tested.Volumes(ctx, testProject, volumeOptions) + volumes, err := tested.Volumes(t.Context(), testProject, volumeOptions) expected := []api.VolumesSummary{vol1, vol2, vol3} assert.NilError(t, err) assert.DeepEqual(t, volumes, expected) // Test with service filter - should only return volumes used by service1 volumeOptions = api.VolumesOptions{Services: []string{"service1"}} - volumes, err = tested.Volumes(ctx, testProject, volumeOptions) + volumes, err = tested.Volumes(t.Context(), testProject, volumeOptions) expected = []api.VolumesSummary{vol1, vol2} assert.NilError(t, err) assert.DeepEqual(t, volumes, expected) diff --git a/pkg/compose/watch_test.go b/pkg/compose/watch_test.go index 560784cd5..956ca4e27 100644 --- a/pkg/compose/watch_test.go +++ b/pkg/compose/watch_test.go @@ -95,7 +95,7 @@ func TestWatch_Sync(t *testing.T) { // cli.EXPECT().Client().Return(apiClient).AnyTimes() - ctx, cancelFunc := context.WithCancel(context.Background()) + ctx, cancelFunc := context.WithCancel(t.Context()) t.Cleanup(cancelFunc) proj := types.Project{ diff --git a/pkg/e2e/cancel_test.go b/pkg/e2e/cancel_test.go index d3c64155d..64f3ff609 100644 --- a/pkg/e2e/cancel_test.go +++ b/pkg/e2e/cancel_test.go @@ -39,7 +39,7 @@ func TestComposeCancel(t *testing.T) { t.Run("metrics on cancel Compose build", func(t *testing.T) { const buildProjectPath = "fixtures/build-infinite/compose.yaml" - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(t.Context()) defer cancel() // require a separate groupID from the process running tests, in order to simulate ctrl+C from a terminal. diff --git a/pkg/e2e/up_test.go b/pkg/e2e/up_test.go index b7011391c..d34f2061e 100644 --- a/pkg/e2e/up_test.go +++ b/pkg/e2e/up_test.go @@ -75,7 +75,7 @@ func TestUpDependenciesNotStopped(t *testing.T) { "app", ) - ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second) + ctx, cancel := context.WithTimeout(t.Context(), 15*time.Second) t.Cleanup(cancel) cmd, err := StartWithNewGroupID(ctx, testCmd, upOut, nil) diff --git a/pkg/watch/debounce_test.go b/pkg/watch/debounce_test.go index fd1c40bbf..39029f845 100644 --- a/pkg/watch/debounce_test.go +++ b/pkg/watch/debounce_test.go @@ -27,7 +27,7 @@ import ( func Test_BatchDebounceEvents(t *testing.T) { ch := make(chan FileEvent) clock := clockwork.NewFakeClock() - ctx, stop := context.WithCancel(context.Background()) + ctx, stop := context.WithCancel(t.Context()) t.Cleanup(stop) eventBatchCh := BatchDebounceEvents(ctx, clock, ch) diff --git a/pkg/watch/notify_test.go b/pkg/watch/notify_test.go index 9b68c4d05..15a4f5913 100644 --- a/pkg/watch/notify_test.go +++ b/pkg/watch/notify_test.go @@ -501,7 +501,7 @@ type notifyFixture struct { func newNotifyFixture(t *testing.T) *notifyFixture { out := bytes.NewBuffer(nil) - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithCancel(t.Context()) nf := ¬ifyFixture{ ctx: ctx, cancel: cancel,