forked from gardener/gardener
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathkubeconfig_test.go
More file actions
77 lines (62 loc) · 2.06 KB
/
kubeconfig_test.go
File metadata and controls
77 lines (62 loc) · 2.06 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// SPDX-FileCopyrightText: SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0
package secrets_test
import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"k8s.io/apimachinery/pkg/runtime"
clientcmdlatest "k8s.io/client-go/tools/clientcmd/api/latest"
clientcmdv1 "k8s.io/client-go/tools/clientcmd/api/v1"
kubernetesutils "github.com/gardener/gardener/pkg/utils/kubernetes"
. "github.com/gardener/gardener/pkg/utils/secrets"
)
var _ = Describe("Kubeconfig Secrets", func() {
var (
name = "bundle"
contextName = "shoot--foo--bar"
cluster = clientcmdv1.Cluster{Server: "server", CertificateAuthority: "/some/path"}
authInfo = clientcmdv1.AuthInfo{Token: "token"}
namespace = "default"
)
Describe("Configuration", func() {
var config *KubeconfigSecretConfig
BeforeEach(func() {
config = &KubeconfigSecretConfig{
Name: name,
ContextName: contextName,
Cluster: cluster,
AuthInfo: authInfo,
Namespace: namespace,
}
})
Describe("#GetName", func() {
It("should return the name", func() {
Expect(config.GetName()).To(Equal(name))
})
})
Describe("#Generate", func() {
It("should generate the kubeconfig", func() {
obj, err := config.Generate()
Expect(err).NotTo(HaveOccurred())
kubeconfig, ok := obj.(*Kubeconfig)
Expect(ok).To(BeTrue())
expected := kubernetesutils.NewKubeconfig(contextName, cluster, authInfo)
expected.Contexts[0].Context.Namespace = namespace
Expect(kubeconfig.Name).To(Equal(name))
Expect(kubeconfig.Kubeconfig).To(Equal(expected))
})
})
Describe("#SecretData", func() {
It("should return the correct data map", func() {
obj, err := config.Generate()
Expect(err).NotTo(HaveOccurred())
kubeconfig, ok := obj.(*Kubeconfig)
Expect(ok).To(BeTrue())
raw, err := runtime.Encode(clientcmdlatest.Codec, kubeconfig.Kubeconfig)
Expect(err).NotTo(HaveOccurred())
Expect(kubeconfig.SecretData()).To(Equal(map[string][]byte{"kubeconfig": raw}))
})
})
})
})