From 016c2768db94c95e28d5c925858883129e9cd795 Mon Sep 17 00:00:00 2001 From: Ville Aikas Date: Tue, 27 Oct 2020 12:19:58 +0200 Subject: [PATCH 1/2] move fuzzer code to _test files Signed-off-by: Ville Aikas --- pkg/apis/duck/v1/{ => test}/fuzzer.go | 11 +-- pkg/apis/eventing/v1/fuzzer.go | 55 -------------- pkg/apis/eventing/v1/roundtrip_test.go | 33 +++++++++ pkg/apis/eventing/v1beta1/roundtrip_test.go | 42 +++++++++-- pkg/apis/flows/v1/fuzzer.go | 55 -------------- pkg/apis/flows/v1/roundtrip_test.go | 34 +++++++++ pkg/apis/flows/v1beta1/roundtrip_test.go | 42 +++++++++-- pkg/apis/messaging/v1/fuzzer.go | 76 -------------------- pkg/apis/messaging/v1/roundtrip_test.go | 55 ++++++++++++++ pkg/apis/messaging/v1beta1/roundtrip_test.go | 63 ++++++++++++++-- 10 files changed, 263 insertions(+), 203 deletions(-) rename pkg/apis/duck/v1/{ => test}/fuzzer.go (84%) delete mode 100644 pkg/apis/eventing/v1/fuzzer.go delete mode 100644 pkg/apis/flows/v1/fuzzer.go delete mode 100644 pkg/apis/messaging/v1/fuzzer.go diff --git a/pkg/apis/duck/v1/fuzzer.go b/pkg/apis/duck/v1/test/fuzzer.go similarity index 84% rename from pkg/apis/duck/v1/fuzzer.go rename to pkg/apis/duck/v1/test/fuzzer.go index 919324b9759..7d7348ec5d0 100644 --- a/pkg/apis/duck/v1/fuzzer.go +++ b/pkg/apis/duck/v1/test/fuzzer.go @@ -14,9 +14,10 @@ See the License for the specific language governing permissions and limitations under the License. */ -package v1 +package test import ( + "knative.dev/eventing/pkg/apis/duck/v1" "math/rand" fuzz "github.com/google/gofuzz" @@ -24,9 +25,9 @@ import ( "k8s.io/apimachinery/pkg/runtime/serializer" ) -var linear = BackoffPolicyLinear -var exponential = BackoffPolicyExponential -var bops = []*BackoffPolicyType{nil, &linear, &exponential} +var linear = v1.BackoffPolicyLinear +var exponential = v1.BackoffPolicyExponential +var bops = []*v1.BackoffPolicyType{nil, &linear, &exponential} // FuzzerFuncs includes fuzzing funcs for knative.dev/duck v1 types // In particular it makes sure that Delivery has only valid BackoffPolicyType in it. @@ -36,7 +37,7 @@ var bops = []*BackoffPolicyType{nil, &linear, &exponential} var FuzzerFuncs = fuzzer.MergeFuzzerFuncs( func(codecs serializer.CodecFactory) []interface{} { return []interface{}{ - func(ds *DeliverySpec, c fuzz.Continue) { + func(ds *v1.DeliverySpec, c fuzz.Continue) { c.FuzzNoCustom(ds) // fuzz the DeliverySpec if ds.BackoffPolicy != nil && *ds.BackoffPolicy == "" { ds.BackoffPolicy = nil diff --git a/pkg/apis/eventing/v1/fuzzer.go b/pkg/apis/eventing/v1/fuzzer.go deleted file mode 100644 index ef53d194bd6..00000000000 --- a/pkg/apis/eventing/v1/fuzzer.go +++ /dev/null @@ -1,55 +0,0 @@ -/* -Copyright 2020 The Knative Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package v1 - -import ( - fuzz "github.com/google/gofuzz" - "k8s.io/apimachinery/pkg/api/apitesting/fuzzer" - "k8s.io/apimachinery/pkg/runtime/serializer" - pkgfuzzer "knative.dev/pkg/apis/testing/fuzzer" -) - -// FuzzerFuncs includes fuzzing funcs for knative.dev/eventing v1 types -// -// For other examples see -// https://github.com/kubernetes/apimachinery/blob/master/pkg/apis/meta/fuzzer/fuzzer.go -var FuzzerFuncs = fuzzer.MergeFuzzerFuncs( - func(codecs serializer.CodecFactory) []interface{} { - return []interface{}{ - func(s *TriggerStatus, c fuzz.Continue) { - c.FuzzNoCustom(s) // fuzz the status object - - // Clear the random fuzzed condition - s.Status.SetConditions(nil) - - // Fuzz the known conditions except their type value - s.InitializeConditions() - pkgfuzzer.FuzzConditions(&s.Status, c) - }, - func(s *BrokerStatus, c fuzz.Continue) { - c.FuzzNoCustom(s) // fuzz the status object - - // Clear the random fuzzed condition - s.Status.SetConditions(nil) - - // Fuzz the known conditions except their type value - s.InitializeConditions() - pkgfuzzer.FuzzConditions(&s.Status, c) - }, - } - }, -) diff --git a/pkg/apis/eventing/v1/roundtrip_test.go b/pkg/apis/eventing/v1/roundtrip_test.go index c45716db7c5..3cc19af8e19 100644 --- a/pkg/apis/eventing/v1/roundtrip_test.go +++ b/pkg/apis/eventing/v1/roundtrip_test.go @@ -17,6 +17,8 @@ limitations under the License. package v1 import ( + fuzz "github.com/google/gofuzz" + "k8s.io/apimachinery/pkg/runtime/serializer" "testing" "k8s.io/apimachinery/pkg/api/apitesting/fuzzer" @@ -26,6 +28,37 @@ import ( "knative.dev/pkg/apis/testing/roundtrip" ) +// FuzzerFuncs includes fuzzing funcs for knative.dev/eventing v1 types +// +// For other examples see +// https://github.com/kubernetes/apimachinery/blob/master/pkg/apis/meta/fuzzer/fuzzer.go +var FuzzerFuncs = fuzzer.MergeFuzzerFuncs( + func(codecs serializer.CodecFactory) []interface{} { + return []interface{}{ + func(s *TriggerStatus, c fuzz.Continue) { + c.FuzzNoCustom(s) // fuzz the status object + + // Clear the random fuzzed condition + s.Status.SetConditions(nil) + + // Fuzz the known conditions except their type value + s.InitializeConditions() + pkgfuzzer.FuzzConditions(&s.Status, c) + }, + func(s *BrokerStatus, c fuzz.Continue) { + c.FuzzNoCustom(s) // fuzz the status object + + // Clear the random fuzzed condition + s.Status.SetConditions(nil) + + // Fuzz the known conditions except their type value + s.InitializeConditions() + pkgfuzzer.FuzzConditions(&s.Status, c) + }, + } + }, +) + func TestEventingRoundTripTypesToJSON(t *testing.T) { scheme := runtime.NewScheme() utilruntime.Must(AddToScheme(scheme)) diff --git a/pkg/apis/eventing/v1beta1/roundtrip_test.go b/pkg/apis/eventing/v1beta1/roundtrip_test.go index 044e1deb488..817a4ad9d2a 100644 --- a/pkg/apis/eventing/v1beta1/roundtrip_test.go +++ b/pkg/apis/eventing/v1beta1/roundtrip_test.go @@ -19,22 +19,56 @@ package v1beta1 import ( "testing" + fuzz "github.com/google/gofuzz" + "k8s.io/apimachinery/pkg/runtime/serializer" + "knative.dev/eventing/pkg/apis/duck/v1/test" + "k8s.io/apimachinery/pkg/api/apitesting/fuzzer" "k8s.io/apimachinery/pkg/runtime" utilruntime "k8s.io/apimachinery/pkg/util/runtime" - duckerfuzzer "knative.dev/eventing/pkg/apis/duck/v1" v1 "knative.dev/eventing/pkg/apis/eventing/v1" pkgfuzzer "knative.dev/pkg/apis/testing/fuzzer" "knative.dev/pkg/apis/testing/roundtrip" ) +// FuzzerFuncs includes fuzzing funcs for knative.dev/eventing v1 types +// +// For other examples see +// https://github.com/kubernetes/apimachinery/blob/master/pkg/apis/meta/fuzzer/fuzzer.go +var FuzzerFuncs = fuzzer.MergeFuzzerFuncs( + func(codecs serializer.CodecFactory) []interface{} { + return []interface{}{ + func(s *v1.TriggerStatus, c fuzz.Continue) { + c.FuzzNoCustom(s) // fuzz the status object + + // Clear the random fuzzed condition + s.Status.SetConditions(nil) + + // Fuzz the known conditions except their type value + s.InitializeConditions() + pkgfuzzer.FuzzConditions(&s.Status, c) + }, + func(s *v1.BrokerStatus, c fuzz.Continue) { + c.FuzzNoCustom(s) // fuzz the status object + + // Clear the random fuzzed condition + s.Status.SetConditions(nil) + + // Fuzz the known conditions except their type value + s.InitializeConditions() + pkgfuzzer.FuzzConditions(&s.Status, c) + }, + } + }, +) + func TestEventingRoundTripTypesToJSON(t *testing.T) { scheme := runtime.NewScheme() utilruntime.Must(AddToScheme(scheme)) fuzzerFuncs := fuzzer.MergeFuzzerFuncs( pkgfuzzer.Funcs, - v1.FuzzerFuncs, + FuzzerFuncs, ) roundtrip.ExternalTypesViaJSON(t, scheme, fuzzerFuncs) } @@ -58,8 +92,8 @@ func TestEventingRoundTripTypesToBetaHub(t *testing.T) { fuzzerFuncs := fuzzer.MergeFuzzerFuncs( pkgfuzzer.Funcs, - v1.FuzzerFuncs, - duckerfuzzer.FuzzerFuncs, + FuzzerFuncs, + test.FuzzerFuncs, ) roundtrip.ExternalTypesViaHub(t, scheme, hubs, fuzzerFuncs) diff --git a/pkg/apis/flows/v1/fuzzer.go b/pkg/apis/flows/v1/fuzzer.go deleted file mode 100644 index f859f94c45c..00000000000 --- a/pkg/apis/flows/v1/fuzzer.go +++ /dev/null @@ -1,55 +0,0 @@ -/* -Copyright 2020 The Knative Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package v1 - -import ( - fuzz "github.com/google/gofuzz" - "k8s.io/apimachinery/pkg/api/apitesting/fuzzer" - "k8s.io/apimachinery/pkg/runtime/serializer" - pkgfuzzer "knative.dev/pkg/apis/testing/fuzzer" -) - -// FuzzerFuncs includes fuzzing funcs for knative.dev/flows v1 types -// -// For other examples see -// https://github.com/kubernetes/apimachinery/blob/master/pkg/apis/meta/fuzzer/fuzzer.go -var FuzzerFuncs = fuzzer.MergeFuzzerFuncs( - func(codecs serializer.CodecFactory) []interface{} { - return []interface{}{ - func(s *SequenceStatus, c fuzz.Continue) { - c.FuzzNoCustom(s) // fuzz the status object - - // Clear the random fuzzed condition - s.Status.SetConditions(nil) - - // Fuzz the known conditions except their type value - s.InitializeConditions() - pkgfuzzer.FuzzConditions(&s.Status, c) - }, - func(s *ParallelStatus, c fuzz.Continue) { - c.FuzzNoCustom(s) // fuzz the status object - - // Clear the random fuzzed condition - s.Status.SetConditions(nil) - - // Fuzz the known conditions except their type value - s.InitializeConditions() - pkgfuzzer.FuzzConditions(&s.Status, c) - }, - } - }, -) diff --git a/pkg/apis/flows/v1/roundtrip_test.go b/pkg/apis/flows/v1/roundtrip_test.go index c45716db7c5..1a2cb277e3d 100644 --- a/pkg/apis/flows/v1/roundtrip_test.go +++ b/pkg/apis/flows/v1/roundtrip_test.go @@ -19,6 +19,9 @@ package v1 import ( "testing" + fuzz "github.com/google/gofuzz" + "k8s.io/apimachinery/pkg/runtime/serializer" + "k8s.io/apimachinery/pkg/api/apitesting/fuzzer" "k8s.io/apimachinery/pkg/runtime" utilruntime "k8s.io/apimachinery/pkg/util/runtime" @@ -26,6 +29,37 @@ import ( "knative.dev/pkg/apis/testing/roundtrip" ) +// FuzzerFuncs includes fuzzing funcs for knative.dev/flows v1 types +// +// For other examples see +// https://github.com/kubernetes/apimachinery/blob/master/pkg/apis/meta/fuzzer/fuzzer.go +var FuzzerFuncs = fuzzer.MergeFuzzerFuncs( + func(codecs serializer.CodecFactory) []interface{} { + return []interface{}{ + func(s *SequenceStatus, c fuzz.Continue) { + c.FuzzNoCustom(s) // fuzz the status object + + // Clear the random fuzzed condition + s.Status.SetConditions(nil) + + // Fuzz the known conditions except their type value + s.InitializeConditions() + pkgfuzzer.FuzzConditions(&s.Status, c) + }, + func(s *ParallelStatus, c fuzz.Continue) { + c.FuzzNoCustom(s) // fuzz the status object + + // Clear the random fuzzed condition + s.Status.SetConditions(nil) + + // Fuzz the known conditions except their type value + s.InitializeConditions() + pkgfuzzer.FuzzConditions(&s.Status, c) + }, + } + }, +) + func TestEventingRoundTripTypesToJSON(t *testing.T) { scheme := runtime.NewScheme() utilruntime.Must(AddToScheme(scheme)) diff --git a/pkg/apis/flows/v1beta1/roundtrip_test.go b/pkg/apis/flows/v1beta1/roundtrip_test.go index e74bad900e5..9e3d93bee25 100644 --- a/pkg/apis/flows/v1beta1/roundtrip_test.go +++ b/pkg/apis/flows/v1beta1/roundtrip_test.go @@ -19,22 +19,56 @@ package v1beta1 import ( "testing" + fuzz "github.com/google/gofuzz" + "k8s.io/apimachinery/pkg/runtime/serializer" + "knative.dev/eventing/pkg/apis/duck/v1/test" + "k8s.io/apimachinery/pkg/api/apitesting/fuzzer" "k8s.io/apimachinery/pkg/runtime" utilruntime "k8s.io/apimachinery/pkg/util/runtime" - duckerfuzzer "knative.dev/eventing/pkg/apis/duck/v1" v1 "knative.dev/eventing/pkg/apis/flows/v1" pkgfuzzer "knative.dev/pkg/apis/testing/fuzzer" "knative.dev/pkg/apis/testing/roundtrip" ) +// FuzzerFuncs includes fuzzing funcs for knative.dev/flows v1 types +// +// For other examples see +// https://github.com/kubernetes/apimachinery/blob/master/pkg/apis/meta/fuzzer/fuzzer.go +var FuzzerFuncs = fuzzer.MergeFuzzerFuncs( + func(codecs serializer.CodecFactory) []interface{} { + return []interface{}{ + func(s *v1.SequenceStatus, c fuzz.Continue) { + c.FuzzNoCustom(s) // fuzz the status object + + // Clear the random fuzzed condition + s.Status.SetConditions(nil) + + // Fuzz the known conditions except their type value + s.InitializeConditions() + pkgfuzzer.FuzzConditions(&s.Status, c) + }, + func(s *v1.ParallelStatus, c fuzz.Continue) { + c.FuzzNoCustom(s) // fuzz the status object + + // Clear the random fuzzed condition + s.Status.SetConditions(nil) + + // Fuzz the known conditions except their type value + s.InitializeConditions() + pkgfuzzer.FuzzConditions(&s.Status, c) + }, + } + }, +) + func TestFlowsRoundTripTypesToJSON(t *testing.T) { scheme := runtime.NewScheme() utilruntime.Must(AddToScheme(scheme)) fuzzerFuncs := fuzzer.MergeFuzzerFuncs( pkgfuzzer.Funcs, - v1.FuzzerFuncs, + FuzzerFuncs, ) roundtrip.ExternalTypesViaJSON(t, scheme, fuzzerFuncs) } @@ -57,8 +91,8 @@ func TestFlowsRoundTripTypesToBetaHub(t *testing.T) { fuzzerFuncs := fuzzer.MergeFuzzerFuncs( pkgfuzzer.Funcs, - v1.FuzzerFuncs, - duckerfuzzer.FuzzerFuncs, + FuzzerFuncs, + test.FuzzerFuncs, ) roundtrip.ExternalTypesViaHub(t, scheme, hubs, fuzzerFuncs) diff --git a/pkg/apis/messaging/v1/fuzzer.go b/pkg/apis/messaging/v1/fuzzer.go deleted file mode 100644 index baecec17e62..00000000000 --- a/pkg/apis/messaging/v1/fuzzer.go +++ /dev/null @@ -1,76 +0,0 @@ -/* -Copyright 2020 The Knative Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package v1 - -import ( - fuzz "github.com/google/gofuzz" - "k8s.io/apimachinery/pkg/api/apitesting/fuzzer" - "k8s.io/apimachinery/pkg/runtime/serializer" - "knative.dev/eventing/pkg/apis/messaging" - pkgfuzzer "knative.dev/pkg/apis/testing/fuzzer" -) - -// FuzzerFuncs includes fuzzing funcs for knative.dev/messaging v1 types -// -// For other examples see -// https://github.com/kubernetes/apimachinery/blob/master/pkg/apis/meta/fuzzer/fuzzer.go -var FuzzerFuncs = fuzzer.MergeFuzzerFuncs( - func(codecs serializer.CodecFactory) []interface{} { - return []interface{}{ - func(ch *Channel, c fuzz.Continue) { - c.FuzzNoCustom(ch) // fuzz the Channel - if ch != nil { - if ch.Annotations == nil { - ch.Annotations = make(map[string]string) - } - ch.Annotations[messaging.SubscribableDuckVersionAnnotation] = "v1" - } - // Clear the random fuzzed condition - ch.Status.SetConditions(nil) - - // Fuzz the known conditions except their type value - ch.Status.InitializeConditions() - pkgfuzzer.FuzzConditions(&ch.Status, c) - }, - func(imc *InMemoryChannel, c fuzz.Continue) { - c.FuzzNoCustom(imc) // fuzz the InMemoryChannel - if imc != nil { - if imc.Annotations == nil { - imc.Annotations = make(map[string]string) - } - imc.Annotations[messaging.SubscribableDuckVersionAnnotation] = "v1" - } - // Clear the random fuzzed condition - imc.Status.SetConditions(nil) - - // Fuzz the known conditions except their type value - imc.Status.InitializeConditions() - pkgfuzzer.FuzzConditions(&imc.Status, c) - }, - func(s *SubscriptionStatus, c fuzz.Continue) { - c.FuzzNoCustom(s) // fuzz the status object - - // Clear the random fuzzed condition - s.Status.SetConditions(nil) - - // Fuzz the known conditions except their type value - s.InitializeConditions() - pkgfuzzer.FuzzConditions(&s.Status, c) - }, - } - }, -) diff --git a/pkg/apis/messaging/v1/roundtrip_test.go b/pkg/apis/messaging/v1/roundtrip_test.go index e1173e57a70..ecdfc2083c8 100644 --- a/pkg/apis/messaging/v1/roundtrip_test.go +++ b/pkg/apis/messaging/v1/roundtrip_test.go @@ -19,6 +19,10 @@ package v1 import ( "testing" + fuzz "github.com/google/gofuzz" + "k8s.io/apimachinery/pkg/runtime/serializer" + "knative.dev/eventing/pkg/apis/messaging" + "k8s.io/apimachinery/pkg/api/apitesting/fuzzer" "k8s.io/apimachinery/pkg/runtime" utilruntime "k8s.io/apimachinery/pkg/util/runtime" @@ -26,6 +30,57 @@ import ( "knative.dev/pkg/apis/testing/roundtrip" ) +// FuzzerFuncs includes fuzzing funcs for knative.dev/messaging v1 types +// +// For other examples see +// https://github.com/kubernetes/apimachinery/blob/master/pkg/apis/meta/fuzzer/fuzzer.go +var FuzzerFuncs = fuzzer.MergeFuzzerFuncs( + func(codecs serializer.CodecFactory) []interface{} { + return []interface{}{ + func(ch *Channel, c fuzz.Continue) { + c.FuzzNoCustom(ch) // fuzz the Channel + if ch != nil { + if ch.Annotations == nil { + ch.Annotations = make(map[string]string) + } + ch.Annotations[messaging.SubscribableDuckVersionAnnotation] = "v1" + } + // Clear the random fuzzed condition + ch.Status.SetConditions(nil) + + // Fuzz the known conditions except their type value + ch.Status.InitializeConditions() + pkgfuzzer.FuzzConditions(&ch.Status, c) + }, + func(imc *InMemoryChannel, c fuzz.Continue) { + c.FuzzNoCustom(imc) // fuzz the InMemoryChannel + if imc != nil { + if imc.Annotations == nil { + imc.Annotations = make(map[string]string) + } + imc.Annotations[messaging.SubscribableDuckVersionAnnotation] = "v1" + } + // Clear the random fuzzed condition + imc.Status.SetConditions(nil) + + // Fuzz the known conditions except their type value + imc.Status.InitializeConditions() + pkgfuzzer.FuzzConditions(&imc.Status, c) + }, + func(s *SubscriptionStatus, c fuzz.Continue) { + c.FuzzNoCustom(s) // fuzz the status object + + // Clear the random fuzzed condition + s.Status.SetConditions(nil) + + // Fuzz the known conditions except their type value + s.InitializeConditions() + pkgfuzzer.FuzzConditions(&s.Status, c) + }, + } + }, +) + func TestMessagingRoundTripTypesToJSON(t *testing.T) { scheme := runtime.NewScheme() utilruntime.Must(AddToScheme(scheme)) diff --git a/pkg/apis/messaging/v1beta1/roundtrip_test.go b/pkg/apis/messaging/v1beta1/roundtrip_test.go index 8dd8e8391b6..f494417120f 100644 --- a/pkg/apis/messaging/v1beta1/roundtrip_test.go +++ b/pkg/apis/messaging/v1beta1/roundtrip_test.go @@ -19,22 +19,77 @@ package v1beta1 import ( "testing" + fuzz "github.com/google/gofuzz" + "k8s.io/apimachinery/pkg/runtime/serializer" + "knative.dev/eventing/pkg/apis/duck/v1/test" + "knative.dev/eventing/pkg/apis/messaging" + "k8s.io/apimachinery/pkg/api/apitesting/fuzzer" "k8s.io/apimachinery/pkg/runtime" utilruntime "k8s.io/apimachinery/pkg/util/runtime" - duckerfuzzer "knative.dev/eventing/pkg/apis/duck/v1" v1 "knative.dev/eventing/pkg/apis/messaging/v1" pkgfuzzer "knative.dev/pkg/apis/testing/fuzzer" "knative.dev/pkg/apis/testing/roundtrip" ) +// FuzzerFuncs includes fuzzing funcs for knative.dev/messaging v1 types +// +// For other examples see +// https://github.com/kubernetes/apimachinery/blob/master/pkg/apis/meta/fuzzer/fuzzer.go +var FuzzerFuncs = fuzzer.MergeFuzzerFuncs( + func(codecs serializer.CodecFactory) []interface{} { + return []interface{}{ + func(ch *v1.Channel, c fuzz.Continue) { + c.FuzzNoCustom(ch) // fuzz the Channel + if ch != nil { + if ch.Annotations == nil { + ch.Annotations = make(map[string]string) + } + ch.Annotations[messaging.SubscribableDuckVersionAnnotation] = "v1" + } + // Clear the random fuzzed condition + ch.Status.SetConditions(nil) + + // Fuzz the known conditions except their type value + ch.Status.InitializeConditions() + pkgfuzzer.FuzzConditions(&ch.Status, c) + }, + func(imc *v1.InMemoryChannel, c fuzz.Continue) { + c.FuzzNoCustom(imc) // fuzz the InMemoryChannel + if imc != nil { + if imc.Annotations == nil { + imc.Annotations = make(map[string]string) + } + imc.Annotations[messaging.SubscribableDuckVersionAnnotation] = "v1" + } + // Clear the random fuzzed condition + imc.Status.SetConditions(nil) + + // Fuzz the known conditions except their type value + imc.Status.InitializeConditions() + pkgfuzzer.FuzzConditions(&imc.Status, c) + }, + func(s *v1.SubscriptionStatus, c fuzz.Continue) { + c.FuzzNoCustom(s) // fuzz the status object + + // Clear the random fuzzed condition + s.Status.SetConditions(nil) + + // Fuzz the known conditions except their type value + s.InitializeConditions() + pkgfuzzer.FuzzConditions(&s.Status, c) + }, + } + }, +) + func TestMessagingRoundTripTypesToJSON(t *testing.T) { scheme := runtime.NewScheme() utilruntime.Must(AddToScheme(scheme)) fuzzerFuncs := fuzzer.MergeFuzzerFuncs( pkgfuzzer.Funcs, - v1.FuzzerFuncs, + FuzzerFuncs, ) roundtrip.ExternalTypesViaJSON(t, scheme, fuzzerFuncs) } @@ -58,8 +113,8 @@ func TestMessagingRoundTripTypesToBetaHub(t *testing.T) { fuzzerFuncs := fuzzer.MergeFuzzerFuncs( pkgfuzzer.Funcs, - v1.FuzzerFuncs, - duckerfuzzer.FuzzerFuncs, + FuzzerFuncs, + test.FuzzerFuncs, ) roundtrip.ExternalTypesViaHub(t, scheme, hubs, fuzzerFuncs) From 5b722646d6ab7b3576bdf25b734830331ef97f4f Mon Sep 17 00:00:00 2001 From: Ville Aikas Date: Tue, 27 Oct 2020 12:28:17 +0200 Subject: [PATCH 2/2] go imports, why no automagic... Signed-off-by: Ville Aikas --- pkg/apis/duck/v1/test/fuzzer.go | 3 ++- pkg/apis/eventing/v1/roundtrip_test.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/apis/duck/v1/test/fuzzer.go b/pkg/apis/duck/v1/test/fuzzer.go index 7d7348ec5d0..9328bb2bae2 100644 --- a/pkg/apis/duck/v1/test/fuzzer.go +++ b/pkg/apis/duck/v1/test/fuzzer.go @@ -17,9 +17,10 @@ limitations under the License. package test import ( - "knative.dev/eventing/pkg/apis/duck/v1" "math/rand" + v1 "knative.dev/eventing/pkg/apis/duck/v1" + fuzz "github.com/google/gofuzz" "k8s.io/apimachinery/pkg/api/apitesting/fuzzer" "k8s.io/apimachinery/pkg/runtime/serializer" diff --git a/pkg/apis/eventing/v1/roundtrip_test.go b/pkg/apis/eventing/v1/roundtrip_test.go index 3cc19af8e19..a4cac97a4f3 100644 --- a/pkg/apis/eventing/v1/roundtrip_test.go +++ b/pkg/apis/eventing/v1/roundtrip_test.go @@ -17,9 +17,10 @@ limitations under the License. package v1 import ( + "testing" + fuzz "github.com/google/gofuzz" "k8s.io/apimachinery/pkg/runtime/serializer" - "testing" "k8s.io/apimachinery/pkg/api/apitesting/fuzzer" "k8s.io/apimachinery/pkg/runtime"