|
@@ -22,7 +22,6 @@ import (
|
|
|
"strings"
|
|
|
"testing"
|
|
|
|
|
|
- "github.com/compose-spec/compose-go/types"
|
|
|
moby "github.com/docker/docker/api/types"
|
|
|
"github.com/docker/docker/api/types/filters"
|
|
|
"github.com/golang/mock/gomock"
|
|
@@ -45,18 +44,18 @@ func TestKillAll(t *testing.T) {
|
|
|
tested.dockerCli = cli
|
|
|
cli.EXPECT().Client().Return(api).AnyTimes()
|
|
|
|
|
|
- project := types.Project{Name: strings.ToLower(testProject), Services: []types.ServiceConfig{testService("service1"), testService("service2")}}
|
|
|
+ name := strings.ToLower(testProject)
|
|
|
|
|
|
ctx := context.Background()
|
|
|
api.EXPECT().ContainerList(ctx, moby.ContainerListOptions{
|
|
|
- Filters: filters.NewArgs(projectFilter(strings.ToLower(testProject))),
|
|
|
+ Filters: filters.NewArgs(projectFilter(name)),
|
|
|
}).Return(
|
|
|
[]moby.Container{testContainer("service1", "123", false), testContainer("service1", "456", false), testContainer("service2", "789", false)}, nil)
|
|
|
api.EXPECT().ContainerKill(anyCancellableContext(), "123", "").Return(nil)
|
|
|
api.EXPECT().ContainerKill(anyCancellableContext(), "456", "").Return(nil)
|
|
|
api.EXPECT().ContainerKill(anyCancellableContext(), "789", "").Return(nil)
|
|
|
|
|
|
- err := tested.kill(ctx, &project, compose.KillOptions{})
|
|
|
+ err := tested.kill(ctx, name, compose.KillOptions{})
|
|
|
assert.NilError(t, err)
|
|
|
}
|
|
|
|
|
@@ -70,23 +69,19 @@ func TestKillSignal(t *testing.T) {
|
|
|
tested.dockerCli = cli
|
|
|
cli.EXPECT().Client().Return(api).AnyTimes()
|
|
|
|
|
|
- project := types.Project{Name: strings.ToLower(testProject), Services: []types.ServiceConfig{testService(serviceName)}}
|
|
|
+ name := strings.ToLower(testProject)
|
|
|
listOptions := moby.ContainerListOptions{
|
|
|
- Filters: filters.NewArgs(projectFilter(strings.ToLower(testProject)), serviceFilter(serviceName)),
|
|
|
+ Filters: filters.NewArgs(projectFilter(name), serviceFilter(serviceName)),
|
|
|
}
|
|
|
|
|
|
ctx := context.Background()
|
|
|
api.EXPECT().ContainerList(ctx, listOptions).Return([]moby.Container{testContainer(serviceName, "123", false)}, nil)
|
|
|
api.EXPECT().ContainerKill(anyCancellableContext(), "123", "SIGTERM").Return(nil)
|
|
|
|
|
|
- err := tested.kill(ctx, &project, compose.KillOptions{Services: []string{serviceName}, Signal: "SIGTERM"})
|
|
|
+ err := tested.kill(ctx, name, compose.KillOptions{Services: []string{serviceName}, Signal: "SIGTERM"})
|
|
|
assert.NilError(t, err)
|
|
|
}
|
|
|
|
|
|
-func testService(name string) types.ServiceConfig {
|
|
|
- return types.ServiceConfig{Name: name}
|
|
|
-}
|
|
|
-
|
|
|
func testContainer(service string, id string, oneOff bool) moby.Container {
|
|
|
return moby.Container{
|
|
|
ID: id,
|