dd0e8eec14
* copyright headers for agent folder * Ignore test data files * fix proto files and remove headers in agent/uiserver folder * ignore deep-copy files
47 lines
1 KiB
Go
47 lines
1 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
package wanfed
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestSplitNodeName(t *testing.T) {
|
|
type testcase struct {
|
|
nodeName string
|
|
expectShortName string
|
|
expectDC string
|
|
expectErr bool
|
|
}
|
|
|
|
cases := []testcase{
|
|
// bad
|
|
{nodeName: "", expectErr: true},
|
|
{nodeName: "foo", expectErr: true},
|
|
{nodeName: "foo.bar.baz", expectErr: true},
|
|
// good
|
|
{nodeName: "foo.bar", expectShortName: "foo", expectDC: "bar"},
|
|
// weird
|
|
{nodeName: ".bar", expectShortName: "", expectDC: "bar"},
|
|
}
|
|
|
|
for _, tc := range cases {
|
|
tc := tc
|
|
t.Run(tc.nodeName, func(t *testing.T) {
|
|
gotShortName, gotDC, gotErr := SplitNodeName(tc.nodeName)
|
|
if tc.expectErr {
|
|
require.Error(t, gotErr)
|
|
require.Empty(t, gotShortName)
|
|
require.Empty(t, gotDC)
|
|
} else {
|
|
require.NoError(t, gotErr)
|
|
require.Equal(t, tc.expectShortName, gotShortName)
|
|
require.Equal(t, tc.expectDC, gotDC)
|
|
}
|
|
})
|
|
}
|
|
}
|