-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_test.go
46 lines (38 loc) · 1.29 KB
/
client_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package ezdeploy
import (
"encoding/base64"
"github.com/stretchr/testify/require"
"os"
"path/filepath"
"testing"
)
func TestResolveKubernetesClient(t *testing.T) {
home, err := os.UserHomeDir()
require.NoError(t, err)
src, err := ResolveKubernetesClient("")
require.NoError(t, err)
require.Equal(t, filepath.Join(home, ".kube", "config"), src.KubeconfigPath)
require.False(t, src.InCluster)
require.Empty(t, src.TemporaryDir)
err = os.Setenv("KUBECONFIG_BASE64", base64.StdEncoding.EncodeToString([]byte("hello")))
require.NoError(t, err)
src, err = ResolveKubernetesClient("")
require.NoError(t, err)
require.False(t, src.InCluster)
require.DirExists(t, src.TemporaryDir)
buf, err := os.ReadFile(src.KubeconfigPath)
require.NoError(t, err)
require.Equal(t, "hello", string(buf))
src.CleanUp()
require.NoDirExists(t, src.TemporaryDir)
err = os.Setenv("KUBECONFIG", "~/.kube/config333")
require.NoError(t, err)
src, err = ResolveKubernetesClient("~/.kube/config222")
require.NoError(t, err)
require.Equal(t, filepath.Join(home, ".kube", "config222"), src.KubeconfigPath)
require.Empty(t, src.TemporaryDir)
src, err = ResolveKubernetesClient("")
require.NoError(t, err)
require.Equal(t, filepath.Join(home, ".kube", "config333"), src.KubeconfigPath)
require.Empty(t, src.TemporaryDir)
}