github.com/ironcore-dev/gardener-extension-provider-ironcore@v0.3.2-0.20240314231816-8336447fb9a0/pkg/apis/ironcore/validation/secret_test.go (about) 1 // SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and IronCore contributors 2 // SPDX-License-Identifier: Apache-2.0 3 4 package validation 5 6 import ( 7 . "github.com/onsi/ginkgo/v2" 8 . "github.com/onsi/gomega" 9 gomegatypes "github.com/onsi/gomega/types" 10 corev1 "k8s.io/api/core/v1" 11 ) 12 13 var _ = Describe("Secret validation", func() { 14 DescribeTable("#ValidateCloudProviderSecret", 15 func(data map[string][]byte, matcher gomegatypes.GomegaMatcher) { 16 secret := &corev1.Secret{ 17 Data: data, 18 } 19 err := ValidateCloudProviderSecret(secret) 20 Expect(err).To(matcher) 21 }, 22 Entry("should return error when the token field is missing", 23 map[string][]byte{ 24 "namespace": []byte("foo"), 25 "username": []byte("admin"), 26 }, HaveOccurred()), 27 Entry("should return error when the namespace field is missing", 28 map[string][]byte{ 29 "token": []byte("foo"), 30 "username": []byte("admin"), 31 }, HaveOccurred()), 32 Entry("should return an error when the namespace name is invalid", 33 map[string][]byte{ 34 "namespace": []byte("%foo"), 35 "token": []byte("foo"), 36 "username": []byte("admin"), 37 }, HaveOccurred()), 38 Entry("should return an error when the username is missing", 39 map[string][]byte{ 40 "namespace": []byte("foo"), 41 "token": []byte("bar"), 42 }, HaveOccurred()), 43 Entry("should return no error if the secret is valid", 44 map[string][]byte{ 45 "namespace": []byte("foo"), 46 "token": []byte("foo"), 47 "username": []byte("admin"), 48 }, 49 Not(HaveOccurred())), 50 ) 51 })