Files
teleport/api/utils/slices_test.go
T
Brian Joerger 488af75797 Client store generalization (#19420)
- Add a generalized client store made up of a key, profile, and trusted certs store. Each sub store can support different backends (~/.tsh, identity_file, in-memory). 
- Replace custom identity file handling with in-memory client store.
- Fix issues with trusted certs handling.
2023-01-06 01:34:04 +00:00

57 lines
1.7 KiB
Go

/*
Copyright 2022 Gravitational, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package utils
import (
"bytes"
"testing"
"github.com/stretchr/testify/require"
)
func TestDeduplicate(t *testing.T) {
tests := []struct {
name string
in, expected []string
}{
{name: "empty slice", in: []string{}, expected: []string{}},
{name: "slice with unique elements", in: []string{"a", "b"}, expected: []string{"a", "b"}},
{name: "slice with duplicate elements", in: []string{"a", "b", "b", "a", "c"}, expected: []string{"a", "b", "c"}},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
require.Equal(t, tc.expected, Deduplicate(tc.in))
})
}
}
func TestDeduplicateAny(t *testing.T) {
tests := []struct {
name string
in, expected [][]byte
}{
{name: "empty slice", in: [][]byte{}, expected: [][]byte{}},
{name: "slice with unique elements", in: [][]byte{{0}, {1}}, expected: [][]byte{{0}, {1}}},
{name: "slice with duplicate elements", in: [][]byte{{0}, {1}, {1}, {0}, {2}}, expected: [][]byte{{0}, {1}, {2}}},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
require.Equal(t, tc.expected, DeduplicateAny(tc.in, bytes.Equal))
})
}
}