github.com/vieux/docker@v0.6.3-0.20161004191708-e097c2a938c7/cli/command/container/ps_test.go (about) 1 package container 2 3 import ( 4 "testing" 5 6 "github.com/docker/docker/opts" 7 "github.com/docker/docker/pkg/testutil/assert" 8 ) 9 10 func TestBuildContainerListOptions(t *testing.T) { 11 filters := opts.NewFilterOpt() 12 assert.NilError(t, filters.Set("foo=bar")) 13 assert.NilError(t, filters.Set("baz=foo")) 14 15 contexts := []struct { 16 psOpts *psOptions 17 expectedAll bool 18 expectedSize bool 19 expectedLimit int 20 expectedFilters map[string]string 21 }{ 22 { 23 psOpts: &psOptions{ 24 all: true, 25 size: true, 26 last: 5, 27 filter: filters, 28 }, 29 expectedAll: true, 30 expectedSize: true, 31 expectedLimit: 5, 32 expectedFilters: map[string]string{ 33 "foo": "bar", 34 "baz": "foo", 35 }, 36 }, 37 { 38 psOpts: &psOptions{ 39 all: true, 40 size: true, 41 last: -1, 42 nLatest: true, 43 }, 44 expectedAll: true, 45 expectedSize: true, 46 expectedLimit: 1, 47 expectedFilters: make(map[string]string), 48 }, 49 } 50 51 for _, c := range contexts { 52 options, err := buildContainerListOptions(c.psOpts) 53 assert.NilError(t, err) 54 55 assert.Equal(t, c.expectedAll, options.All) 56 assert.Equal(t, c.expectedSize, options.Size) 57 assert.Equal(t, c.expectedLimit, options.Limit) 58 assert.Equal(t, options.Filter.Len(), len(c.expectedFilters)) 59 60 for k, v := range c.expectedFilters { 61 f := options.Filter 62 if !f.ExactMatch(k, v) { 63 t.Fatalf("Expected filter with key %s to be %s but got %s", k, v, f.Get(k)) 64 } 65 } 66 } 67 }