github.com/brahmaroutu/docker@v1.2.1-0.20160809185609-eb28dde01f16/api/client/container/ps_test.go (about)

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