|
|
@@ -20,12 +20,12 @@ import (
|
|
|
"context"
|
|
|
"testing"
|
|
|
|
|
|
- "github.com/docker/docker/api/types/filters"
|
|
|
-
|
|
|
"github.com/docker/compose-cli/api/compose"
|
|
|
"github.com/docker/compose-cli/local/mocks"
|
|
|
|
|
|
apitypes "github.com/docker/docker/api/types"
|
|
|
+ "github.com/docker/docker/api/types/filters"
|
|
|
+ "github.com/docker/docker/api/types/volume"
|
|
|
"github.com/golang/mock/gomock"
|
|
|
"gotest.tools/v3/assert"
|
|
|
)
|
|
|
@@ -79,3 +79,24 @@ func TestDownRemoveOrphans(t *testing.T) {
|
|
|
err := tested.Down(context.Background(), testProject, compose.DownOptions{RemoveOrphans: true})
|
|
|
assert.NilError(t, err)
|
|
|
}
|
|
|
+
|
|
|
+func TestDownRemoveVolumes(t *testing.T) {
|
|
|
+ mockCtrl := gomock.NewController(t)
|
|
|
+ defer mockCtrl.Finish()
|
|
|
+ api := mocks.NewMockAPIClient(mockCtrl)
|
|
|
+ tested.apiClient = api
|
|
|
+
|
|
|
+ api.EXPECT().ContainerList(gomock.Any(), projectFilterListOpt()).Return(
|
|
|
+ []apitypes.Container{testContainer("service1", "123")}, nil)
|
|
|
+
|
|
|
+ api.EXPECT().ContainerStop(gomock.Any(), "123", nil).Return(nil)
|
|
|
+ api.EXPECT().ContainerRemove(gomock.Any(), "123", apitypes.ContainerRemoveOptions{Force: true}).Return(nil)
|
|
|
+
|
|
|
+ api.EXPECT().NetworkList(gomock.Any(), apitypes.NetworkListOptions{Filters: filters.NewArgs(projectFilter(testProject))}).Return(nil, nil)
|
|
|
+
|
|
|
+ api.EXPECT().VolumeList(gomock.Any(), filters.NewArgs(projectFilter(testProject))).Return(volume.VolumeListOKBody{Volumes: []*apitypes.Volume{{Name: "myProject_volume"}}}, nil)
|
|
|
+ api.EXPECT().VolumeRemove(gomock.Any(), "myProject_volume", true).Return(nil)
|
|
|
+
|
|
|
+ err := tested.Down(context.Background(), testProject, compose.DownOptions{Volumes: true})
|
|
|
+ assert.NilError(t, err)
|
|
|
+}
|