Ejemplo n.º 1
0
	"testing"

	"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
	"github.com/fsouza/go-dockerclient"
)

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
Ejemplo n.º 2
0
	"reflect"
	"testing"

	"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
)

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
Ejemplo n.º 3
0
	return TestType1{}
}

type ExternalInternalSame struct {
	MyWeirdCustomEmbeddedVersionKindField `json:",inline" yaml:",inline"`
	A                                     TestType2 `yaml:"A,omitempty" json:"A,omitempty"`
}

// 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)
	},
)