2016-09-08 13:11:39 -04:00
|
|
|
package container
|
|
|
|
|
2016-09-13 14:53:11 -04:00
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/docker/docker/opts"
|
|
|
|
"github.com/docker/docker/pkg/testutil/assert"
|
|
|
|
)
|
2016-09-08 13:11:39 -04:00
|
|
|
|
|
|
|
func TestBuildContainerListOptions(t *testing.T) {
|
2016-09-13 14:53:11 -04:00
|
|
|
filters := opts.NewFilterOpt()
|
|
|
|
assert.NilError(t, filters.Set("foo=bar"))
|
|
|
|
assert.NilError(t, filters.Set("baz=foo"))
|
2016-09-08 13:11:39 -04:00
|
|
|
|
|
|
|
contexts := []struct {
|
|
|
|
psOpts *psOptions
|
|
|
|
expectedAll bool
|
|
|
|
expectedSize bool
|
|
|
|
expectedLimit int
|
|
|
|
expectedFilters map[string]string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
psOpts: &psOptions{
|
|
|
|
all: true,
|
|
|
|
size: true,
|
|
|
|
last: 5,
|
2016-09-13 14:53:11 -04:00
|
|
|
filter: filters,
|
2016-09-08 13:11:39 -04:00
|
|
|
},
|
|
|
|
expectedAll: true,
|
|
|
|
expectedSize: true,
|
|
|
|
expectedLimit: 5,
|
|
|
|
expectedFilters: map[string]string{
|
|
|
|
"foo": "bar",
|
|
|
|
"baz": "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
psOpts: &psOptions{
|
|
|
|
all: true,
|
|
|
|
size: true,
|
|
|
|
last: -1,
|
|
|
|
nLatest: true,
|
|
|
|
},
|
|
|
|
expectedAll: true,
|
|
|
|
expectedSize: true,
|
|
|
|
expectedLimit: 1,
|
|
|
|
expectedFilters: make(map[string]string),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, c := range contexts {
|
|
|
|
options, err := buildContainerListOptions(c.psOpts)
|
2016-09-13 14:53:11 -04:00
|
|
|
assert.NilError(t, err)
|
2016-09-08 13:11:39 -04:00
|
|
|
|
2016-09-13 14:53:11 -04:00
|
|
|
assert.Equal(t, c.expectedAll, options.All)
|
|
|
|
assert.Equal(t, c.expectedSize, options.Size)
|
|
|
|
assert.Equal(t, c.expectedLimit, options.Limit)
|
|
|
|
assert.Equal(t, options.Filter.Len(), len(c.expectedFilters))
|
2016-09-08 13:11:39 -04:00
|
|
|
|
|
|
|
for k, v := range c.expectedFilters {
|
|
|
|
f := options.Filter
|
|
|
|
if !f.ExactMatch(k, v) {
|
|
|
|
t.Fatalf("Expected filter with key %s to be %s but got %s", k, v, f.Get(k))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|