This repository has been archived by the owner on Jan 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 489
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ensure bindViper is called before fetching kubeconfig
Signed-off-by: Wayne Witzel III <[email protected]>
- Loading branch information
Showing
2 changed files
with
41 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
Copyright (c) 2019 the Octant contributors. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package commands | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_bindViper_KUBECONFIG(t *testing.T) { | ||
cmd := &cobra.Command{} | ||
|
||
expected := "/testdata/kubeconfig.yml" | ||
os.Setenv("KUBECONFIG", expected) | ||
defer os.Unsetenv("KUBECONFIG") | ||
|
||
// Before bindViper | ||
actual := viper.GetString("kubeconfig") | ||
assert.Equal(t, "", actual) | ||
|
||
err := bindViper(cmd) | ||
require.NoError(t, err) | ||
|
||
// After bindViper | ||
actual = viper.GetString("kubeconfig") | ||
assert.Equal(t, expected, actual) | ||
} |