-
Notifications
You must be signed in to change notification settings - Fork 716
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added fuzz tests for subscriber (#4507)
* added fuzz tests for subscriber Signed-off-by: Amit Kumar Das <amit.das@harness.io> * fixed go fmt Signed-off-by: Amit Kumar Das <amit.das@harness.io> --------- Signed-off-by: Amit Kumar Das <amit.das@harness.io> Co-authored-by: Vedant Shrotria <vedant.shrotria@harness.io>
- Loading branch information
Showing
5 changed files
with
243 additions
and
0 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 2 additions & 0 deletions
2
chaoscenter/subscriber/pkg/events/testdata/fuzz/FuzzGenerateWorkflowPayload/582528ddfad69eb5
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,2 @@ | ||
go test fuzz v1 | ||
[]byte("0") |
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,42 @@ | ||
package events | ||
|
||
import ( | ||
"fmt" | ||
"subscriber/pkg/graphql" | ||
"subscriber/pkg/k8s" | ||
"subscriber/pkg/types" | ||
"testing" | ||
|
||
fuzz "github.com/AdaLogics/go-fuzz-headers" | ||
"github.com/golang/mock/gomock" | ||
) | ||
|
||
func FuzzGenerateWorkflowPayload(f *testing.F) { | ||
f.Fuzz(func(t *testing.T, data []byte) { | ||
fuzzConsumer := fuzz.NewConsumer(data) | ||
|
||
targetStruct := &struct { | ||
cid, accessKey, version, completed string | ||
wfEvent types.WorkflowEvent | ||
}{} | ||
err := fuzzConsumer.GenerateStruct(targetStruct) | ||
if err != nil { | ||
return | ||
} | ||
|
||
ctrl := gomock.NewController(t) | ||
defer ctrl.Finish() | ||
subscriberGraphql := graphql.NewSubscriberGql() | ||
subscriberK8s := k8s.NewK8sSubscriber(subscriberGraphql) | ||
subscriberEvents := NewSubscriberEventsOperator(subscriberGraphql, subscriberK8s) | ||
|
||
event, err := subscriberEvents.GenerateWorkflowPayload(targetStruct.cid, targetStruct.accessKey, targetStruct.version, targetStruct.completed, targetStruct.wfEvent) | ||
if err != nil { | ||
fmt.Println(event) | ||
t.Errorf("Unexpected error: %v", err) | ||
} | ||
if event == nil { | ||
t.Errorf("Returned payload is nil") | ||
} | ||
}) | ||
} |