Skip to content

Commit 0b8fa46

Browse files
authored
Merge pull request moby#51369 from dohrisalim/issue#50159
integration-cli: migrate TestAPIStatsContainerNotFound to integration tests
2 parents ada6104 + 9b749d7 commit 0b8fa46

File tree

2 files changed

+33
-22
lines changed

2 files changed

+33
-22
lines changed

integration-cli/docker_api_stats_test.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ import (
1313
"testing"
1414
"time"
1515

16-
cerrdefs "github.com/containerd/errdefs"
1716
"github.com/moby/moby/api/types/container"
1817
"github.com/moby/moby/api/types/system"
19-
"github.com/moby/moby/client"
2018
"github.com/moby/moby/v2/integration-cli/cli"
2119
"github.com/moby/moby/v2/internal/testutil"
2220
"github.com/moby/moby/v2/internal/testutil/request"
@@ -178,26 +176,6 @@ func getNetworkStats(t *testing.T, id string) map[string]container.NetworkStats
178176
return st.Networks
179177
}
180178

181-
func (s *DockerAPISuite) TestAPIStatsContainerNotFound(c *testing.T) {
182-
testRequires(c, DaemonIsLinux)
183-
apiClient, err := client.New(client.FromEnv)
184-
assert.NilError(c, err)
185-
defer func() { _ = apiClient.Close() }()
186-
187-
_, err = apiClient.ContainerStats(testutil.GetContext(c), "no-such-container", client.ContainerStatsOptions{
188-
Stream: true,
189-
})
190-
assert.ErrorType(c, err, cerrdefs.IsNotFound)
191-
assert.ErrorContains(c, err, "no-such-container")
192-
193-
_, err = apiClient.ContainerStats(testutil.GetContext(c), "no-such-container", client.ContainerStatsOptions{
194-
Stream: false,
195-
IncludePreviousSample: true,
196-
})
197-
assert.ErrorType(c, err, cerrdefs.IsNotFound)
198-
assert.ErrorContains(c, err, "no-such-container")
199-
}
200-
201179
func (s *DockerAPISuite) TestAPIStatsNoStreamConnectedContainers(c *testing.T) {
202180
testRequires(c, DaemonIsLinux)
203181

integration/container/stats_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"reflect"
77
"testing"
88

9+
cerrdefs "github.com/containerd/errdefs"
910
containertypes "github.com/moby/moby/api/types/container"
1011
"github.com/moby/moby/client"
1112
"github.com/moby/moby/v2/integration/internal/container"
@@ -60,3 +61,35 @@ func TestStats(t *testing.T) {
6061
assert.Assert(t, is.ErrorIs(err, io.EOF))
6162
})
6263
}
64+
65+
func TestStatsContainerNotFound(t *testing.T) {
66+
ctx := setupTest(t)
67+
apiClient := testEnv.APIClient()
68+
69+
tests := []struct {
70+
name string
71+
options client.ContainerStatsOptions
72+
}{
73+
{
74+
name: "with stream",
75+
options: client.ContainerStatsOptions{
76+
Stream: true,
77+
},
78+
},
79+
{
80+
name: "without stream",
81+
options: client.ContainerStatsOptions{
82+
Stream: false,
83+
IncludePreviousSample: true,
84+
},
85+
},
86+
}
87+
88+
for _, tc := range tests {
89+
t.Run(tc.name, func(t *testing.T) {
90+
_, err := apiClient.ContainerStats(ctx, "no-such-container", tc.options)
91+
assert.ErrorType(t, err, cerrdefs.IsNotFound)
92+
assert.ErrorContains(t, err, "no-such-container")
93+
})
94+
}
95+
}

0 commit comments

Comments
 (0)