From bd7509d8c9e56a9e60dadfdfd7291f22cc497c97 Mon Sep 17 00:00:00 2001 From: Tiago Natel Date: Thu, 31 Mar 2022 09:08:10 +0100 Subject: [PATCH] chore: add go fuzz support --- cmd/terradoc/cli/generate_fuzz_test.go | 51 +++++++++++++++++++ ...0976cd4ed84423fb5a97d0a54df55978d92947abb6 | 2 + go.mod | 6 +-- go.sum | 5 +- 4 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 cmd/terradoc/cli/generate_fuzz_test.go create mode 100644 cmd/terradoc/cli/testdata/fuzz/FuzzGenerate/167824474a7d2b13069b310976cd4ed84423fb5a97d0a54df55978d92947abb6 diff --git a/cmd/terradoc/cli/generate_fuzz_test.go b/cmd/terradoc/cli/generate_fuzz_test.go new file mode 100644 index 0000000..e21908c --- /dev/null +++ b/cmd/terradoc/cli/generate_fuzz_test.go @@ -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) + }) +} diff --git a/cmd/terradoc/cli/testdata/fuzz/FuzzGenerate/167824474a7d2b13069b310976cd4ed84423fb5a97d0a54df55978d92947abb6 b/cmd/terradoc/cli/testdata/fuzz/FuzzGenerate/167824474a7d2b13069b310976cd4ed84423fb5a97d0a54df55978d92947abb6 new file mode 100644 index 0000000..29f7b0b --- /dev/null +++ b/cmd/terradoc/cli/testdata/fuzz/FuzzGenerate/167824474a7d2b13069b310976cd4ed84423fb5a97d0a54df55978d92947abb6 @@ -0,0 +1,2 @@ +go test fuzz v1 +string("section{\nvariable\"\"{\ntype=\"\"\n}\n}") diff --git a/go.mod b/go.mod index 645a880..dbda1ff 100644 --- a/go.mod +++ b/go.mod @@ -1,18 +1,18 @@ module github.com/mineiros-io/terradoc -go 1.17 +go 1.18 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 diff --git a/go.sum b/go.sum index 4565f32..8cad58b 100644 --- a/go.sum +++ b/go.sum @@ -2,9 +2,9 @@ github.com/agext/levenshtein v1.2.1 h1:QmvMAjj2aEICytGiWzmxoE0x2KZvE0fvmqMOfy2tj github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= github.com/alecthomas/kong v0.3.0 h1:qOLFzu0dGPNz8z5TiXGzgW3gb3RXfWVJKeAxcghVW88= github.com/alecthomas/kong v0.3.0/go.mod h1:uzxf/HUh0tj43x1AyJROl3JT7SgsZ5m+icOv1csRhc0= +github.com/alecthomas/repr v0.0.0-20210801044451-80ca428c5142 h1:8Uy0oSf5co/NZXje7U1z8Mpep++QJOldL2hs/sBQf48= github.com/alecthomas/repr v0.0.0-20210801044451-80ca428c5142/go.mod h1:2kn6fqh/zIyPLmm3ugklbEi5hg5wS435eygvNfaDQL8= github.com/apparentlymart/go-dump v0.0.0-20180507223929-23540a00eaa3/go.mod h1:oL81AME2rN47vu18xqj1S1jPIPuN7afo62yKTNn3XMM= -github.com/apparentlymart/go-textseg v1.0.0 h1:rRmlIsPEEhUTIKQb7T++Nz/A5Q6C9IuX2wFoYVvnCs0= github.com/apparentlymart/go-textseg v1.0.0/go.mod h1:z96Txxhf3xSFMPmb5X/1W05FF/Nj9VFpLOpjS5yuumk= github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw= github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo= @@ -34,12 +34,14 @@ github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 h1:DpOJ2HYzC github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4= @@ -72,4 +74,5 @@ google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCID gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=