github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/pkg/util/comparison_test.go (about)

     1  // Copyright 2023 PingCAP, Inc.
     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  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  package util
    14  
    15  import (
    16  	"testing"
    17  )
    18  
    19  func TestAreStringSlicesEquivalent(t *testing.T) {
    20  	tests := []struct {
    21  		name string
    22  		a    []string
    23  		b    []string
    24  		want bool
    25  	}{
    26  		{
    27  			name: "equal slices",
    28  			a:    []string{"foo", "bar", "baz"},
    29  			b:    []string{"baz", "foo", "bar"},
    30  			want: true,
    31  		},
    32  		{
    33  			name: "different lengths",
    34  			a:    []string{"foo", "bar", "baz"},
    35  			b:    []string{"foo", "bar"},
    36  			want: false,
    37  		},
    38  		{
    39  			name: "different elements",
    40  			a:    []string{"foo", "bar", "baz"},
    41  			b:    []string{"qux", "quux", "corge"},
    42  			want: false,
    43  		},
    44  		{
    45  			name: "nil elements",
    46  			a:    []string{},
    47  			b:    []string{},
    48  			want: true,
    49  		},
    50  	}
    51  
    52  	for _, tt := range tests {
    53  		t.Run(tt.name, func(t *testing.T) {
    54  			if got := AreStringSlicesEquivalent(tt.a, tt.b); got != tt.want {
    55  				t.Errorf("AreStringSlicesEquivalent() = %v, want %v", got, tt.want)
    56  			}
    57  		})
    58  	}
    59  }
    60  
    61  // END: j3d8f4b2j2p9