mirror of
https://github.com/moby/moby.git
synced 2026-01-11 02:31:44 +00:00
integration-cli: migrate TestAPIStatsContainerNotFound to integration tests
Migrate TestAPIStatsContainerNotFound from the deprecated integration-cli test suite to the modern integration test framework in integration/container. The test verifies that the container stats API returns a NotFound error for non-existent containers, testing both streaming and non-streaming modes. Changes made: - Migrated test to integration/container/stats_test.go using standard Go testing patterns - Refactored to use test array pattern for better test organization - Removed test from integration-cli/docker_api_stats_test.go - Removed unused imports from integration-cli file - Removed Windows skip as it may not be necessary Signed-off-by: Salim Dohri <dohri.salim@gmail.com>
This commit is contained in:
@@ -13,10 +13,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
cerrdefs "github.com/containerd/errdefs"
|
||||
"github.com/moby/moby/api/types/container"
|
||||
"github.com/moby/moby/api/types/system"
|
||||
"github.com/moby/moby/client"
|
||||
"github.com/moby/moby/v2/integration-cli/cli"
|
||||
"github.com/moby/moby/v2/internal/testutil"
|
||||
"github.com/moby/moby/v2/internal/testutil/request"
|
||||
@@ -178,26 +176,6 @@ func getNetworkStats(t *testing.T, id string) map[string]container.NetworkStats
|
||||
return st.Networks
|
||||
}
|
||||
|
||||
func (s *DockerAPISuite) TestAPIStatsContainerNotFound(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
apiClient, err := client.New(client.FromEnv)
|
||||
assert.NilError(c, err)
|
||||
defer func() { _ = apiClient.Close() }()
|
||||
|
||||
_, err = apiClient.ContainerStats(testutil.GetContext(c), "no-such-container", client.ContainerStatsOptions{
|
||||
Stream: true,
|
||||
})
|
||||
assert.ErrorType(c, err, cerrdefs.IsNotFound)
|
||||
assert.ErrorContains(c, err, "no-such-container")
|
||||
|
||||
_, err = apiClient.ContainerStats(testutil.GetContext(c), "no-such-container", client.ContainerStatsOptions{
|
||||
Stream: false,
|
||||
IncludePreviousSample: true,
|
||||
})
|
||||
assert.ErrorType(c, err, cerrdefs.IsNotFound)
|
||||
assert.ErrorContains(c, err, "no-such-container")
|
||||
}
|
||||
|
||||
func (s *DockerAPISuite) TestAPIStatsNoStreamConnectedContainers(c *testing.T) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
cerrdefs "github.com/containerd/errdefs"
|
||||
containertypes "github.com/moby/moby/api/types/container"
|
||||
"github.com/moby/moby/client"
|
||||
"github.com/moby/moby/v2/integration/internal/container"
|
||||
@@ -60,3 +61,35 @@ func TestStats(t *testing.T) {
|
||||
assert.Assert(t, is.ErrorIs(err, io.EOF))
|
||||
})
|
||||
}
|
||||
|
||||
func TestStatsContainerNotFound(t *testing.T) {
|
||||
ctx := setupTest(t)
|
||||
apiClient := testEnv.APIClient()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
options client.ContainerStatsOptions
|
||||
}{
|
||||
{
|
||||
name: "with stream",
|
||||
options: client.ContainerStatsOptions{
|
||||
Stream: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "without stream",
|
||||
options: client.ContainerStatsOptions{
|
||||
Stream: false,
|
||||
IncludePreviousSample: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
_, err := apiClient.ContainerStats(ctx, "no-such-container", tc.options)
|
||||
assert.ErrorType(t, err, cerrdefs.IsNotFound)
|
||||
assert.ErrorContains(t, err, "no-such-container")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user