当前位置: 首页>>代码示例>>Golang>>正文


Golang gofuzz.New函数代码示例

本文整理汇总了Golang中github.com/google/gofuzz.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了New函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: getContainer

func getContainer(name string) source_api.Container {
	f := fuzz.New().NumElements(1, 1).NilChance(0)
	containerSpec := cadvisor.ContainerSpec{
		CreationTime:  time.Unix(fakeContainerCreationTime, 0),
		HasCpu:        true,
		HasMemory:     true,
		HasNetwork:    true,
		HasFilesystem: true,
		HasDiskIo:     true,
		Cpu: cadvisor.CpuSpec{
			Limit: 100,
		},
		Memory: cadvisor.MemorySpec{
			Limit: 100,
		},
	}
	containerStats := make([]*cadvisor.ContainerStats, 1)
	f.Fuzz(&containerStats)
	return source_api.Container{
		Name:  name,
		Image: "gcr.io/" + name,
		Spec:  containerSpec,
		Stats: containerStats,
	}
}
开发者ID:slodha,项目名称:heapster,代码行数:25,代码来源:decoder_test.go

示例2: TestAnonymousConfig

func TestAnonymousConfig(t *testing.T) {
	f := fuzz.New().NilChance(0.0).NumElements(1, 1)
	f.Funcs(
		func(r *runtime.Codec, f fuzz.Continue) {},
		func(r *http.RoundTripper, f fuzz.Continue) {},
		func(fn *func(http.RoundTripper) http.RoundTripper, f fuzz.Continue) {},
	)
	for i := 0; i < 20; i++ {
		original := &restclient.Config{}
		f.Fuzz(original)
		actual := AnonymousClientConfig(original)
		expected := *original

		// this is the list of known security related fields, add to this list if a new field
		// is added to restclient.Config, update AnonymousClientConfig to preserve the field otherwise.
		expected.Impersonate = ""
		expected.BearerToken = ""
		expected.Username = ""
		expected.Password = ""
		expected.TLSClientConfig.CertData = nil
		expected.TLSClientConfig.CertFile = ""
		expected.TLSClientConfig.KeyData = nil
		expected.TLSClientConfig.KeyFile = ""

		if !reflect.DeepEqual(actual, expected) {
			t.Fatalf("AnonymousClientConfig dropped unexpected fields, identify whether they are security related or not: %s", diff.ObjectGoPrintDiff(expected, actual))
		}
	}
}
开发者ID:RomainVabre,项目名称:origin,代码行数:29,代码来源:clientcmd_test.go

示例3: TestFuzzMapToType

// This contains maps.
// Since map order is random, we can expect the encoding order to be random
// Therefore we cannot use binary compare.
func TestFuzzMapToType(t *testing.T) {
	base := &TTestMaps{}
	ff := &XTestMaps{}
	f := fuzz.New()
	f.NumElements(0, 50)
	f.NilChance(0.1)
	f.Funcs(fuzzTime)
	for i := 0; i < 100; i++ {
		f.RandSource(rand.New(rand.NewSource(int64(i * 5275))))
		f.Fuzz(base)
		ff = &XTestMaps{*base}

		bufbase, err := json.Marshal(base)
		require.NoError(t, err, "base[%T] failed to Marshal", base)

		bufff, err := json.Marshal(ff)
		require.NoError(t, err, "ff[%T] failed to Marshal", ff)

		var baseD map[string]interface{}
		var ffD map[string]interface{}

		err = json.Unmarshal(bufbase, &baseD)
		require.NoError(t, err, "ff[%T] failed to Unmarshal", base)

		err = json.Unmarshal(bufff, &ffD)
		require.NoError(t, err, "ff[%T] failed to Unmarshal", ff)

		require.Equal(t, baseD, ffD, "Inspected struct difference of base[%T] != ff[%T]", base, ff)
	}
}
开发者ID:gooops,项目名称:ffjson,代码行数:33,代码来源:fuzz_test.go

示例4: TestFuzzInput

func TestFuzzInput(t *testing.T) {
	var pods []*cache.PodElement
	f := fuzz.New().NumElements(2, 10)
	f.Fuzz(&pods)
	_, err := NewDecoder().TimeseriesFromPods(pods)
	assert.NoError(t, err)
}
开发者ID:naxhh,项目名称:heapster,代码行数:7,代码来源:decoder_test.go

示例5: getContainerElement

