From fef67e4dabe65be063462900da4db6e6feb6ed05 Mon Sep 17 00:00:00 2001 From: Brendan Chang Date: Mon, 28 Oct 2019 14:47:40 -0400 Subject: [PATCH] Fix validation for metav1 fuzz targets. --- test/fuzz/yaml/yaml.go | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/test/fuzz/yaml/yaml.go b/test/fuzz/yaml/yaml.go index 19dbbcd1f38..d88115b2bda 100644 --- a/test/fuzz/yaml/yaml.go +++ b/test/fuzz/yaml/yaml.go @@ -20,7 +20,8 @@ limitations under the License. package yaml import ( - "bytes" + "fmt" + "strings" "gopkg.in/yaml.v2" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -41,8 +42,12 @@ func FuzzDurationStrict(b []byte) int { if err != nil { panic(err) } - if !bytes.Equal(result, b) { - panic("result != input") + // Result is in the format "d: \n", so strip off the trailing + // newline and convert durationHolder.D to the expected format. + resultStr := strings.TrimSpace(string(result[:])) + inputStr := fmt.Sprintf("d: %s", durationHolder.D.Duration) + if resultStr != inputStr { + panic(fmt.Sprintf("result(%v) != input(%v)", resultStr, inputStr)) } return 1 } @@ -61,8 +66,18 @@ func FuzzMicroTimeStrict(b []byte) int { if err != nil { panic(err) } - if !bytes.Equal(result, b) { - panic("result != input") + // Result is in the format "t: