|
| 1 | +package api_test |
| 2 | + |
| 3 | +import ( |
| 4 | + _ "k8s.io/kubernetes/pkg/apis/core/install" |
| 5 | + // install all APIs |
| 6 | + _ "github.com/openshift/hive/pkg/api/install" |
| 7 | +) |
| 8 | + |
| 9 | +// TODO (staebler): Determine if these round-trip serialization tests offer value for Hive's use-case. |
| 10 | +/* |
| 11 | +func v1alpha1Fuzzer(t *testing.T, seed int64) *fuzz.Fuzzer { |
| 12 | + f := fuzzer.FuzzerFor(kapitesting.FuzzerFuncs, rand.NewSource(seed), legacyscheme.Codecs) |
| 13 | + f.Funcs( |
| 14 | + func(j *hiveapi.ClusterImageSet, c fuzz.Continue) { |
| 15 | + c.FuzzNoCustom(j) |
| 16 | + }, |
| 17 | +
|
| 18 | + func(j *runtime.Object, c fuzz.Continue) { |
| 19 | + // runtime.EmbeddedObject causes a panic inside of fuzz because runtime.Object isn't handled. |
| 20 | + }, |
| 21 | + func(t *time.Time, c fuzz.Continue) { |
| 22 | + // This is necessary because the standard fuzzed time.Time object is |
| 23 | + // completely nil, but when JSON unmarshals dates it fills in the |
| 24 | + // unexported loc field with the time.UTC object, resulting in |
| 25 | + // reflect.DeepEqual returning false in the round trip tests. We solve it |
| 26 | + // by using a date that will be identical to the one JSON unmarshals. |
| 27 | + *t = time.Date(2000, 1, 1, 1, 1, 1, 0, time.UTC) |
| 28 | + }, |
| 29 | + func(u64 *uint64, c fuzz.Continue) { |
| 30 | + // TODO: uint64's are NOT handled right. |
| 31 | + *u64 = c.RandUint64() >> 8 |
| 32 | + }, |
| 33 | + ) |
| 34 | + return f |
| 35 | +} |
| 36 | +
|
| 37 | +const fuzzIters = 20 |
| 38 | +
|
| 39 | +// For debugging problems |
| 40 | +func TestSpecificKind(t *testing.T) { |
| 41 | + seed := int64(2703387474910584091) |
| 42 | + fuzzer := v1alpha1Fuzzer(t, seed) |
| 43 | +
|
| 44 | + legacyscheme.Scheme.Log(t) |
| 45 | + defer legacyscheme.Scheme.Log(nil) |
| 46 | +
|
| 47 | + gvk := hiveapi.SchemeGroupVersion.WithKind("ClusterImageSet") |
| 48 | + // TODO: make upstream CodecFactory customizable |
| 49 | + codecs := serializer.NewCodecFactory(legacyscheme.Scheme) |
| 50 | + for i := 0; i < fuzzIters; i++ { |
| 51 | + roundtrip.RoundTripSpecificKindWithoutProtobuf(t, gvk, legacyscheme.Scheme, codecs, fuzzer, nil) |
| 52 | + } |
| 53 | +} |
| 54 | +
|
| 55 | +// TestRoundTripTypes applies the round-trip test to all round-trippable Kinds |
| 56 | +// in all of the API groups registered for test in the testapi package. |
| 57 | +func TestRoundTripTypes(t *testing.T) { |
| 58 | + seed := rand.Int63() |
| 59 | + fuzzer := v1alpha1Fuzzer(t, seed) |
| 60 | +
|
| 61 | + roundtrip.RoundTripTypes(t, legacyscheme.Scheme, legacyscheme.Codecs, fuzzer, nil) |
| 62 | +} |
| 63 | +*/ |
0 commit comments