MCPcopy
hub / github.com/docker/compose / TestKillSignal

Function TestKillSignal

pkg/compose/kill_test.go:75–110  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

73}
74
75func TestKillSignal(t *testing.T) {
76 const serviceName = "service1"
77 mockCtrl := gomock.NewController(t)
78 defer mockCtrl.Finish()
79
80 api, cli := prepareMocks(mockCtrl)
81 tested, err := NewComposeService(cli)
82 assert.NilError(t, err)
83
84 name := strings.ToLower(testProject)
85 listOptions := client.ContainerListOptions{
86 Filters: projectFilter(name).Add("label", serviceFilter(serviceName), compose.ConfigHashLabel),
87 }
88
89 api.EXPECT().ContainerList(t.Context(), listOptions).Return(client.ContainerListResult{
90 Items: []container.Summary{testContainer(serviceName, "123", false)},
91 }, nil)
92 api.EXPECT().VolumeList(
93 gomock.Any(),
94 client.VolumeListOptions{
95 Filters: projectFilter(strings.ToLower(testProject)),
96 }).
97 Return(client.VolumeListResult{}, nil)
98 api.EXPECT().NetworkList(gomock.Any(), client.NetworkListOptions{Filters: projectFilter(strings.ToLower(testProject))}).
99 Return(client.NetworkListResult{
100 Items: []network.Summary{{
101 Network: network.Network{ID: "abc123", Name: "testProject_default"},
102 }},
103 }, nil)
104 api.EXPECT().ContainerKill(anyCancellableContext(), "123", client.ContainerKillOptions{
105 Signal: "SIGTERM",
106 }).Return(client.ContainerKillResult{}, nil)
107
108 err = tested.Kill(t.Context(), name, compose.KillOptions{Services: []string{serviceName}, Signal: "SIGTERM"})
109 assert.NilError(t, err)
110}
111
112func testContainer(service string, id string, oneOff bool) container.Summary {
113 // canonical docker names in the API start with a leading slash, some

Callers

nothing calls this directly

Calls 13

prepareMocksFunction · 0.85
NewComposeServiceFunction · 0.85
projectFilterFunction · 0.85
serviceFilterFunction · 0.85
testContainerFunction · 0.85
anyCancellableContextFunction · 0.85
KillMethod · 0.65
AddMethod · 0.45
ContainerListMethod · 0.45
EXPECTMethod · 0.45
VolumeListMethod · 0.45
NetworkListMethod · 0.45

Tested by

no test coverage detected