Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding fuzz tests #392

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions graphql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5725,3 +5725,28 @@ func Test_fieldFunc(t *testing.T) {
},
})
}

type query struct{}

func (_ *query) Hello() string { return "Hello, world!" }
func (_ *query) Hi(string, string) string { return "Hello, world!" }
func (_ *query) LaunchMissil(string, string) string { return "Hello, world!" }

func FuzzSchemaExec(f *testing.F) {
f.Fuzz(func(t *testing.T, s string, queryString , operationName string) {
defer func(){
if err := recover(); err != nil{
if !strings.Contains(err.(error).Error(), "invalid syntax"){
panic(err)
}
}
}()
ctx := context.Background()
variables := map[string]interface{}{}
schema,err := graphql.ParseSchema(s, &query{})
if err != nil {
t.Skip()
}
schema.Exec(ctx, queryString, operationName, variables)
})
}
12 changes: 12 additions & 0 deletions internal/query/query_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package query

import (
"testing"
)

func FuzzParseQuery(f *testing.F) {
f.Fuzz(func(t *testing.T, queryStr string) {
Parse(queryStr)
})
}

7 changes: 7 additions & 0 deletions internal/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1143,3 +1143,10 @@ func TestInterfaceImplementsInterface(t *testing.T) {
})
}
}

func FuzzParse(f *testing.F){
f.Fuzz(func(t *testing.T, schemaString string, useStringDescriptions bool){
s := schema.New()
schema.Parse(s, schemaString, useStringDescriptions)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When using string descriptions the syntax changes. So maybe we'll end up with a bunch of syntax errors which are expected. I wonder how beneficial is such a test. As in what are the type of errors that we could catch and prevent.

})
}
Loading