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