mirror of
https://github.com/ahmetb/kubectx.git
synced 2025-05-22 15:13:12 +00:00
* stop using XDG_CACHE_HOME as home directory XDG_CACHE_HOME is not a substitute for $HOME, see [1]. [1]: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html * fix bats testing setup/teardown since cmdutil.Homedir() would treat $XDG_CACHE_HOME as $HOME, deleting $XDG_CACHE_HOME would wipe out previous kubens state. now that we're not doing that, we need to make a real synthetic $HOME and clear it out so that $HOME/.kube/kubens doesn't persist between runs.
33 lines
571 B
Bash
33 lines
571 B
Bash
#!/usr/bin/env bats
|
|
|
|
# bats setup function
|
|
setup() {
|
|
TEMP_HOME="$(mktemp -d)"
|
|
export TEMP_HOME
|
|
export HOME=$TEMP_HOME
|
|
export KUBECONFIG="${TEMP_HOME}/config"
|
|
}
|
|
|
|
# bats teardown function
|
|
teardown() {
|
|
rm -rf "$TEMP_HOME"
|
|
}
|
|
|
|
use_config() {
|
|
cp "$BATS_TEST_DIRNAME/testdata/$1" $KUBECONFIG
|
|
}
|
|
|
|
# wrappers around "kubectl config" command
|
|
|
|
get_namespace() {
|
|
kubectl config view -o=jsonpath="{.contexts[?(@.name==\"$(get_context)\")].context.namespace}"
|
|
}
|
|
|
|
get_context() {
|
|
kubectl config current-context
|
|
}
|
|
|
|
switch_context() {
|
|
kubectl config use-context "${1}"
|
|
}
|