func getContainerElement(name string) *cache.ContainerElement {
	f := fuzz.New().NumElements(1, 1).NilChance(0)
	containerSpec := &cadvisor_api.ContainerSpec{
		CreationTime:  time.Unix(fakeContainerCreationTime, 0),
		HasCpu:        true,
		HasMemory:     true,
		HasNetwork:    true,
		HasFilesystem: true,
		HasDiskIo:     true,
		Cpu: cadvisor_api.CpuSpec{
			Limit: 100,
		},
		Memory: cadvisor_api.MemorySpec{
			Limit: 100,
		},
	}
	containerStats := make([]*cadvisor_api.ContainerStats, 1)
	f.Fuzz(&containerStats)
	return &cache.ContainerElement{
		Metadata: cache.Metadata{
			Name: name,
		},
		Metrics: []*cache.ContainerMetricElement{
			{
				Spec:  containerSpec,
				Stats: containerStats[0],
			},
		},
	}
}
开发者ID:naxhh,项目名称:heapster,代码行数:30,代码来源:decoder_test.go

示例6: TestFuzzInput

func TestFuzzInput(t *testing.T) {
	var input source_api.AggregateData
	fuzz.New().Fuzz(&input)
	timeseries, err := NewDecoder().Timeseries(input)
	assert.NoError(t, err)
	assert.NotEmpty(t, timeseries)
}
开发者ID:slodha,项目名称:heapster,代码行数:7,代码来源:decoder_test.go

示例7: TestGC

func TestGC(t *testing.T) {
	var podEvictedCount int
	var containerEvictedCount int

	cache := NewCache(time.Millisecond, time.Second)
	cache.AddCacheListener(CacheListener{
		PodEvicted: func(namespace string, name string) {
			podEvictedCount += 1
		},
		FreeContainerEvicted: func(hostname string, name string) {
			containerEvictedCount += 1
		},
	})

	var (
		pods       []source_api.Pod
		containers []source_api.Container
	)
	f := fuzz.New().NumElements(2, 10).NilChance(0)
	f.Fuzz(&pods)
	f.Fuzz(&containers)
	assert := assert.New(t)
	assert.NoError(cache.StorePods(pods))
	assert.NoError(cache.StoreContainers(containers))
	zeroTime := time.Time{}
	assert.NotEmpty(cache.GetFreeContainers(zeroTime, zeroTime))
	assert.NotEmpty(cache.GetPods(zeroTime, zeroTime))
	// Expect all data to be deleted after 2 seconds.
	time.Sleep(10 * time.Second)
	assert.Empty(cache.GetFreeContainers(zeroTime, zeroTime))
	assert.Empty(cache.GetPods(zeroTime, zeroTime))

	assert.Equal(len(pods), podEvictedCount)
	assert.Equal(len(containers), containerEvictedCount)
}
开发者ID:AlbertZheng,项目名称:heapster,代码行数:35,代码来源:cache_impl_test.go

示例8: getContainer

func getContainer(name string) source_api.Container {
	f := fuzz.New().NumElements(2, 2).NilChance(0)
	now := time.Now()
	containerSpec := source_api.ContainerSpec{
		ContainerSpec: cadvisor.ContainerSpec{
			CreationTime:  now,
			HasCpu:        true,
			HasMemory:     true,
			HasNetwork:    true,
			HasFilesystem: true,
			HasDiskIo:     true,
		},
	}
	containerStats := make([]*source_api.ContainerStats, 1)
	f.Fuzz(&containerStats)
	for idx := range containerStats {
		containerStats[idx].Timestamp = now
	}
	return source_api.Container{
		Name:  name,
		Spec:  containerSpec,
		Stats: containerStats,
		Image: "gcr.io/" + name,
	}
}
开发者ID:ravihansa3000,项目名称:heapster,代码行数:25,代码来源:impl_test.go

示例9: testTypeFuzzN

// Fuzz test for N iterations
func testTypeFuzzN(t *testing.T, base interface{}, ff interface{}, n int) {
	require.Implements(t, (*json.Marshaler)(nil), ff)
	require.Implements(t, (*json.Unmarshaler)(nil), ff)
	require.Implements(t, (*marshalerFaster)(nil), ff)
	require.Implements(t, (*unmarshalFaster)(nil), ff)

	if _, ok := base.(unmarshalFaster); ok {
		require.FailNow(t, "base should not have a UnmarshalJSONFFLexer")
	}

	if _, ok := base.(marshalerFaster); ok {
		require.FailNow(t, "base should not have a MarshalJSONBuf")
	}

	f := fuzz.New()
	f.NumElements(0, 1+n/40)
	f.NilChance(0.2)
	f.Funcs(fuzzTime, fuzzTimeSlice)
	for i := 0; i < n; i++ {
		f.RandSource(rand.New(rand.NewSource(int64(i * 5275))))
		f.Fuzz(base)
		f.RandSource(rand.New(rand.NewSource(int64(i * 5275))))
		f.Fuzz(ff)

		testSameMarshal(t, base, ff)
		testCycle(t, base, ff)
	}
}
开发者ID:gooops,项目名称:ffjson,代码行数:29,代码来源:fuzz_test.go

