Пример #1
0
)

var fuzzIters = flag.Int("fuzz_iters", 3, "How many fuzzing iterations to do.")

// apiObjectFuzzer can randomly populate api objects.
var apiObjectFuzzer = util.NewFuzzer(
	func(j *JSONBase) {
		// We have to customize the randomization of JSONBases because their
		// APIVersion and Kind must remain blank in memory.
		j.APIVersion = ""
		j.Kind = ""
		j.ID = util.RandString()
		// TODO: Fix JSON/YAML packages and/or write custom encoding
		// for uint64's. Somehow the LS *byte* of this is lost, but
		// only when all 8 bytes are set.
		j.ResourceVersion = util.RandUint64() >> 8
		j.SelfLink = util.RandString()
		j.CreationTimestamp = util.RandString()
	},
	func(intstr *util.IntOrString) {
		// util.IntOrString will panic if its kind is set wrong.
		if util.RandBool() {
			intstr.Kind = util.IntstrInt
			intstr.IntVal = int(util.RandUint64())
			intstr.StrVal = ""
		} else {
			intstr.Kind = util.IntstrString
			intstr.IntVal = 0
			intstr.StrVal = util.RandString()
		}
	},
Пример #2
0
}

// TestObjectFuzzer can randomly populate all the above objects.
var TestObjectFuzzer = util.NewFuzzer(
	func(j *MyWeirdCustomEmbeddedVersionKindField) {
		// We have to customize the randomization of MyWeirdCustomEmbeddedVersionKindFields because their
		// APIVersion and Kind must remain blank in memory.
		j.APIVersion = ""
		j.ObjectKind = ""
		j.ID = util.RandString()
	},
	func(u *uint64) {
		// TODO: Fix JSON/YAML packages and/or write custom encoding
		// for uint64's. Somehow the LS *byte* of this is lost, but
		// only when all 8 bytes are set.
		*u = util.RandUint64() >> 8
	},
	func(u *uint) {
		// TODO: Fix JSON/YAML packages and/or write custom encoding
		// for uint64's. Somehow the LS *byte* of this is lost, but
		// only when all 8 bytes are set.
		*u = uint(util.RandUint64() >> 8)
	},
)

// Returns a new Scheme set up with the test objects.
func GetTestScheme() *Scheme {
	s := NewScheme()
	s.AddKnownTypes("", TestType1{}, ExternalInternalSame{})
	s.AddKnownTypes("v1", externalTypeReturn(), ExternalInternalSame{})
	s.ExternalVersion = "v1"