c8d: Fix TestImagesFilterMultiReference

Signed-off-by: Djordje Lukic <djordje.lukic@docker.com>
This commit is contained in:
Djordje Lukic 2023-07-21 13:47:49 +02:00
parent 1d8108b009
commit e5cffc07b3
No known key found for this signature in database
2 changed files with 14 additions and 13 deletions

View file

@ -357,22 +357,23 @@ func (i *ImageService) setupFilters(ctx context.Context, imageFilters filters.Ar
})
}
err = imageFilters.WalkValues("reference", func(value string) error {
if refs := imageFilters.Get("reference"); len(refs) != 0 {
fltrs = append(fltrs, func(image images.Image) bool {
ref, err := reference.ParseNormalizedNamed(image.Name)
if err != nil {
return false
}
found, err := reference.FamiliarMatch(value, ref)
if err != nil {
return false
for _, value := range refs {
found, err := reference.FamiliarMatch(value, ref)
if err != nil {
return false
}
if found {
return found
}
}
return found
return false
})
return nil
})
if err != nil {
return nil, err
}
return func(image images.Image) bool {

View file

@ -20,7 +20,7 @@ import (
// Regression : #38171
func TestImagesFilterMultiReference(t *testing.T) {
skip.If(t, versions.LessThan(testEnv.DaemonAPIVersion(), "1.40"), "broken in earlier versions")
defer setupTest(t)()
t.Cleanup(setupTest(t))
client := testEnv.APIClient()
ctx := context.Background()
@ -42,13 +42,13 @@ func TestImagesFilterMultiReference(t *testing.T) {
filter.Add("reference", repoTags[1])
filter.Add("reference", repoTags[2])
options := types.ImageListOptions{
All: false,
Filters: filter,
}
images, err := client.ImageList(ctx, options)
assert.NilError(t, err)
assert.Check(t, is.Equal(len(images[0].RepoTags), 3))
assert.Assert(t, is.Len(images, 1))
assert.Check(t, is.Len(images[0].RepoTags, 3))
for _, repoTag := range images[0].RepoTags {
if repoTag != repoTags[0] && repoTag != repoTags[1] && repoTag != repoTags[2] {
t.Errorf("list images doesn't match any repoTag we expected, repoTag: %s", repoTag)
@ -57,7 +57,7 @@ func TestImagesFilterMultiReference(t *testing.T) {
}
func TestImagesFilterBeforeSince(t *testing.T) {
defer setupTest(t)()
t.Cleanup(setupTest(t))
client := testEnv.APIClient()
ctx := context.Background()