mirror of
https://github.com/gravitational/teleport.git
synced 2026-11-02 06:08:23 +08:00
- 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.
57 lines
1.7 KiB
Go
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))
|
|
})
|
|
}
|
|
}
|