github.com/fafucoder/cilium@v1.6.11/pkg/comparator/comparator_test.go (about)

     1  // Copyright 2018 Authors of Cilium
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // +build !privileged_tests
    16  
    17  package comparator
    18  
    19  import (
    20  	"testing"
    21  
    22  	. "gopkg.in/check.v1"
    23  )
    24  
    25  // Hook up gocheck into the "go test" runner.
    26  func Test(t *testing.T) {
    27  	TestingT(t)
    28  }
    29  
    30  type ComparatorSuite struct{}
    31  
    32  var _ = Suite(&ComparatorSuite{})
    33  
    34  func (s *ComparatorSuite) TestMapStringEquals(c *C) {
    35  	tests := []struct {
    36  		m1   map[string]string
    37  		m2   map[string]string
    38  		want bool
    39  	}{
    40  		{
    41  			m1:   nil,
    42  			m2:   nil,
    43  			want: true,
    44  		},
    45  		{
    46  			m1: map[string]string{
    47  				"foo": "bar",
    48  			},
    49  			m2: map[string]string{
    50  				"foo": "bar",
    51  			},
    52  			want: true,
    53  		},
    54  		{
    55  			m1:   map[string]string{},
    56  			m2:   map[string]string{},
    57  			want: true,
    58  		},
    59  		{
    60  			m1: map[string]string{
    61  				"fo": "bar",
    62  			},
    63  			m2: map[string]string{
    64  				"foo": "bar",
    65  			},
    66  			want: false,
    67  		},
    68  		{
    69  			m1: nil,
    70  			m2: map[string]string{
    71  				"foo": "bar",
    72  			},
    73  			want: false,
    74  		},
    75  		{
    76  			m1: map[string]string{
    77  				"foo": "bar",
    78  			},
    79  			m2:   nil,
    80  			want: false,
    81  		},
    82  		{
    83  			m1: map[string]string{
    84  				"foo": "bar",
    85  			},
    86  			m2:   nil,
    87  			want: false,
    88  		},
    89  	}
    90  	for _, tt := range tests {
    91  		c.Assert(MapStringEquals(tt.m1, tt.m2), Equals, tt.want)
    92  	}
    93  }
    94  
    95  func (s *ComparatorSuite) TestMapBoolEquals(c *C) {
    96  	tests := []struct {
    97  		m1   map[string]bool
    98  		m2   map[string]bool
    99  		want bool
   100  	}{
   101  		{
   102  			m1:   nil,
   103  			m2:   nil,
   104  			want: true,
   105  		},
   106  		{
   107  			m1: map[string]bool{
   108  				"foo": true,
   109  			},
   110  			m2: map[string]bool{
   111  				"foo": true,
   112  			},
   113  			want: true,
   114  		},
   115  		{
   116  			m1:   map[string]bool{},
   117  			m2:   map[string]bool{},
   118  			want: true,
   119  		},
   120  		{
   121  			m1: map[string]bool{
   122  				"fo": true,
   123  			},
   124  			m2: map[string]bool{
   125  				"foo": true,
   126  			},
   127  			want: false,
   128  		},
   129  		{
   130  			m1: nil,
   131  			m2: map[string]bool{
   132  				"foo": true,
   133  			},
   134  			want: false,
   135  		},
   136  		{
   137  			m1: map[string]bool{
   138  				"foo": true,
   139  			},
   140  			m2:   nil,
   141  			want: false,
   142  		},
   143  		{
   144  			m1: map[string]bool{
   145  				"foo": true,
   146  			},
   147  			m2:   nil,
   148  			want: false,
   149  		},
   150  	}
   151  	for _, tt := range tests {
   152  		c.Assert(MapBoolEquals(tt.m1, tt.m2), Equals, tt.want)
   153  	}
   154  }