Created
November 14, 2019 17:16
-
-
Save munnerz/19a72d4683bb388cddfb22397dfa747e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func objectNTimes(t *testing.T, fuzzer *gofuzz.Fuzzer, obj runtime.Object, schema *structuralschema.Structural, iterations int) { | |
t.Logf("Running CRD schema pruning fuzz test for object %v", obj.GetObjectKind()) | |
for i := 0; i < iterations; i++ { | |
fuzzed := obj.DeepCopyObject() | |
// fuzz *before* converting to unstructured, so we get typed fuzzing | |
fuzzer.Fuzz(fuzzed) | |
unstructuredFuzzed, err := runtime.DefaultUnstructuredConverter.ToUnstructured(fuzzed) | |
if err != nil { | |
t.Fatalf("Failed to convert type to `runtime.Unstructured`: %v", err) | |
return | |
} | |
pruned, err := runtime.DefaultUnstructuredConverter.ToUnstructured(fuzzed) | |
if err != nil { | |
t.Fatalf("Failed to convert type to `runtime.Unstructured`: %v", err) | |
return | |
} | |
structuralpruning.Prune(pruned, schema, true) | |
//t.Logf("Fuzzed: %+v", fuzzed) | |
//t.Logf("Pruned: %+v", pruned) | |
if !cmp.Equal(unstructuredFuzzed, pruned) { | |
t.Errorf("Failed fuzz test, difference: %v", cmp.Diff(unstructuredFuzzed, pruned)) | |
} | |
t.Logf("Passed fuzz test iteration %d", i) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment