istio.io/istio@v0.0.0-20240520182934-d79c90f27776/pkg/util/identifier/util_test.go (about)

     1  // Copyright Istio Authors
     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  package identifier
    16  
    17  import "testing"
    18  
    19  func TestIsSameOrEmpty(t *testing.T) {
    20  	tests := []struct {
    21  		name     string
    22  		a        string
    23  		b        string
    24  		expected bool
    25  	}{
    26  		{
    27  			name:     "a and b are same empty",
    28  			expected: true,
    29  		},
    30  		{
    31  			name:     "b is empty",
    32  			a:        "foo",
    33  			expected: true,
    34  		},
    35  		{
    36  			name:     "a is empty",
    37  			b:        "bar",
    38  			expected: true,
    39  		},
    40  		{
    41  			name:     "a and b are same",
    42  			a:        "bar",
    43  			b:        "bar",
    44  			expected: true,
    45  		},
    46  		{
    47  			name:     "a and b are not same",
    48  			a:        "foo",
    49  			b:        "bar",
    50  			expected: false,
    51  		},
    52  	}
    53  
    54  	for _, tt := range tests {
    55  		t.Run(tt.name, func(t *testing.T) {
    56  			res := IsSameOrEmpty(tt.a, tt.b)
    57  			if res != tt.expected {
    58  				t.Errorf("IsSameOrEmpty() = %v, want %v", res, tt.expected)
    59  			}
    60  		})
    61  	}
    62  }