github.com/rumpl/bof@v23.0.0-rc.2+incompatible/integration/image/list_test.go (about)

     1  package image // import "github.com/docker/docker/integration/image"
     2  
     3  import (
     4  	"context"
     5  	"strings"
     6  	"testing"
     7  
     8  	"github.com/docker/docker/api/types"
     9  	"github.com/docker/docker/api/types/filters"
    10  	"github.com/docker/docker/api/types/versions"
    11  	"gotest.tools/v3/assert"
    12  	is "gotest.tools/v3/assert/cmp"
    13  	"gotest.tools/v3/skip"
    14  )
    15  
    16  // Regression : #38171
    17  func TestImagesFilterMultiReference(t *testing.T) {
    18  	skip.If(t, versions.LessThan(testEnv.DaemonAPIVersion(), "1.40"), "broken in earlier versions")
    19  	defer setupTest(t)()
    20  	client := testEnv.APIClient()
    21  	ctx := context.Background()
    22  
    23  	name := strings.ToLower(t.Name())
    24  	repoTags := []string{
    25  		name + ":v1",
    26  		name + ":v2",
    27  		name + ":v3",
    28  		name + ":v4",
    29  	}
    30  
    31  	for _, repoTag := range repoTags {
    32  		err := client.ImageTag(ctx, "busybox:latest", repoTag)
    33  		assert.NilError(t, err)
    34  	}
    35  
    36  	filter := filters.NewArgs()
    37  	filter.Add("reference", repoTags[0])
    38  	filter.Add("reference", repoTags[1])
    39  	filter.Add("reference", repoTags[2])
    40  	options := types.ImageListOptions{
    41  		All:     false,
    42  		Filters: filter,
    43  	}
    44  	images, err := client.ImageList(ctx, options)
    45  	assert.NilError(t, err)
    46  
    47  	assert.Check(t, is.Equal(len(images[0].RepoTags), 3))
    48  	for _, repoTag := range images[0].RepoTags {
    49  		if repoTag != repoTags[0] && repoTag != repoTags[1] && repoTag != repoTags[2] {
    50  			t.Errorf("list images doesn't match any repoTag we expected, repoTag: %s", repoTag)
    51  		}
    52  	}
    53  }