super-graph/core/internal/psql/fuzz.go

56 lines
784 B
Go
Raw Normal View History

2020-02-02 07:43:09 +01:00
// +build gofuzz
package psql
import (
"encoding/json"
"github.com/dosco/super-graph/core/internal/qcode"
2020-02-02 07:43:09 +01:00
)
var (
qcompileTest, _ = qcode.NewCompiler(qcode.Config{})
schema = GetTestSchema()
2020-02-02 07:43:09 +01:00
vars = map[string]string{
2020-02-02 07:43:09 +01:00
"admin_account_id": "5",
}
2020-02-02 07:43:09 +01:00
pcompileTest = NewCompiler(Config{
Schema: schema,
Vars: vars,
})
)
// FuzzerEntrypoint for Fuzzbuzz
func Fuzz(data []byte) int {
gql := `mutation {
product(insert: $data) {
id
name
user {
id
full_name
email
}
}
}`
qc, err := qcompileTest.Compile([]byte(gql), "user")
if err != nil {
panic("qcompile can't fail")
}
vars := map[string]json.RawMessage{
"data": json.RawMessage(data),
}
_, _, err = pcompileTest.CompileEx(qc, vars)
if err != nil {
return 0
}
return 1
}