sigs.k8s.io/cluster-api-provider-aws@v1.5.5/exp/api/v1alpha3/conversion_test.go (about) 1 /* 2 Copyright 2021 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package v1alpha3 18 19 import ( 20 "testing" 21 22 fuzz "github.com/google/gofuzz" 23 . "github.com/onsi/gomega" 24 "k8s.io/apimachinery/pkg/api/apitesting/fuzzer" 25 "k8s.io/apimachinery/pkg/runtime" 26 runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer" 27 28 "sigs.k8s.io/cluster-api-provider-aws/exp/api/v1beta1" 29 utilconversion "sigs.k8s.io/cluster-api/util/conversion" 30 ) 31 32 func fuzzFuncs(_ runtimeserializer.CodecFactory) []interface{} { 33 return []interface{}{ 34 AWSMachinePoolFuzzer, 35 } 36 } 37 38 func AWSMachinePoolFuzzer(obj *AWSMachinePool, c fuzz.Continue) { 39 c.FuzzNoCustom(obj) 40 41 // AWSMachinePool.Spec.AWSLaunchTemplate.AMI.ARN and AWSMachinePool.Spec.AWSLaunchTemplate.AMI.Filters has been removed in v1beta1, so setting it to nil in order to avoid v1alpha3 --> v1beta1 --> v1alpha3 round trip errors. 42 obj.Spec.AWSLaunchTemplate.AMI.ARN = nil 43 obj.Spec.AWSLaunchTemplate.AMI.Filters = nil 44 } 45 46 func TestFuzzyConversion(t *testing.T) { 47 g := NewWithT(t) 48 scheme := runtime.NewScheme() 49 g.Expect(AddToScheme(scheme)).To(Succeed()) 50 g.Expect(v1beta1.AddToScheme(scheme)).To(Succeed()) 51 52 t.Run("for AWSMachinePool", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{ 53 Scheme: scheme, 54 Hub: &v1beta1.AWSMachinePool{}, 55 Spoke: &AWSMachinePool{}, 56 FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzFuncs}, 57 })) 58 59 t.Run("for AWSManagedMachinePool", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{ 60 Scheme: scheme, 61 Hub: &v1beta1.AWSManagedMachinePool{}, 62 Spoke: &AWSManagedMachinePool{}, 63 })) 64 65 t.Run("for AWSFargateProfile", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{ 66 Scheme: scheme, 67 Hub: &v1beta1.AWSFargateProfile{}, 68 Spoke: &AWSFargateProfile{}, 69 })) 70 }