示例10: TestSyncLastUpdated

func TestSyncLastUpdated(t *testing.T) {
	as := assert.New(t)
	s1 := &DummySink{}
	c := cache.NewCache(time.Hour, time.Minute)
	m, err := newExternalSinkManager([]sink_api.ExternalSink{s1}, c, time.Microsecond)
	as.Nil(err)
	var (
		pods                                        []source_api.Pod
		containers                                  []source_api.Container
		events                                      []*cache.Event
		expectedESync, expectedPSync, expectedNSync time.Time
	)
	f := fuzz.New().NumElements(10, 10).NilChance(0)
	f.Fuzz(&pods)
	now := time.Now()
	for pidx := range pods {
		for cidx := range pods[pidx].Containers {
			for sidx := range pods[pidx].Containers[cidx].Stats {
				ts := now.Add(time.Duration(sidx) * time.Minute)
				pods[pidx].Containers[cidx].Stats[sidx].Timestamp = ts
				expectedPSync = hUtil.GetLatest(expectedPSync, ts)
			}
		}
	}
	f.Fuzz(&containers)
	for cidx := range containers {
		for sidx := range containers[cidx].Stats {
			ts := now.Add(time.Duration(sidx) * time.Minute)
			containers[cidx].Stats[sidx].Timestamp = ts
			expectedNSync = hUtil.GetLatest(expectedNSync, ts)
		}
	}
	f.Fuzz(&events)
	for eidx := range events {
		ts := now.Add(time.Duration(eidx) * time.Minute)
		events[eidx].LastUpdate = ts
		events[eidx].UID = fmt.Sprintf("id:%d", eidx)
		expectedESync = hUtil.GetLatest(expectedESync, ts)
	}
	err = c.StorePods(pods)
	if err != nil {
		glog.Fatalf("Failed to store pods %v", err)
	}
	err = c.StoreContainers(containers)
	if err != nil {
		glog.Fatalf("Failed to store containers %v", err)
	}
	err = c.StoreEvents(events)
	if err != nil {
		glog.Fatalf("Failed to store events %v", err)
	}
	m.store()
	as.Equal(m.lastSync.eventsSync, expectedESync, "Event now: %v, eventSync: %v, expected: %v", now, m.lastSync.eventsSync, expectedESync)
	as.Equal(m.lastSync.podSync, expectedPSync, "Pod now: %v, podSync: %v, expected: %v", now, m.lastSync.podSync, expectedPSync)
	as.Equal(m.lastSync.nodeSync, expectedNSync, "Node now: %v, nodeSync: %v, expected: %v", now, m.lastSync.nodeSync, expectedNSync)
}
开发者ID:apeeyush,项目名称:heapster,代码行数:56,代码来源:external_test.go

示例11: BenchmarkMatchLen256

func BenchmarkMatchLen256(b *testing.B) {
	size := 256
	ta := make([]byte, size)
	f := fuzz.New()
	f.NumElements(size, size)
	f.NilChance(0.0)
	f.Fuzz(&ta)
	b.SetBytes(int64(size))
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		_ = MatchLen(ta, ta, size)
	}
}
开发者ID:klauspost,项目名称:match,代码行数:13,代码来源:match_test.go

示例12: TestGC

