...

Source file src/github.com/GoogleCloudPlatform/k8s-config-connector/pkg/util/slice/slice_test.go

Documentation: github.com/GoogleCloudPlatform/k8s-config-connector/pkg/util/slice

     1  // Copyright 2023 Google LLC
     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 slice_test
    16  
    17  import (
    18  	"reflect"
    19  	"testing"
    20  
    21  	"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/util/slice"
    22  
    23  	"github.com/google/go-cmp/cmp"
    24  )
    25  
    26  func TestReverse(t *testing.T) {
    27  	t.Parallel()
    28  	tests := []struct {
    29  		name     string
    30  		input    []string
    31  		expected []string
    32  	}{
    33  		{
    34  			name:     "nil array",
    35  			input:    nil,
    36  			expected: nil,
    37  		},
    38  		{
    39  			name:     "empty array",
    40  			input:    []string{},
    41  			expected: []string{},
    42  		},
    43  		{
    44  			name:     "array with content",
    45  			input:    []string{"one", "two", "three", "four", "five"},
    46  			expected: []string{"five", "four", "three", "two", "one"},
    47  		},
    48  	}
    49  
    50  	for _, tc := range tests {
    51  		tc := tc
    52  		t.Run(tc.name, func(t *testing.T) {
    53  			sliceToReverse := tc.input
    54  			slice.Reverse(sliceToReverse)
    55  			if got, want := sliceToReverse, tc.expected; !reflect.DeepEqual(got, want) {
    56  				t.Fatalf("unexpected diff (-want +got): \n%v", cmp.Diff(want, got))
    57  			}
    58  		})
    59  	}
    60  }
    61  

View as plain text