config API: fix up fuzz tests

Signed-off-by: James Munnelly <jmunnelly@apple.com>
This commit is contained in:
James Munnelly
2021-11-26 14:12:54 +00:00
parent 0e1d603c93
commit 415ca56933
6 changed files with 74 additions and 42 deletions
+1
View File
@@ -29,6 +29,7 @@ filegroup(
name = "all-srcs",
srcs = [
":package-srcs",
"//internal/apis/config/fuzzer:all-srcs",
"//internal/apis/config/install:all-srcs",
"//internal/apis/config/scheme:all-srcs",
"//internal/apis/config/v1alpha1:all-srcs",
+28
View File
@@ -0,0 +1,28 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "go_default_library",
srcs = ["fuzzer.go"],
importpath = "github.com/jetstack/cert-manager/internal/apis/config/fuzzer",
visibility = ["//:__subpackages__"],
deps = [
"//internal/apis/config:go_default_library",
"@com_github_google_gofuzz//:go_default_library",
"@io_k8s_apimachinery//pkg/runtime/serializer:go_default_library",
"@io_k8s_utils//pointer:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)
+41
View File
@@ -0,0 +1,41 @@
/*
Copyright 2021 The cert-manager 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 fuzzer
import (
fuzz "github.com/google/gofuzz"
runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/utils/pointer"
"github.com/jetstack/cert-manager/internal/apis/config"
)
// Funcs returns the fuzzer functions for the apps api group.
var Funcs = func(codecs runtimeserializer.CodecFactory) []interface{} {
return []interface{}{
func(s *config.WebhookConfiguration, c fuzz.Continue) {
c.FuzzNoCustom(s) // fuzz self without calling this function again
if s.HealthzPort == nil {
s.HealthzPort = pointer.Int(12)
}
if s.SecurePort == nil {
s.SecurePort = pointer.Int(123)
}
},
}
}
+2 -8
View File
@@ -29,19 +29,13 @@ filegroup(
go_test(
name = "go_default_test",
srcs = [
"pruning_test.go",
"roundtrip_test.go",
],
srcs = ["roundtrip_test.go"],
data = [
"//deploy/crds:templated_files",
],
embed = [":go_default_library"],
deps = [
"//internal/apis/acme/fuzzer:go_default_library",
"//pkg/api:go_default_library",
"//pkg/api/testing:go_default_library",
"@com_github_munnerz_crd_schema_fuzz//:go_default_library",
"//internal/apis/config/fuzzer:go_default_library",
"@io_k8s_apimachinery//pkg/api/apitesting/roundtrip:go_default_library",
],
)
@@ -1,32 +0,0 @@
/*
Copyright 2020 The cert-manager 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 install
import (
"testing"
crdfuzz "github.com/munnerz/crd-schema-fuzz"
acmefuzzer "github.com/jetstack/cert-manager/internal/apis/acme/fuzzer"
"github.com/jetstack/cert-manager/pkg/api"
apitesting "github.com/jetstack/cert-manager/pkg/api/testing"
)
func TestPruneTypes(t *testing.T) {
crdfuzz.SchemaFuzzTestForCRDWithPath(t, api.Scheme, apitesting.PathForCRD(t, "orders"), acmefuzzer.Funcs)
crdfuzz.SchemaFuzzTestForCRDWithPath(t, api.Scheme, apitesting.PathForCRD(t, "challenges"), acmefuzzer.Funcs)
}
@@ -21,9 +21,9 @@ import (
"k8s.io/apimachinery/pkg/api/apitesting/roundtrip"
acmefuzzer "github.com/jetstack/cert-manager/internal/apis/acme/fuzzer"
configfuzzer "github.com/jetstack/cert-manager/internal/apis/config/fuzzer"
)
func TestRoundTripTypes(t *testing.T) {
roundtrip.RoundTripTestForAPIGroup(t, Install, acmefuzzer.Funcs)
roundtrip.RoundTripTestForAPIGroup(t, Install, configfuzzer.Funcs)
}