本文整理汇总了Golang中github.com/google/gofuzz.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: TestFuzz
func TestFuzz(t *testing.T) {
cache := NewCache(time.Hour, time.Second)
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))
time.Sleep(5 * time.Second)
zeroTime := time.Time{}
assert.NotEmpty(cache.GetPods(zeroTime, zeroTime))
}
开发者ID:AlbertZheng,项目名称:heapster,代码行数:16,代码来源:cache_impl_test.go
示例17: cmeFactory
// cmeFactory generates a complete ContainerMetricElement with fuzzed data.
// CMEs created by cmeFactory contain partially fuzzed stats, aside from hardcoded values for Memory usage.
// The timestamp of the CME is rouded to the current minute and offset by a random number of hours.
func cmeFactory() *cache.ContainerMetricElement {
f := fuzz.New().NilChance(0).NumElements(1, 1)
containerSpec := source_api.ContainerSpec{
ContainerSpec: cadvisor.ContainerSpec{
CreationTime: time.Now(),
HasCpu: true,
HasMemory: true,
HasNetwork: true,
HasFilesystem: true,
HasDiskIo: true,
},
}
containerSpec.Cpu.Limit = 1024
containerSpec.Memory.Limit = 10000000
// Create a fuzzed ContainerStats struct
var containerStats source_api.ContainerStats
f.Fuzz(&containerStats)
// Standardize timestamp to the current minute plus a random number of hours ([1, 10])
now_time := time.Now().Round(time.Minute)
new_time := now_time
for new_time == now_time {
new_time = now_time.Add(time.Duration(rand.Intn(10)) * 5 * time.Minute)
}
containerStats.Timestamp = new_time
containerSpec.CreationTime = new_time.Add(-time.Hour)
// Standardize memory usage and limit to test aggregation
containerStats.Memory.Usage = uint64(5000)
containerStats.Memory.WorkingSet = uint64(602)
// Standardize the device name, usage and limit
new_fs := cadvisor.FsStats{}
f.Fuzz(&new_fs)
new_fs.Device = "/dev/device1"
new_fs.Usage = 50000
new_fs.Limit = 100000
containerStats.Filesystem = []cadvisor.FsStats{new_fs}
return &cache.ContainerMetricElement{
Spec: &containerSpec,
Stats: &containerStats,
}
}
开发者ID:MohamedFAhmed,项目名称:heapster,代码行数:48,代码来源:impl_test.go
示例18: TestSetSinksStore
func TestSetSinksStore(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)
as.Equal(0, s1.StoredTimeseries)
as.Equal(0, s1.StoredEvents)
var (
pods []source_api.Pod
containers []source_api.Container
events []*cache.Event
)
f := fuzz.New().NumElements(1, 1).NilChance(0)
f.Fuzz(&pods)
f.Fuzz(&containers)
f.Fuzz(&events)
c.StorePods(pods)
c.StoreContainers(containers)
c.StoreEvents(events)
m.sync()
as.Equal(1, s1.StoredTimeseries)
as.Equal(1, s1.StoredEvents)
err = m.SetSinks([]sink_api.ExternalSink{})
as.Nil(err)
m.sync()
as.Equal(1, s1.StoredTimeseries)
as.Equal(1, s1.StoredEvents)
err = m.SetSinks([]sink_api.ExternalSink{s1})
as.Equal(1, s1.StoredTimeseries)
as.Equal(1, s1.StoredEvents)
as.Nil(err)
f.Fuzz(&pods)
f.Fuzz(&containers)
f.Fuzz(&events)
c.StorePods(pods)
c.StoreContainers(containers)
c.StoreEvents(events)
m.sync()
time.Sleep(time.Second)
as.Equal(2, s1.StoredTimeseries)
as.Equal(2, s1.StoredEvents)
}
开发者ID:apeeyush,项目名称:heapster,代码行数:44,代码来源:external_test.go
示例19: generateCustomMetrics
func generateCustomMetrics(spec []v1.MetricSpec) map[string][]v1.MetricVal {
ret := map[string][]v1.MetricVal{}
for _, metricSpec := range spec {
f := fuzz.New().NilChance(0).Funcs(
func(e *v1.MetricVal, c fuzz.Continue) {
switch metricSpec.Format {
case v1.IntType:
c.Fuzz(&e.IntValue)
case v1.FloatType:
c.Fuzz(&e.FloatValue)
}
})
var metrics []v1.MetricVal
f.Fuzz(&metrics)
ret[metricSpec.Name] = metrics
}
return ret
}
开发者ID:kubernetes,项目名称:kubernetes,代码行数:19,代码来源:summary_test.go
示例20: emptyCMEFactory
// emptyCMEFactory generates an empty ContainerMetricElement.
func emptyCMEFactory() *cache.ContainerMetricElement {
f := fuzz.New().NilChance(0).NumElements(1, 1)
containerSpec := cadvisor.ContainerSpec{
CreationTime: time.Now(),
HasCpu: false,
HasMemory: false,
HasNetwork: false,
HasFilesystem: false,
HasDiskIo: false,
}
var containerStats cadvisor.ContainerStats
f.Fuzz(&containerStats)
containerStats.Timestamp = time.Now()
return &cache.ContainerMetricElement{
Spec: &containerSpec,
Stats: &containerStats,
}
}
开发者ID:kshelton,项目名称:heapster,代码行数:20,代码来源:impl_test.go
注:本文中的github.com/google/gofuzz.New函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论