github.com/ironcore-dev/gardener-extension-provider-ironcore@v0.3.2-0.20240314231816-8336447fb9a0/pkg/apis/ironcore/validation/infrastructure_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 . "github.com/onsi/gomega/gstruct" 10 corev1 "k8s.io/api/core/v1" 11 "k8s.io/apimachinery/pkg/util/validation/field" 12 13 apisironcore "github.com/ironcore-dev/gardener-extension-provider-ironcore/pkg/apis/ironcore" 14 ) 15 16 var _ = Describe("InfrastructureConfig validation", func() { 17 var ( 18 infra *apisironcore.InfrastructureConfig 19 fldPath *field.Path 20 networkName = "test-network" 21 ) 22 23 BeforeEach(func() { 24 infra = &apisironcore.InfrastructureConfig{ 25 NetworkRef: &corev1.LocalObjectReference{ 26 Name: networkName, 27 }, 28 } 29 }) 30 31 Describe("#ValidateInfrastructureConfig", func() { 32 It("should return no errors for a valid configuration", func() { 33 Expect(ValidateInfrastructureConfig(infra, nil, nil, nil, fldPath)).To(BeEmpty()) 34 }) 35 36 It("should fail with invalid network reference", func() { 37 infra.NetworkRef.Name = "my%network" 38 39 errorList := ValidateInfrastructureConfig(infra, nil, nil, nil, fldPath) 40 41 Expect(errorList).To(ConsistOf( 42 PointTo(MatchFields(IgnoreExtras, Fields{ 43 "Type": Equal(field.ErrorTypeInvalid), 44 "Field": Equal("networkRef.name"), 45 })), 46 )) 47 }) 48 }) 49 50 Describe("#ValidateInfrastructureConfigUpdate", func() { 51 It("should return no errors for an unchanged config", func() { 52 Expect(ValidateInfrastructureConfigUpdate(infra, infra, fldPath)).To(BeEmpty()) 53 }) 54 }) 55 })