func TestNilUnstructuredContent(t *testing.T) { … } // TestUnstructuredMetadataRoundTrip checks that metadata accessors // correctly set the metadata for unstructured objects. // First, it fuzzes an empty ObjectMeta and sets this value as the metadata for an unstructured object. // Next, it uses metadata accessor methods to set these fuzzed values to another unstructured object. // Finally, it checks that both the unstructured objects are equal. func TestUnstructuredMetadataRoundTrip(t *testing.T) { … } // TestUnstructuredMetadataOmitempty checks that ObjectMeta omitempty // semantics are enforced for unstructured objects. // The fuzzing test above should catch these cases but this is here just to be safe. // Example: the metadata.clusterName field has the omitempty json tag // so if it is set to it's zero value (""), it should be removed from the metadata map. func TestUnstructuredMetadataOmitempty(t *testing.T) { … } // TestRoundTripJSONCBORUnstructured performs fuzz testing for roundtrip for // unstructured object between JSON and CBOR func TestRoundTripJSONCBORUnstructured(t *testing.T) { … } // TestRoundTripJSONCBORUnstructuredList performs fuzz testing for roundtrip for // unstructuredList object between JSON and CBOR func TestRoundTripJSONCBORUnstructuredList(t *testing.T) { … } func setObjectMeta(u *unstructured.Unstructured, objectMeta *metav1.ObjectMeta) error { … } func setObjectMetaUsingAccessors(u, uCopy *unstructured.Unstructured) { … } // roundtripType performs fuzz testing for roundtrip conversion for // unstructured or unstructuredList object between two formats (A and B) in forward // and backward directions // Original and final unstructured/list are compared along with all intermediate ones func roundtripType[U runtime.Unstructured](t *testing.T) { … } // roundtrip tests that an Unstructured object roundtrips faithfully along the // sequence Unstructured -> A -> Unstructured -> B -> Unstructured -> A -> Unstructured, // given serializers for two encodings A and B. The final object and both intermediate // objects must all be equal to the original. func roundtrip(t *testing.T, original runtime.Unstructured, a, b runtime.Serializer) { … } func getSeed(t *testing.T) int64 { … } const maxUnstructuredDepth … const maxUnstructuredFanOut … func unstructuredFuzzerFuncs(codecs serializer.CodecFactory) []interface{ … } func generateNonEmptyString(c fuzz.Continue) string { … } // generateNonEmptyNoSlashString generates a non-empty string without any slashes func generateNonEmptyNoSlashString(c fuzz.Continue) string { … } // generateValidAPIVersionString generates valid apiVersion string with formats: // <string>/<string> or <string> func generateValidAPIVersionString(c fuzz.Continue) string { … } // generateRandomTypeValue generates fuzzed valid JSON data types: // 1. numbers (float64, int64) // 2. string (utf-8 encodings) // 3. boolean // 4. array ([]interface{}) // 5. object (map[string]interface{}) // 6. null // Decoding into unstructured can only produce a nil interface{} value or the // concrete types map[string]interface{}, []interface{}, int64, float64, string, and bool // If a value of other types is put into an unstructured, it will roundtrip // to one of the above list of supported types. For example, if Time type is used, // it will be encoded into a RFC 3339 format string such as "2001-02-03T12:34:56Z" // and when decoding into Unstructured, there is no information to indicate // that this string was originally produced by encoding a metav1.Time. // All external-versioned builtin types are exercised through RoundtripToUnstructured // in apitesting package. Types like metav1.Time are implicitly being exercised // because they appear as fields in those types. func generateRandomTypeValue(depth int, c fuzz.Continue) interface{ … } func unstructuredEqual(t *testing.T, a, b runtime.Unstructured) bool { … } // numberEqual asserts equality of two numbers which one is int64 and one is float64 // In JSON, a non-decimal float64 is converted to int64 automatically in case the // float64 fits into int64 range. Otherwise, the non-decimal float64 remains a float. // As a result, this func does an int64 to float64 conversion using math/big package // to ensure the conversion is lossless before comparison. func numberEqual(a int64, b float64) bool { … } func anyEqual(t *testing.T, a, b interface{ … }