mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 07:20:13 +00:00
Merge pull request #92491 from BenTheElder/fuzz-only-test
compile out gofuzz from prod binaries
This commit is contained in:
commit
aa084d4919
@ -793,7 +793,7 @@ kube::golang::build_binaries() {
|
|||||||
|
|
||||||
# extract tags if any specified in GOFLAGS
|
# extract tags if any specified in GOFLAGS
|
||||||
# shellcheck disable=SC2001
|
# shellcheck disable=SC2001
|
||||||
gotags="selinux,$(echo "${GOFLAGS:-}" | sed -e 's|.*-tags=\([^-]*\).*|\1|')"
|
gotags="selinux,notest,$(echo "${GOFLAGS:-}" | sed -e 's|.*-tags=\([^-]*\).*|\1|')"
|
||||||
|
|
||||||
local -a targets=()
|
local -a targets=()
|
||||||
local arg
|
local arg
|
||||||
|
@ -47,9 +47,11 @@ go_library(
|
|||||||
"labels.go",
|
"labels.go",
|
||||||
"meta.go",
|
"meta.go",
|
||||||
"micro_time.go",
|
"micro_time.go",
|
||||||
|
"micro_time_fuzz.go",
|
||||||
"micro_time_proto.go",
|
"micro_time_proto.go",
|
||||||
"register.go",
|
"register.go",
|
||||||
"time.go",
|
"time.go",
|
||||||
|
"time_fuzz.go",
|
||||||
"time_proto.go",
|
"time_proto.go",
|
||||||
"types.go",
|
"types.go",
|
||||||
"types_swagger_doc_generated.go",
|
"types_swagger_doc_generated.go",
|
||||||
|
@ -19,8 +19,6 @@ package v1
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/google/gofuzz"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const RFC3339Micro = "2006-01-02T15:04:05.000000Z07:00"
|
const RFC3339Micro = "2006-01-02T15:04:05.000000Z07:00"
|
||||||
@ -181,16 +179,3 @@ func (t MicroTime) MarshalQueryParameter() (string, error) {
|
|||||||
|
|
||||||
return t.UTC().Format(RFC3339Micro), nil
|
return t.UTC().Format(RFC3339Micro), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fuzz satisfies fuzz.Interface.
|
|
||||||
func (t *MicroTime) Fuzz(c fuzz.Continue) {
|
|
||||||
if t == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// Allow for about 1000 years of randomness. Accurate to a tenth of
|
|
||||||
// micro second. Leave off nanoseconds because JSON doesn't
|
|
||||||
// represent them so they can't round-trip properly.
|
|
||||||
t.Time = time.Unix(c.Rand.Int63n(1000*365*24*60*60), 1000*c.Rand.Int63n(1000000))
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ fuzz.Interface = &MicroTime{}
|
|
||||||
|
@ -0,0 +1,39 @@
|
|||||||
|
// +build !notest
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright 2020 The Kubernetes 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 (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
fuzz "github.com/google/gofuzz"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Fuzz satisfies fuzz.Interface.
|
||||||
|
func (t *MicroTime) Fuzz(c fuzz.Continue) {
|
||||||
|
if t == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// Allow for about 1000 years of randomness. Accurate to a tenth of
|
||||||
|
// micro second. Leave off nanoseconds because JSON doesn't
|
||||||
|
// represent them so they can't round-trip properly.
|
||||||
|
t.Time = time.Unix(c.Rand.Int63n(1000*365*24*60*60), 1000*c.Rand.Int63n(1000000))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ensure MicroTime implements fuzz.Interface
|
||||||
|
var _ fuzz.Interface = &MicroTime{}
|
@ -19,8 +19,6 @@ package v1
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
fuzz "github.com/google/gofuzz"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Time is a wrapper around time.Time which supports correct
|
// Time is a wrapper around time.Time which supports correct
|
||||||
@ -182,16 +180,3 @@ func (t Time) MarshalQueryParameter() (string, error) {
|
|||||||
|
|
||||||
return t.UTC().Format(time.RFC3339), nil
|
return t.UTC().Format(time.RFC3339), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fuzz satisfies fuzz.Interface.
|
|
||||||
func (t *Time) Fuzz(c fuzz.Continue) {
|
|
||||||
if t == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// Allow for about 1000 years of randomness. Leave off nanoseconds
|
|
||||||
// because JSON doesn't represent them so they can't round-trip
|
|
||||||
// properly.
|
|
||||||
t.Time = time.Unix(c.Rand.Int63n(1000*365*24*60*60), 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ fuzz.Interface = &Time{}
|
|
||||||
|
@ -0,0 +1,39 @@
|
|||||||
|
// +build !notest
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright 2020 The Kubernetes 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 (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
fuzz "github.com/google/gofuzz"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Fuzz satisfies fuzz.Interface.
|
||||||
|
func (t *Time) Fuzz(c fuzz.Continue) {
|
||||||
|
if t == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// Allow for about 1000 years of randomness. Leave off nanoseconds
|
||||||
|
// because JSON doesn't represent them so they can't round-trip
|
||||||
|
// properly.
|
||||||
|
t.Time = time.Unix(c.Rand.Int63n(1000*365*24*60*60), 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ensure Time implements fuzz.Interface
|
||||||
|
var _ fuzz.Interface = &Time{}
|
@ -17,6 +17,7 @@ go_library(
|
|||||||
name = "go_default_library",
|
name = "go_default_library",
|
||||||
srcs = [
|
srcs = [
|
||||||
"generated.pb.go",
|
"generated.pb.go",
|
||||||
|
"instr_fuzz.go",
|
||||||
"intstr.go",
|
"intstr.go",
|
||||||
],
|
],
|
||||||
importmap = "k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/util/intstr",
|
importmap = "k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/util/intstr",
|
||||||
|
@ -0,0 +1,42 @@
|
|||||||
|
// +build !notest
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright 2020 The Kubernetes 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 intstr
|
||||||
|
|
||||||
|
import (
|
||||||
|
fuzz "github.com/google/gofuzz"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Fuzz satisfies fuzz.Interface
|
||||||
|
func (intstr *IntOrString) Fuzz(c fuzz.Continue) {
|
||||||
|
if intstr == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if c.RandBool() {
|
||||||
|
intstr.Type = Int
|
||||||
|
c.Fuzz(&intstr.IntVal)
|
||||||
|
intstr.StrVal = ""
|
||||||
|
} else {
|
||||||
|
intstr.Type = String
|
||||||
|
intstr.IntVal = 0
|
||||||
|
c.Fuzz(&intstr.StrVal)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ensure IntOrString implements fuzz.Interface
|
||||||
|
var _ fuzz.Interface = &IntOrString{}
|
@ -25,7 +25,6 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/google/gofuzz"
|
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -129,21 +128,6 @@ func (IntOrString) OpenAPISchemaType() []string { return []string{"string"} }
|
|||||||
// the OpenAPI spec of this type.
|
// the OpenAPI spec of this type.
|
||||||
func (IntOrString) OpenAPISchemaFormat() string { return "int-or-string" }
|
func (IntOrString) OpenAPISchemaFormat() string { return "int-or-string" }
|
||||||
|
|
||||||
func (intstr *IntOrString) Fuzz(c fuzz.Continue) {
|
|
||||||
if intstr == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if c.RandBool() {
|
|
||||||
intstr.Type = Int
|
|
||||||
c.Fuzz(&intstr.IntVal)
|
|
||||||
intstr.StrVal = ""
|
|
||||||
} else {
|
|
||||||
intstr.Type = String
|
|
||||||
intstr.IntVal = 0
|
|
||||||
c.Fuzz(&intstr.StrVal)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func ValueOrDefault(intOrPercent *IntOrString, defaultValue IntOrString) *IntOrString {
|
func ValueOrDefault(intOrPercent *IntOrString, defaultValue IntOrString) *IntOrString {
|
||||||
if intOrPercent == nil {
|
if intOrPercent == nil {
|
||||||
return &defaultValue
|
return &defaultValue
|
||||||
|
Loading…
Reference in New Issue
Block a user