mirror of
https://github.com/ahmetb/kubectx.git
synced 2025-06-19 20:23:23 +00:00
Fix bugs for test pass, update tests
Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
This commit is contained in:
parent
8ce95d4a00
commit
37441b648f
@ -43,6 +43,9 @@ func parseKubeconfig(path string) (kubeconfig, error) {
|
||||
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return v, nil
|
||||
}
|
||||
return v, errors.Wrap(err, "file open error")
|
||||
}
|
||||
err = yaml.NewDecoder(f).Decode(&v)
|
||||
|
@ -38,7 +38,7 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
case RenameOp:
|
||||
if err := rename(v.Old, v.New); err != nil {
|
||||
if err := renameContexts(v.Old, v.New); err != nil {
|
||||
printError("failed to rename: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ func parseRenameSyntax(v string) (string, string, bool) {
|
||||
// rename changes the old (NAME or '.' for current-context)
|
||||
// to the "new" value. If the old refers to the current-context,
|
||||
// current-context preference is also updated.
|
||||
func rename(old, new string) error {
|
||||
func renameContexts(old, new string) error {
|
||||
f, rootNode, err := openKubeconfig()
|
||||
if err != nil {
|
||||
return nil
|
||||
|
@ -4,16 +4,6 @@ COMMAND="$BATS_TEST_DIRNAME/../kubectx"
|
||||
|
||||
load common
|
||||
|
||||
@test "no kubectl detected" {
|
||||
OLDPATH="$PATH"
|
||||
PATH=/bin
|
||||
run ${COMMAND}
|
||||
echo "$output"
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" = "kubectl is not installed" ]]
|
||||
PATH="$OLDPATH"
|
||||
}
|
||||
|
||||
@test "--help should not fail" {
|
||||
run ${COMMAND} --help
|
||||
echo "$output"
|
||||
@ -32,7 +22,7 @@ load common
|
||||
run ${COMMAND} -
|
||||
echo "$output"
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" = "error: No previous context found." ]]
|
||||
[[ $output = *"no previous context found" ]]
|
||||
}
|
||||
|
||||
@test "list contexts when no kubeconfig exists" {
|
||||
|
Loading…
Reference in New Issue
Block a user