func TestGC(t *testing.T) {
	var mutex sync.Mutex
	var podEvictedCount int
	var containerEvictedCount int

	cache := NewCache(time.Millisecond, time.Second)
	cache.AddCacheListener(CacheListener{
		PodEvicted: func(namespace string, name string) {
			mutex.Lock()
			defer mutex.Unlock()
			podEvictedCount += 1
		},
		FreeContainerEvicted: func(hostname string, name string) {
			mutex.Lock()
			defer mutex.Unlock()
			containerEvictedCount += 1
		},
	})

	var (
		pods       []source_api.Pod
		containers []source_api.Container
	)
	f := fuzz.New().NumElements(2, 10).NilChance(0)
	f.Fuzz(&pods)
	f.Fuzz(&containers)
	for i := range pods {
		pods[i].ID = fmt.Sprintf("ID-%d", i)
		pods[i].Name = fmt.Sprintf("%d-%s", i, pods[i].Name)
	}
	for i := range containers {
		containers[i].Hostname = fmt.Sprintf("Node-%d", i%5)
		containers[i].Name = fmt.Sprintf("%d-%s", i, containers[i].Name)
	}

	assert := assert.New(t)
	assert.NoError(cache.StorePods(pods))
	assert.NoError(cache.StoreContainers(containers))
	zeroTime := time.Time{}
	assert.NotEmpty(cache.GetFreeContainers(zeroTime, zeroTime))
	assert.NotEmpty(cache.GetPods(zeroTime, zeroTime))
	// Expect all data to be deleted after 2 seconds.
	time.Sleep(10 * time.Second)
	assert.Empty(cache.GetFreeContainers(zeroTime, zeroTime))
	assert.Empty(cache.GetPods(zeroTime, zeroTime))

	mutex.Lock()
	defer mutex.Unlock()
	assert.Equal(len(pods), podEvictedCount)
	assert.Equal(len(containers), containerEvictedCount)
}
开发者ID:ravihansa3000,项目名称:heapster,代码行数:51,代码来源:impl_test.go

示例13: BenchmarkMatch8

func BenchmarkMatch8(b *testing.B) {
	size := 32768
	ta := make([]byte, size)
	found := make([]int, 0, 10)
	f := fuzz.New()
	f.NumElements(size, size)
	f.NilChance(0.0)
	f.Fuzz(&ta)
	b.SetBytes(int64(size))
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		found = Match8(ta[800:808], ta, found)
	}
}
开发者ID:klauspost,项目名称:match,代码行数:14,代码来源:match_test.go

示例14: Stop

func (reaper *DaemonSetReaper) Stop(namespace, name string, timeout time.Duration, gracePeriod *api.DeleteOptions) (string, error) {
	ds, err := reaper.Experimental().DaemonSets(namespace).Get(name)
	if err != nil {
		return "", err
	}

	// Update the daemon set to select for a non-existent NodeName.
	// The daemon set controller will then kill all the daemon pods corresponding to daemon set.
	nodes, err := reaper.Nodes().List(labels.Everything(), fields.Everything())
	if err != nil {
		return "", err
	}
	var fuzzer = fuzz.New()
	var nameExists bool

	var nodeName string
	fuzzer.Fuzz(&nodeName)
	nameExists = false
	for _, node := range nodes.Items {
		nameExists = nameExists || node.Name == nodeName
	}
	if nameExists {
		// Probability of reaching here is extremely low, most likely indicates a programming bug/library error.
		return "", fmt.Errorf("Name collision generating an unused node name. Please retry this operation.")
	}

	ds.Spec.Template.Spec.NodeName = nodeName
	// force update to avoid version conflict
	ds.ResourceVersion = ""

	if ds, err = reaper.Experimental().DaemonSets(namespace).Update(ds); err != nil {
		return "", err
	}

	// Wait for the daemon set controller to kill all the daemon pods.
	if err := wait.Poll(reaper.pollInterval, reaper.timeout, func() (bool, error) {
		updatedDS, err := reaper.Experimental().DaemonSets(namespace).Get(name)
		if err != nil {
			return false, nil
		}
		return updatedDS.Status.CurrentNumberScheduled+updatedDS.Status.NumberMisscheduled == 0, nil
	}); err != nil {
		return "", err
	}

	if err := reaper.Experimental().DaemonSets(namespace).Delete(name); err != nil {
		return "", err
	}
	return fmt.Sprintf("%s stopped", name), nil
}
开发者ID:alena1108,项目名称:kubernetes,代码行数:50,代码来源:stop.go

示例15: BenchmarkMatch4Convert

// Shows the overhead of converting to bytes.
func BenchmarkMatch4Convert(b *testing.B) {
	size := 1024
	found := make([]int, 0, 10)
	ta := make([]byte, size)
	f := fuzz.New()
	f.NumElements(size, size)
	f.NilChance(0.0)
	f.Fuzz(&ta)
	txt := string(ta)
	b.SetBytes(int64(size))
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		found = Match4([]byte(txt[800:804]), []byte(txt), found)
	}
}
开发者ID:klauspost,项目名称:match,代码行数:16,代码来源:match_test.go


注:本文中的github.com/google/gofuzz.New函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。