github.com/aristanetworks/goarista@v0.0.0-20240514173732-cca2755bbd44/sliceutils/sliceutils_test.go (about) 1 // Copyright (c) 2023 Arista Networks, Inc. 2 // Use of this source code is governed by the Apache License 2.0 3 // that can be found in the COPYING file. 4 5 package sliceutils 6 7 import ( 8 "testing" 9 10 "github.com/aristanetworks/goarista/test" 11 ) 12 13 func TestToAnySlice(t *testing.T) { 14 in := []int{1, 2, 3} 15 exp := []any{1, 2, 3} 16 got := ToAnySlice(in) 17 if d := test.Diff(got, exp); d != "" { 18 t.Fatalf("expected: %v, got %v, diff: %s", exp, got, d) 19 } 20 21 in2 := []string{"a", "b", "c"} 22 exp = []any{"a", "b", "c"} 23 got = ToAnySlice(in2) 24 if d := test.Diff(got, exp); d != "" { 25 t.Fatalf("expected: %v, got %v, diff: %s", exp, got, d) 26 } 27 28 } 29 30 func TestSortedStringKeys(t *testing.T) { 31 in := map[string]any{"b": "1", "aaaa": 2, "aaa": 3} 32 got := SortedStringKeys(in) 33 exp := []string{"aaa", "aaaa", "b"} 34 if d := test.Diff(exp, got); d != "" { 35 t.Fatalf("expected %#v, got %#v, diff %s", exp, got, d) 36 } 37 38 }