Skip to content

integration-cli: migrate TestAPIStatsContainerNotFound to integration tests#51369

Merged
robmry merged 1 commit intomoby:masterfrom
dohrisalim:issue#50159
Nov 3, 2025
Merged

integration-cli: migrate TestAPIStatsContainerNotFound to integration tests#51369
robmry merged 1 commit intomoby:masterfrom
dohrisalim:issue#50159

Conversation

@dohrisalim
Copy link
Contributor

Summary

Migrates TestAPIStatsContainerNotFound from the deprecated integration-cli test suite to the modern integration/container package following established migration patterns.

Changes

  • Added: New TestStatsContainerNotFound function in integration/container/stats_test.go
  • Removed: Old TestAPIStatsContainerNotFound function from integration-cli/docker_api_stats_test.go
  • Cleaned up: Removed unused imports (cerrdefs and client) from integration-cli file

Test Description

The test validates that the ContainerStats API correctly returns NotFound errors when requesting stats for non-existent containers, covering both:

  • Streaming mode (Stream: true)
  • Non-streaming mode (Stream: false)

Migration Patterns Applied

  • Converted from check.v1 framework to standard testing package
  • Updated assertions to use gotest.tools/v3/assert
  • Changed from testRequires(c, DaemonIsLinux) to skip.If(t, testEnv.DaemonInfo.OSType == "windows")
  • Updated context handling: testutil.GetContext(c)setupTest(t)
  • Updated API client access: client.NewClientWithOpts(client.FromEnv)testEnv.APIClient()

Test Results

=== RUN   TestStatsContainerNotFound
--- PASS: TestStatsContainerNotFound (0.03s)
PASS

DONE 1 tests in 3.358s

Related Issue

Related to #50159

Copy link
Contributor

@robmry robmry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @dohrisalim - thank you for taking a look at this!

It needs a rebase.

Could you remove the PR link from the commit comment, as GitHub tends to spam PRs when commits are merged.

And, a couple of suggestions (please squash commits) ...

}

func TestStatsContainerNotFound(t *testing.T) {
skip.If(t, testEnv.DaemonInfo.OSType == "windows")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original test was skipped on Windows, but I'm not sure it needs to be - could try removing this?

ctx := setupTest(t)
apiClient := testEnv.APIClient()

_, err := apiClient.ContainerStats(ctx, "no-such-container", client.ContainerStatsOptions{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there are two tests doing the same thing (just with different options) - it'd be best to use a test array, see TestAttach for an example. Then each test gets its own result, the second still runs if the first fails, and we can add more if we think of them.

	tests := []struct {
		name    string
		options client.ContainerStatsOptions
	}{
        ...
    }

@robmry robmry added the kind/refactor PR's that refactor, or clean-up code label Oct 31, 2025
@dohrisalim
Copy link
Contributor Author

dohrisalim commented Oct 31, 2025

Thanks for the fast reply @robmry, I'm on it!

@dohrisalim dohrisalim force-pushed the issue#50159 branch 2 times, most recently from 6501d7b to b82c165 Compare November 2, 2025 09:12
@dohrisalim
Copy link
Contributor Author

Hi @robmry , can you take a look at this PR at your convenience. I made the changes you requested.

@robmry
Copy link
Contributor

robmry commented Nov 2, 2025

Hi @robmry , can you take a look at this PR at your convenience. I made the changes you requested.

Thanks - looks good, but needs a rebase to fix the merge conflict before tests will run.

… 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>
@dohrisalim
Copy link
Contributor Author

Sorry about that I thought I did the rebase, the pr should be mergeable now.

@dohrisalim
Copy link
Contributor Author

Hey👋 @robmry could you take a look at this pr when you're free?

Copy link
Contributor

@robmry robmry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - thank you @dohrisalim.

@robmry robmry added this to the 29.0.0 milestone Nov 3, 2025
@robmry
Copy link
Contributor

robmry commented Nov 3, 2025

I'll get this merged ... test changes only, and the tests pass.

@robmry robmry merged commit 0b8fa46 into moby:master Nov 3, 2025
181 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/testing kind/refactor PR's that refactor, or clean-up code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants