Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
c320931d
Commit
c320931d
authored
Apr 20, 2015
by
Tim Hockin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Easier fuzzing for volumes
parent
78356bf7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
10 deletions
+7
-10
fuzzer.go
pkg/api/testing/fuzzer.go
+7
-10
No files found.
pkg/api/testing/fuzzer.go
View file @
c320931d
...
...
@@ -18,6 +18,7 @@ package testing
import
(
"math/rand"
"reflect"
"strconv"
"testing"
...
...
@@ -34,13 +35,6 @@ import (
"speter.net/go/exp/math/dec/inf"
)
func
fuzzOneOf
(
c
fuzz
.
Continue
,
objs
...
interface
{})
{
// Use a new fuzzer which cannot populate nil to ensure one obj will be set.
f
:=
fuzz
.
New
()
.
NilChance
(
0
)
.
NumElements
(
1
,
1
)
i
:=
c
.
RandUint64
()
%
uint64
(
len
(
objs
))
f
.
Fuzz
(
objs
[
i
])
}
// FuzzerFor can randomly populate api objects that are destined for version.
func
FuzzerFor
(
t
*
testing
.
T
,
version
string
,
src
rand
.
Source
)
*
fuzz
.
Fuzzer
{
f
:=
fuzz
.
New
()
.
NilChance
(
.5
)
.
NumElements
(
1
,
1
)
...
...
@@ -171,9 +165,12 @@ func FuzzerFor(t *testing.T, version string, src rand.Source) *fuzz.Fuzzer {
*
rp
=
policies
[
c
.
Rand
.
Intn
(
len
(
policies
))]
},
func
(
vs
*
api
.
VolumeSource
,
c
fuzz
.
Continue
)
{
// Exactly one of the fields should be set.
//FIXME: the fuzz can still end up nil. What if fuzz allowed me to say that?
fuzzOneOf
(
c
,
&
vs
.
HostPath
,
&
vs
.
EmptyDir
,
&
vs
.
GCEPersistentDisk
,
&
vs
.
AWSElasticBlockStore
,
&
vs
.
GitRepo
,
&
vs
.
Secret
,
&
vs
.
NFS
,
&
vs
.
ISCSI
,
&
vs
.
Glusterfs
)
// Exactly one of the fields must be set.
v
:=
reflect
.
ValueOf
(
vs
)
.
Elem
()
i
:=
int
(
c
.
RandUint64
()
%
uint64
(
v
.
NumField
()))
v
=
v
.
Field
(
i
)
.
Addr
()
// Use a new fuzzer which cannot populate nil to ensure one field will be set.
fuzz
.
New
()
.
NilChance
(
0
)
.
NumElements
(
1
,
1
)
.
Fuzz
(
v
.
Interface
())
},
func
(
d
*
api
.
DNSPolicy
,
c
fuzz
.
Continue
)
{
policies
:=
[]
api
.
DNSPolicy
{
api
.
DNSClusterFirst
,
api
.
DNSDefault
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment