Fix bugs for test pass, update tests

Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
This commit is contained in:
Ahmet Alp Balkan 2020-04-10 16:22:43 -07:00
parent 8ce95d4a00
commit 37441b648f
No known key found for this signature in database
GPG Key ID: 441833503E604E2C
4 changed files with 6 additions and 13 deletions

View File

@ -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)

View File

@ -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)
}

View File

@ -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

View File

@ -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" {