mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-26 05:03:09 +00:00
Merge pull request #84480 from BrendanSChang/fuzz
Fix validation for metav1 fuzz targets.
This commit is contained in:
commit
4c6bed6e4e
@ -20,7 +20,8 @@ limitations under the License.
|
|||||||
package yaml
|
package yaml
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
@ -41,8 +42,12 @@ func FuzzDurationStrict(b []byte) int {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
if !bytes.Equal(result, b) {
|
// Result is in the format "d: <duration>\n", so strip off the trailing
|
||||||
panic("result != input")
|
// 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
|
return 1
|
||||||
}
|
}
|
||||||
@ -61,8 +66,18 @@ func FuzzMicroTimeStrict(b []byte) int {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
if !bytes.Equal(result, b) {
|
// Result is in the format "t: <time>\n", so strip off the trailing
|
||||||
panic("result != input")
|
// newline and convert microTimeHolder.T to the expected format. If
|
||||||
|
// time is zero, the value is marshaled to "null".
|
||||||
|
resultStr := strings.TrimSpace(string(result[:]))
|
||||||
|
var inputStr string
|
||||||
|
if microTimeHolder.T.Time.IsZero() {
|
||||||
|
inputStr = "t: null"
|
||||||
|
} else {
|
||||||
|
inputStr = fmt.Sprintf("t: %s", microTimeHolder.T.Time)
|
||||||
|
}
|
||||||
|
if resultStr != inputStr {
|
||||||
|
panic(fmt.Sprintf("result(%v) != input(%v)", resultStr, inputStr))
|
||||||
}
|
}
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
@ -95,8 +110,18 @@ func FuzzTimeStrict(b []byte) int {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
if !bytes.Equal(result, b) {
|
// Result is in the format "t: <time>\n", so strip off the trailing
|
||||||
panic("result != input")
|
// newline and convert timeHolder.T to the expected format. If time is
|
||||||
|
// zero, the value is marshaled to "null".
|
||||||
|
resultStr := strings.TrimSpace(string(result[:]))
|
||||||
|
var inputStr string
|
||||||
|
if timeHolder.T.Time.IsZero() {
|
||||||
|
inputStr = "t: null"
|
||||||
|
} else {
|
||||||
|
inputStr = fmt.Sprintf("t: %s", timeHolder.T.Time)
|
||||||
|
}
|
||||||
|
if resultStr != inputStr {
|
||||||
|
panic(fmt.Sprintf("result(%v) != input(%v)", resultStr, inputStr))
|
||||||
}
|
}
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user