...
1
2
3
4
5
6
7
8
9
10
11
12
13
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