Skip to content

command: add tests for container diff and rename#5467

Merged
thaJeztah merged 1 commit intodocker:masterfrom
Stavrospanakakis:cli-container-tests
Oct 4, 2024
Merged

command: add tests for container diff and rename#5467
thaJeztah merged 1 commit intodocker:masterfrom
Stavrospanakakis:cli-container-tests

Conversation

@Stavrospanakakis
Copy link
Copy Markdown
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
Copy Markdown
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

Comment thread cli/command/container/diff_test.go Outdated
Comment thread cli/command/container/diff_test.go Outdated
Comment thread cli/command/container/diff_test.go Outdated
Comment thread cli/command/container/rename_test.go Outdated
@laurazard laurazard self-assigned this Sep 23, 2024
@codecov-commenter
Copy link
Copy Markdown

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
Copy Markdown
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

Comment thread cli/command/container/diff_test.go Outdated
Comment thread cli/command/container/diff_test.go Outdated
Comment thread cli/command/container/diff_test.go Outdated
Comment thread cli/command/container/diff_test.go Outdated
Comment thread cli/command/container/diff_test.go Outdated
Comment thread cli/command/container/diff_test.go Outdated
Comment thread cli/command/container/rename_test.go Outdated
Comment thread cli/command/container/rename_test.go Outdated
Comment thread cli/command/container/rename_test.go
Comment thread cli/command/container/rename_test.go Outdated
@Stavrospanakakis
Copy link
Copy Markdown
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.

Comment thread cli/command/container/rename_test.go
Comment thread cli/command/container/rename_test.go Outdated
Comment thread cli/command/container/rename_test.go Outdated
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

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

@laurazard
Copy link
Copy Markdown
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 <laurabrehm@hey.com>
Signed-off-by: Stavros Panakakis <stavrospanakakis@gmail.com>
@Stavrospanakakis
Copy link
Copy Markdown
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
Copy Markdown
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
@thaJeztah
Copy link
Copy Markdown
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