mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-10-31 02:08:13 +00:00 
			
		
		
		
	Fix validation for metav1 fuzz targets.
This commit is contained in:
		| @@ -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 | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Brendan Chang
					Brendan Chang