github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/integration/image/list_test.go (about)

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