github.com/looshlee/beatles@v0.0.0-20220727174639-742810ab631c/pkg/checker/checker_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 checker
    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  	check.TestingT(t)
    28  }
    29  
    30  type CheckerSuite struct{}
    31  
    32  var _ = check.Suite(&CheckerSuite{})
    33  
    34  func (s *CheckerSuite) TestDeepEqualsCheck(c *check.C) {
    35  	names := []string{"a", "b"}
    36  	type args struct {
    37  		params []interface{}
    38  	}
    39  	tests := []struct {
    40  		name string
    41  		args args
    42  		want bool
    43  	}{
    44  		{
    45  			name: "args of basic type are equal",
    46  			args: args{
    47  				params: []interface{}{1, 1},
    48  			},
    49  			want: true,
    50  		},
    51  		{
    52  			name: "args of basic type are not equal",
    53  			args: args{
    54  				params: []interface{}{1, 2},
    55  			},
    56  			want: false,
    57  		},
    58  		{
    59  			name: "maps are deeply equal",
    60  			args: args{
    61  				params: []interface{}{
    62  					map[string]string{
    63  						"foo": "bar",
    64  					},
    65  					map[string]string{
    66  						"foo": "bar",
    67  					},
    68  				},
    69  			},
    70  			want: true,
    71  		},
    72  		{
    73  			name: "maps are not equal",
    74  			args: args{
    75  				params: []interface{}{
    76  					map[string]string{
    77  						"foo": "ar",
    78  					},
    79  					map[string]string{
    80  						"foo": "bar",
    81  					},
    82  				},
    83  			},
    84  			want: false,
    85  		},
    86  	}
    87  	for _, tt := range tests {
    88  		equal, err := DeepEquals.Check(tt.args.params, names)
    89  		c.Assert(equal, check.Equals, tt.want)
    90  		c.Assert(equal, check.Equals, err == "")
    91  	}
    92  
    93  	equal, err := DeepEquals.Check([]interface{}{1, 1}, []string{"a"})
    94  	c.Assert(equal, check.Equals, false)
    95  	c.Assert(err, check.NotNil)
    96  
    97  	equal, err = DeepEquals.Check([]interface{}{1}, []string{"a"})
    98  	c.Assert(equal, check.Equals, false)
    99  	c.Assert(err, check.NotNil)
   100  }