(t *testing.T)
| 29 | ) |
| 30 | |
| 31 | func TestVolumes(t *testing.T) { |
| 32 | mockCtrl := gomock.NewController(t) |
| 33 | defer mockCtrl.Finish() |
| 34 | |
| 35 | mockApi, mockCli := prepareMocks(mockCtrl) |
| 36 | tested := composeService{ |
| 37 | dockerCli: mockCli, |
| 38 | } |
| 39 | |
| 40 | // Create test volumes |
| 41 | vol1 := volume.Volume{Name: testProject + "_vol1"} |
| 42 | vol2 := volume.Volume{Name: testProject + "_vol2"} |
| 43 | vol3 := volume.Volume{Name: testProject + "_vol3"} |
| 44 | |
| 45 | // Create test containers with volume mounts |
| 46 | c1 := container.Summary{ |
| 47 | Labels: map[string]string{api.ServiceLabel: "service1"}, |
| 48 | Mounts: []container.MountPoint{ |
| 49 | {Name: testProject + "_vol1"}, |
| 50 | {Name: testProject + "_vol2"}, |
| 51 | }, |
| 52 | } |
| 53 | c2 := container.Summary{ |
| 54 | Labels: map[string]string{api.ServiceLabel: "service2"}, |
| 55 | Mounts: []container.MountPoint{ |
| 56 | {Name: testProject + "_vol3"}, |
| 57 | }, |
| 58 | } |
| 59 | |
| 60 | listOpts := client.ContainerListOptions{Filters: projectFilter(testProject)} |
| 61 | volumeListOpts := client.VolumeListOptions{Filters: projectFilter(testProject)} |
| 62 | volumeReturn := client.VolumeListResult{ |
| 63 | Items: []volume.Volume{vol1, vol2, vol3}, |
| 64 | } |
| 65 | containerReturn := client.ContainerListResult{ |
| 66 | Items: []container.Summary{c1, c2}, |
| 67 | } |
| 68 | |
| 69 | mockApi.EXPECT().ContainerList(t.Context(), listOpts).Times(2).Return(containerReturn, nil) |
| 70 | mockApi.EXPECT().VolumeList(t.Context(), volumeListOpts).Times(2).Return(volumeReturn, nil) |
| 71 | |
| 72 | // Test without service filter - should return all project volumes |
| 73 | volumes, err := tested.Volumes(t.Context(), testProject, api.VolumesOptions{}) |
| 74 | expected := []api.VolumesSummary{vol1, vol2, vol3} |
| 75 | assert.NilError(t, err) |
| 76 | assert.DeepEqual(t, volumes, expected) |
| 77 | |
| 78 | // Test with service filter - should only return volumes used by service1 |
| 79 | volumes, err = tested.Volumes(t.Context(), testProject, api.VolumesOptions{Services: []string{"service1"}}) |
| 80 | expected = []api.VolumesSummary{vol1, vol2} |
| 81 | assert.NilError(t, err) |
| 82 | assert.DeepEqual(t, volumes, expected) |
| 83 | } |
nothing calls this directly
no test coverage detected