Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

command: add tests for container diff and rename #5467

Merged
merged 1 commit into from
Oct 4, 2024

Conversation

Stavrospanakakis
Copy link
Contributor

- What I did
This commit adds tests for the commands docker diff and docker rename. Also, it creates the mock methods of the docker client ContainerDiff and ContainerRename so they can be used in the tests.

For docker diff, it covers the cases that:

  • the command runs successfully
  • the client returns an error
  • the container id is empty

For docker rename, it covers the cases that:

  • the command runs successfully
  • the container old name is empty
  • the container new name is empty
  • the client returns an error

- How I did it
I read all the test cases developed in cli/command/container directory and did the same for diff.go and
rename.go using a fakeClient and mocking the client ContainerDiff and ContainerRename methods.

- How to verify it
Run: make test

- Description for the changelog

Add tests for container diff and rename commands

- A picture of a cute animal (not mandatory but encouraged)

Copy link
Member

@laurazard laurazard left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution! Left a couple of nits to make the tests a little tidier, but overall LGTM

cli/command/container/diff_test.go Outdated Show resolved Hide resolved
cli/command/container/diff_test.go Outdated Show resolved Hide resolved
cli/command/container/diff_test.go Outdated Show resolved Hide resolved
cli/command/container/rename_test.go Outdated Show resolved Hide resolved
@laurazard laurazard self-assigned this Sep 23, 2024
@codecov-commenter
Copy link

codecov-commenter commented Sep 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 59.92%. Comparing base (baa7a9f) to head (46b360b).
Report is 41 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5467      +/-   ##
==========================================
+ Coverage   59.74%   59.92%   +0.17%     
==========================================
  Files         345      345              
  Lines       23431    23431              
==========================================
+ Hits        13999    14040      +41     
+ Misses       8458     8417      -41     
  Partials      974      974              

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

thanks for contributing! I left comments/ suggestions inline; let me know what you think

cli/command/container/diff_test.go Outdated Show resolved Hide resolved
cli/command/container/diff_test.go Outdated Show resolved Hide resolved
cli/command/container/diff_test.go Outdated Show resolved Hide resolved
cli/command/container/diff_test.go Outdated Show resolved Hide resolved
cli/command/container/diff_test.go Outdated Show resolved Hide resolved
cli/command/container/diff_test.go Outdated Show resolved Hide resolved
cli/command/container/rename_test.go Outdated Show resolved Hide resolved
cli/command/container/rename_test.go Outdated Show resolved Hide resolved
cli/command/container/rename_test.go Show resolved Hide resolved
cli/command/container/rename_test.go Outdated Show resolved Hide resolved
@Stavrospanakakis
Copy link
Contributor Author

@thaJeztah @laurazard Thank you for the code review:) I committed the suggested changes from GitHub UI and will now work on the code review comments. When this pull request is ready after all the required changes, I will rebase and sign to match the Contribution guidelines.

cli/command/container/rename_test.go Outdated Show resolved Hide resolved
cli/command/container/rename_test.go Outdated Show resolved Hide resolved
cli/command/container/rename_test.go Outdated Show resolved Hide resolved
Copy link
Member

@laurazard laurazard left a comment

Choose a reason for hiding this comment

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

LGTM

@Stavrospanakakis
Copy link
Contributor Author

@laurazard @thaJeztah I added all the requested changes and squashed the git commits.

@laurazard
Copy link
Member

@thaJeztah this LGTY?

This commit adds tests for the commands
docker diff and docker rename. Also,
it creates the mock methods of the
docker client ContainerDiff and
ContainerRename so they can
be used in the tests.

For docker diff, it covers the
cases that:
 - the command runs successfully
 - the client returns an error
 - the container id is empty

For docker rename, it covers
the cases that:
 - the command runs successfully
 - the container old name is empty
 - the container new name is empty
 - the client returns an error

Co-authored-by: Laura Brehm <[email protected]>
Signed-off-by: Stavros Panakakis <[email protected]>
@Stavrospanakakis
Copy link
Contributor Author

@laurazard @thaJeztah I renamed containerId to containerID because the CI failed with this error:

#16 [lint 4/4] RUN --mount=type=bind,target=.     --mount=type=cache,target=/root/.cache         golangci-lint run
#16 63.82 cli/command/container/diff_test.go:88:2: ST1003: var containerId should be containerID (stylecheck)
#16 63.82 	containerId := ""
#16 63.82 	^
#16 ERROR: process "/bin/sh -c golangci-lint run" did not complete successfully: exit code: 1
------
 > [lint 4/4] RUN --mount=type=bind,target=.     --mount=type=cache,target=/root/.cache         golangci-lint run:
63.82 cli/command/container/diff_test.go:88:2: ST1003: var containerId should be containerID (stylecheck)
63.82 	containerId := ""
63.82 	^

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM!

sorry for the delay; I somehow forgot about this one 🙈

@thaJeztah thaJeztah merged commit 7908982 into docker:master Oct 4, 2024
95 checks passed
@thaJeztah
Copy link
Member

Thanks for contributing!!

@Stavrospanakakis Stavrospanakakis deleted the cli-container-tests branch October 6, 2024 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants