forked from fluxcd/pkg
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch_fuzz_test.go
More file actions
55 lines (45 loc) · 1.08 KB
/
Copy pathpatch_fuzz_test.go
File metadata and controls
55 lines (45 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package conditions
import (
"testing"
fuzz "github.com/AdaLogics/go-fuzz-headers"
"github.com/fluxcd/pkg/runtime/conditions/testdata"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func Fuzz_PatchApply(f *testing.F) {
f.Fuzz(func(t *testing.T,
beforeData, afterData, setterData []byte) {
before, err := newFake(fuzz.NewConsumer(beforeData))
if err != nil {
return
}
after, err := newFake(fuzz.NewConsumer(afterData))
if err != nil {
return
}
patch := NewPatch(before, after)
setter, err := newFake(fuzz.NewConsumer(setterData))
if err != nil {
return
}
_ = patch.Apply(setter)
})
}
func newFake(fc *fuzz.ConsumeFuzzer) (*testdata.Fake, error) {
obj := &testdata.Fake{}
noOfConditions, err := fc.GetInt()
if err != nil {
return obj, err
}
maxNoOfConditions := 30
conditions := make([]metav1.Condition, 0)
for i := 0; i < noOfConditions%maxNoOfConditions; i++ {
c := metav1.Condition{}
err = fc.GenerateStruct(&c)
if err != nil {
return obj, err
}
conditions = append(conditions, c)
}
obj.SetConditions(conditions)
return obj, nil
}