talos/pkg/kubeconfig/kubeconfig_test.go
Utku Ozdemir ae3840dbc3
refactor: move kubeconfig package under public api
Move the kubeconfig package under pkg/ so that other projects can reuse parts of it.

Signed-off-by: Utku Ozdemir <utku.ozdemir@siderolabs.com>
2022-07-01 19:22:16 +02:00

61 lines
1.3 KiB
Go

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package kubeconfig_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/talos-systems/talos/pkg/kubeconfig"
)
func TestSinglePath(t *testing.T) {
expectedDefaultPath, err := kubeconfig.DefaultPath()
assert.NoError(t, err)
for _, tt := range []struct {
name string
envVar string
shouldErr bool
expected string
}{
{
name: "NoKUBECONFIGSet",
shouldErr: false,
expected: expectedDefaultPath,
},
{
name: "UseKUBECONFIGSet",
envVar: "/my/custom/path/to/kubeconfig",
shouldErr: false,
expected: "/my/custom/path/to/kubeconfig",
},
{
name: "MultiKUBECONFIGSet",
envVar: "/my/custom/path/to/kubeconfig:/another/path/to/kubeconfig:/foo/bar/kubeconfig",
shouldErr: true,
},
} {
tt := tt
t.Run(tt.name, func(t *testing.T) {
if tt.envVar != "" {
t.Setenv("KUBECONFIG", tt.envVar)
}
result, err := kubeconfig.SinglePath()
if tt.shouldErr {
require.Error(t, err)
} else {
require.NoError(t, err)
}
assert.Equal(t, tt.expected, result)
})
}
}