-
Notifications
You must be signed in to change notification settings - Fork 29
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
test: add ability to mock the Docker client #287
test: add ability to mock the Docker client #287
Conversation
This commit adds the ability to mock the docker.client so that we can perform tests on the methods in the `docker.go` file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat!
mock.Mock | ||
} | ||
|
||
func (m *MockDockerClient) ImagePull(ctx context.Context, ref string, options image.PullOptions) (io.ReadCloser, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FTR to reduce the boilerplate here, we can also only add to the interface the exact functions that we need from the client. Then we can mock them on a need-by-need basiss
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @victorges,
I’ve ensured that all tests related to [this branch](https://github.com/livepeer/ai-worker/tree/auto_pull_containers) have been implemented based on your changes. Please take a look, and feel free to make any adjustments if you see room for improvement.
I also attempted to remove the [ContainerInspect](https://github.com/livepeer/ai-worker/blob/72bca183d51b4437914ec31e994039298a0204d2/worker/docker_test.go#L46) mock method since it’s not being used in the tests. However, doing so caused the following error:
cannot use mockDockerClient (variable of type *MockDockerClient) as DockerClient value in struct literal: *MockDockerClient does not implement DockerClient (missing method ContainerInspect)
Let me know if you have any suggestions on how to address this, or if there’s a better way to handle it.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really curious that it would complain after removing the function from the interface. Let's leave it anyway since I'm using it in some of the latest changes I made to ai-worker for realtime containers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea we use it already here. However, this function is not part of the Docker Manager but is separate. Ideally, it should be removed from the manager and mocked independently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you already use it in the Manager for realtime let's keep it as is.
This commit renames the docker client interface so that it is more clear what it does.
This commit ensures the docker.warm and docker.hasCapacity methods are tested correctly. It also cleans up the earlier added tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!
mock.Mock | ||
} | ||
|
||
func (m *MockDockerClient) ImagePull(ctx context.Context, ref string, options image.PullOptions) (io.ReadCloser, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really curious that it would complain after removing the function from the interface. Let's leave it anyway since I'm using it in some of the latest changes I made to ai-worker for realtime containers.
This pull request adds the ability to mock the docker.client so that we can perform tests on the methods in the
docker.go
file.