-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3820f98
commit 4177381
Showing
5 changed files
with
180 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
apis/core/v1alpha1/targettypes/kubernetes_cluster_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package targettypes_test | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/gardener/landscaper/apis/core/v1alpha1" | ||
"github.com/gardener/landscaper/apis/core/v1alpha1/targettypes" | ||
"k8s.io/utils/ptr" | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestConfig(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Types Testing") | ||
} | ||
|
||
var _ = Describe("Kubernetes Cluster Target Types", func() { | ||
|
||
It("should marshal a kubeconfig", func() { | ||
targetConfig := &targettypes.KubernetesClusterTargetConfig{ | ||
Kubeconfig: targettypes.ValueRef{ | ||
StrVal: ptr.To("test-kubeconfig"), | ||
}, | ||
} | ||
targetConfigJSON, err := json.Marshal(targetConfig) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(targetConfigJSON).To(MatchJSON(`{"kubeconfig":"test-kubeconfig"}`)) | ||
}) | ||
|
||
It("should unmarshal a kubeconfig", func() { | ||
configJSON := []byte(`{"kubeconfig":"test-kubeconfig"}`) | ||
config := &targettypes.KubernetesClusterTargetConfig{} | ||
Expect(json.Unmarshal(configJSON, config)).To(Succeed()) | ||
Expect(config).To(Equal(&targettypes.KubernetesClusterTargetConfig{ | ||
Kubeconfig: targettypes.ValueRef{ | ||
StrVal: ptr.To("test-kubeconfig"), | ||
}, | ||
})) | ||
}) | ||
|
||
It("should marshal an old secretRef", func() { | ||
targetConfig := &targettypes.KubernetesClusterTargetConfig{ | ||
Kubeconfig: targettypes.ValueRef{ | ||
SecretRef: &v1alpha1.SecretReference{ | ||
ObjectReference: v1alpha1.ObjectReference{ | ||
Name: "test-secret-name", | ||
Namespace: "test-namespace", | ||
}, | ||
Key: "test-key", | ||
}, | ||
}, | ||
} | ||
targetConfigBytes, err := json.Marshal(targetConfig) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(targetConfigBytes).To(MatchJSON(`{"kubeconfig":{"secretRef":{"name":"test-secret-name","namespace":"test-namespace","key":"test-key"}}}`)) | ||
}) | ||
|
||
It("should unmarshal an old secretRef", func() { | ||
configJSON := []byte(`{"kubeconfig":{"secretRef":{"name":"test-secret-name","namespace":"test-namespace","key":"test-key"}}}`) | ||
config := &targettypes.KubernetesClusterTargetConfig{} | ||
Expect(json.Unmarshal(configJSON, config)).To(Succeed()) | ||
Expect(config).To(Equal(&targettypes.KubernetesClusterTargetConfig{ | ||
Kubeconfig: targettypes.ValueRef{ | ||
SecretRef: &v1alpha1.SecretReference{ | ||
ObjectReference: v1alpha1.ObjectReference{ | ||
Name: "test-secret-name", | ||
Namespace: "test-namespace", | ||
}, | ||
Key: "test-key", | ||
}, | ||
}, | ||
})) | ||
}) | ||
|
||
It("should marshal an oidc config", func() { | ||
targetConfig := &targettypes.KubernetesClusterTargetConfig{ | ||
OIDCConfig: &targettypes.OIDCConfig{ | ||
Server: "test-server", | ||
CACertificate: []byte("test-cert"), | ||
ServiceAccount: "test-account", | ||
Audience: []string{"test-audience"}, | ||
}, | ||
} | ||
targetConfigJSON, err := json.Marshal(targetConfig) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(targetConfigJSON).To(MatchJSON(`{"kubeconfig":{},"oidcConfig":{"server":"test-server","caCertificate":"dGVzdC1jZXJ0","serviceAccount":"test-account","audience":["test-audience"]}}`)) | ||
}) | ||
|
||
It("should unmarshal an oidc config", func() { | ||
configJSON := []byte(`{"kubeconfig":{},"oidcConfig":{"server":"test-server","caCertificate":"dGVzdC1jZXJ0","serviceAccount":"test-account","audience":["test-audience"]}}`) | ||
config := &targettypes.KubernetesClusterTargetConfig{} | ||
Expect(json.Unmarshal(configJSON, config)).To(Succeed()) | ||
Expect(config).To(Equal(&targettypes.KubernetesClusterTargetConfig{ | ||
Kubeconfig: targettypes.ValueRef{ | ||
StrVal: ptr.To("{}"), | ||
}, | ||
OIDCConfig: &targettypes.OIDCConfig{ | ||
Server: "test-server", | ||
CACertificate: []byte("test-cert"), | ||
ServiceAccount: "test-account", | ||
Audience: []string{"test-audience"}, | ||
}, | ||
})) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters