Skip to content

Commit

Permalink
Reset KUBERNETES env variables to ensure there's no Kube connection f…
Browse files Browse the repository at this point in the history
…or unit test (#379)
  • Loading branch information
cardil authored Oct 23, 2024
1 parent a6872a8 commit 72533af
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion pkg/k8s/kubeclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
func TestNewClients(t *testing.T) {
basic, err := clientcmd.NewClientConfigFromBytes([]byte(basicKubeconfig))
assert.NilError(t, err)
t.Setenv("KUBECONFIG", "/var/blackhole/not-existing.yaml")
emptyKubeconfigEnv(t)
tcs := []newClientsTestCase{{
name: "nil",
wantErr: k8s.ErrNoKubernetesConnection,
Expand All @@ -46,6 +46,20 @@ func TestNewClients(t *testing.T) {
}
}

func emptyKubeconfigEnv(t *testing.T) {
t.Helper()
t.Setenv("KUBECONFIG", "/var/blackhole/not-existing.yaml")
t.Setenv("KUBERNETES_MASTER", "")
t.Setenv("KUBERNETES_SERVICE_PORT_HTTPS", "")
t.Setenv("KUBERNETES_SERVICE_PORT", "")
t.Setenv("KUBERNETES_PORT_443_TCP", "")
t.Setenv("KUBERNETES_PORT_443_TCP_PROTO", "")
t.Setenv("KUBERNETES_PORT_443_TCP_ADDR", "")
t.Setenv("KUBERNETES_SERVICE_HOST", "")
t.Setenv("KUBERNETES_PORT", "")
t.Setenv("KUBERNETES_PORT_443_TCP_PORT", "")
}

func just(cc clientcmd.ClientConfig) func() (clientcmd.ClientConfig, error) {
return func() (clientcmd.ClientConfig, error) {
return cc, nil
Expand Down

0 comments on commit 72533af

Please sign in to comment.