-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: Improve fuzz tests' reliability
Establish conventions which aligns with what is supported upstream today, whilst expanding on documentation to ensure other contributors have pointers on how to debug/check for issues going forwards. Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
- Loading branch information
Paulo Gomes
committed
Nov 23, 2022
1 parent
ab2b4eb
commit a877fb6
Showing
7 changed files
with
149 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
Copyright 2020 The Kubernetes Authors. | ||
Copyright 2021 The Flux authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package conditions | ||
|
||
import ( | ||
"testing" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
) | ||
|
||
func Fuzz_Unstructured(f *testing.F) { | ||
f.Add("type", "reason true", "condition message") | ||
|
||
f.Fuzz(func(t *testing.T, | ||
ct, reason, message string) { | ||
|
||
cs := []metav1.Condition{{ | ||
Type: ct, | ||
Status: metav1.ConditionUnknown, | ||
Reason: reason, | ||
Message: message, | ||
}} | ||
|
||
u := &unstructured.Unstructured{ | ||
Object: map[string]interface{}{}, | ||
} | ||
s := UnstructuredSetter(u) | ||
s.SetConditions(cs) | ||
|
||
g := UnstructuredGetter(u) | ||
_ = g.GetConditions() | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters