-
Notifications
You must be signed in to change notification settings - Fork 0
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
chore: add go fuzz support #39
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
//go:build go1.18 | ||
|
||
package cli | ||
|
||
import ( | ||
"bytes" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/mineiros-io/terradoc/internal/parsers/docparser" | ||
"github.com/mineiros-io/terradoc/internal/renderers/markdown" | ||
) | ||
|
||
func FuzzGenerate(f *testing.F) { | ||
seedCorpus := []string{ | ||
`section { | ||
title = "test" | ||
variable "module_enabled" { | ||
type = bool | ||
} | ||
}`, | ||
`section { | ||
title = "test" | ||
section { | ||
a = 1 | ||
} | ||
}`, | ||
`section { | ||
variable "local_secondary_indexes" { | ||
type = any | ||
readme_type = "list(local_secondary_index)" | ||
} | ||
}`, | ||
} | ||
|
||
for _, seed := range seedCorpus { | ||
f.Add(seed) | ||
} | ||
|
||
f.Fuzz(func(t *testing.T, str string) { | ||
r := strings.NewReader(str) | ||
w := bytes.Buffer{} | ||
|
||
def, err := docparser.Parse(r, "in.hcl") | ||
if err != nil { | ||
return | ||
} | ||
|
||
_ = markdown.Render(&w, def) | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
go test fuzz v1 | ||
string("section{\nvariable\"\"{\ntype=\"\"\n}\n}") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
module github.com/mineiros-io/terradoc | ||
|
||
go 1.17 | ||
go 1.18 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does terradoc now require at least go 1.18 ? 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just added everything I had and committed.. this is not needed. With this change, I was testing if go1.17 still builds.. I'm going to mark this PR as draft. |
||
|
||
require ( | ||
github.com/alecthomas/kong v0.3.0 | ||
github.com/google/go-cmp v0.5.6 | ||
github.com/hashicorp/hcl/v2 v2.10.1 | ||
github.com/madlambda/spells v0.2.0 | ||
github.com/zclconf/go-cty v1.9.1 | ||
) | ||
|
||
require ( | ||
github.com/agext/levenshtein v1.2.1 // indirect | ||
github.com/alecthomas/kong v0.3.0 // indirect | ||
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect | ||
github.com/madlambda/spells v0.2.0 // indirect | ||
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 // indirect | ||
github.com/pkg/errors v0.9.1 // indirect | ||
golang.org/x/text v0.3.6 // indirect | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm maybe one property to check here is that if parsing worked, calling render should always write something on
w
if the return err is nil (not 100% sure this is always true, so maybe @thiesen can confirm). Like if the render suceeded, I think it always renders something, there is no scenario for empty rendering on terradoc I think 🤔 . But this can be done later anyway.