github.com/Heebron/moby@v0.0.0-20221111184709-6eab4f55faf7/volume/service/convert_test.go (about)

     1  package service
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/docker/docker/api/types/filters"
     7  	"gotest.tools/v3/assert"
     8  	"gotest.tools/v3/assert/cmp"
     9  )
    10  
    11  func TestFilterWithPrune(t *testing.T) {
    12  	f := filters.NewArgs()
    13  	assert.NilError(t, withPrune(f))
    14  	assert.Check(t, cmp.Len(f.Get("label"), 1))
    15  	assert.Check(t, f.Match("label", AnonymousLabel))
    16  
    17  	f = filters.NewArgs()
    18  	f.Add("label", "foo=bar")
    19  	f.Add("label", "bar=baz")
    20  	assert.NilError(t, withPrune(f))
    21  
    22  	assert.Check(t, cmp.Len(f.Get("label"), 3))
    23  	assert.Check(t, f.Match("label", AnonymousLabel))
    24  	assert.Check(t, f.Match("label", "foo=bar"))
    25  	assert.Check(t, f.Match("label", "bar=baz"))
    26  
    27  	f = filters.NewArgs()
    28  	f.Add("label", "foo=bar")
    29  	f.Add("all", "1")
    30  	assert.NilError(t, withPrune(f))
    31  
    32  	assert.Check(t, cmp.Len(f.Get("label"), 1))
    33  	assert.Check(t, f.Match("label", "foo=bar"))
    34  
    35  	f = filters.NewArgs()
    36  	f.Add("label", "foo=bar")
    37  	f.Add("all", "true")
    38  	assert.NilError(t, withPrune(f))
    39  
    40  	assert.Check(t, cmp.Len(f.Get("label"), 1))
    41  	assert.Check(t, f.Match("label", "foo=bar"))
    42  
    43  	f = filters.NewArgs()
    44  	f.Add("all", "0")
    45  	assert.NilError(t, withPrune(f))
    46  	assert.Check(t, cmp.Len(f.Get("label"), 1))
    47  	assert.Check(t, f.Match("label", AnonymousLabel))
    48  
    49  	f = filters.NewArgs()
    50  	f.Add("all", "false")
    51  	assert.NilError(t, withPrune(f))
    52  	assert.Check(t, cmp.Len(f.Get("label"), 1))
    53  	assert.Check(t, f.Match("label", AnonymousLabel))
    54  
    55  	f = filters.NewArgs()
    56  	f.Add("all", "")
    57  	assert.ErrorContains(t, withPrune(f), "invalid filter 'all'")
    58  
    59  	f = filters.NewArgs()
    60  	f.Add("all", "1")
    61  	f.Add("all", "0")
    62  	assert.ErrorContains(t, withPrune(f), "invalid filter 'all")
    63  }