chore: add unit tests for Prune function#46
Merged
mdelapenya merged 5 commits intotestcontainers:mainfrom Nov 17, 2022
Merged
Conversation
* main: chore(ci): only push Docker image on tags (testcontainers#47)
HofmeisterAn
approved these changes
Nov 17, 2022
mdelapenya
added a commit
to gesellix/moby-ryuk
that referenced
this pull request
Dec 1, 2022
* main: feat: add golangci-lint (testcontainers#48) chore: add unit tests for Prune function (testcontainers#46) chore(ci): only push Docker image on tags (testcontainers#47) chore: bump build system versions (testcontainers#45) chore: rename branch to main (testcontainers#44)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
It adds unit tests for the Prune function and for that:
For the images, I see that this block is not deterministic at the test level: at the moment 25 images are created using the Docker API, the images prune report includes not only the deleted images but untagged ones.
The prune report is formed by a struct with two fields: Deleted and Untagged. When a layer is deleted the untagged field is empty, and viceversa. The test for the images is currently failing because it's not deterministic and dependent on the number of instructions in the Dockerfile used to build the image at the test level. In this test, we are adding a very simple Dockerfile extending the
nginx:alpinebase image.See GH action:
A simple solution for the test would be to check that the length of the deletedImages is greater than zero, but I wanted to check with you first before adding that condition. At the same hand, I advocate for a change at the moment we increase the number of deleted images: instead of appending an entry to the map for each element in the
pruneReport.ImagesDeletedprune report (see above block), I'd ask for those entries where the Untagged field is not empty (capturing the real image that was deleted)Why is important?
Unit test the prune code 😅