-
Notifications
You must be signed in to change notification settings - Fork 2
/
namespace_test.go
53 lines (49 loc) · 1.22 KB
/
namespace_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
47
48
49
50
51
52
53
package main
import (
"testing"
)
func TestExtractCurrentNamespace(t *testing.T) {
kubeconfig := []byte(`apiVersion: v1
clusters:
- cluster:
certificate-authority: /Users/gerald/.minikube/ca.crt
server: https://192.168.99.100:8443
name: 192-168-99-100:8443
- cluster:
certificate-authority: /Users/gerald/.minikube/ca.crt
server: https://192.168.99.100:8443
name: minikube
contexts:
- context:
cluster: 192-168-99-100:8443
namespace: default
user: /192-168-99-100:8443
name: default/192-168-99-100:8443/
- context:
cluster: minikube
namespace: kube-system
user: minikube
name: minikube
current-context: minikube
kind: Config
preferences: {}
users:
- name: /192-168-99-100:8443
user:
client-certificate: /Users/gerald/.minikube/client.crt
client-key: /Users/gerald/.minikube/client.key
- name: minikube
user:
client-certificate: /Users/gerald/.minikube/client.crt
client-key: /Users/gerald/.minikube/client.key
`)
namespace, err := extractCurrentNamespace(kubeconfig)
if err != nil {
t.Errorf("Must accept valid kubeconfig: %v", err)
return
}
expected := "kube-system"
if namespace != "kube-system" {
t.Errorf("Expected namespace %s, got %s", expected, namespace)
}
}