-
Notifications
You must be signed in to change notification settings - Fork 548
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When interating with the kubeconfig it can be expected that a user may have the KUBECONFIG environment variable set, so we need to use it when appropriate. Closes #5091 Signed-off-by: Tim Jones <[email protected]>
- Loading branch information
Showing
4 changed files
with
77 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// 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/internal/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) | ||
}) | ||
} | ||
} |