github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/daemon/cluster/filters_test.go (about)

     1  package cluster // import "github.com/demonoid81/moby/daemon/cluster"
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/demonoid81/moby/api/types/filters"
     7  )
     8  
     9  func TestNewListSecretsFilters(t *testing.T) {
    10  	validNameFilter := filters.NewArgs()
    11  	validNameFilter.Add("name", "test_name")
    12  
    13  	validIDFilter := filters.NewArgs()
    14  	validIDFilter.Add("id", "7c9009d6720f6de3b492f5")
    15  
    16  	validLabelFilter := filters.NewArgs()
    17  	validLabelFilter.Add("label", "type=test")
    18  	validLabelFilter.Add("label", "storage=ssd")
    19  	validLabelFilter.Add("label", "memory")
    20  
    21  	validNamesFilter := filters.NewArgs()
    22  	validNamesFilter.Add("names", "test_name")
    23  
    24  	validAllFilter := filters.NewArgs()
    25  	validAllFilter.Add("name", "nodeName")
    26  	validAllFilter.Add("id", "7c9009d6720f6de3b492f5")
    27  	validAllFilter.Add("label", "type=test")
    28  	validAllFilter.Add("label", "memory")
    29  	validAllFilter.Add("names", "test_name")
    30  
    31  	validFilters := []filters.Args{
    32  		validNameFilter,
    33  		validIDFilter,
    34  		validLabelFilter,
    35  		validNamesFilter,
    36  		validAllFilter,
    37  	}
    38  
    39  	invalidTypeFilter := filters.NewArgs()
    40  	invalidTypeFilter.Add("nonexist", "aaaa")
    41  
    42  	invalidFilters := []filters.Args{
    43  		invalidTypeFilter,
    44  	}
    45  
    46  	for _, filter := range validFilters {
    47  		if _, err := newListSecretsFilters(filter); err != nil {
    48  			t.Fatalf("Should get no error, got %v", err)
    49  		}
    50  	}
    51  
    52  	for _, filter := range invalidFilters {
    53  		if _, err := newListSecretsFilters(filter); err == nil {
    54  			t.Fatalf("Should get an error for filter %v, while got nil", filter)
    55  		}
    56  	}
    57  }
    58  
    59  func TestNewListConfigsFilters(t *testing.T) {
    60  	validNameFilter := filters.NewArgs()
    61  	validNameFilter.Add("name", "test_name")
    62  
    63  	validIDFilter := filters.NewArgs()
    64  	validIDFilter.Add("id", "7c9009d6720f6de3b492f5")
    65  
    66  	validLabelFilter := filters.NewArgs()
    67  	validLabelFilter.Add("label", "type=test")
    68  	validLabelFilter.Add("label", "storage=ssd")
    69  	validLabelFilter.Add("label", "memory")
    70  
    71  	validAllFilter := filters.NewArgs()
    72  	validAllFilter.Add("name", "nodeName")
    73  	validAllFilter.Add("id", "7c9009d6720f6de3b492f5")
    74  	validAllFilter.Add("label", "type=test")
    75  	validAllFilter.Add("label", "memory")
    76  
    77  	validFilters := []filters.Args{
    78  		validNameFilter,
    79  		validIDFilter,
    80  		validLabelFilter,
    81  		validAllFilter,
    82  	}
    83  
    84  	invalidTypeFilter := filters.NewArgs()
    85  	invalidTypeFilter.Add("nonexist", "aaaa")
    86  
    87  	invalidFilters := []filters.Args{
    88  		invalidTypeFilter,
    89  	}
    90  
    91  	for _, filter := range validFilters {
    92  		if _, err := newListConfigsFilters(filter); err != nil {
    93  			t.Fatalf("Should get no error, got %v", err)
    94  		}
    95  	}
    96  
    97  	for _, filter := range invalidFilters {
    98  		if _, err := newListConfigsFilters(filter); err == nil {
    99  			t.Fatalf("Should get an error for filter %v, while got nil", filter)
   100  		}
   101  	}
   102  }