-
Notifications
You must be signed in to change notification settings - Fork 458
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add fuzz test for configloader
That PR contains an example of how fuzz tests can be written with Go 1.18. It also fixes a few panics with invalid configs. Signed-off-by: Alexey Palazhchenko <alexey.palazhchenko@talos-systems.com>
- Loading branch information
Showing
8 changed files
with
836 additions
and
28 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
pkg/machinery/config/configloader/configloader_fuzz_test.go
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,37 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
//go:build go1.18 | ||
// +build go1.18 | ||
|
||
package configloader_test | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func FuzzConfigLoader(f *testing.F) { | ||
files, err := filepath.Glob(filepath.Join("testdata", "*.test")) | ||
require.NoError(f, err) | ||
|
||
for _, file := range files { | ||
b, err := os.ReadFile(file) | ||
require.NoError(f, err) | ||
f.Add(b) | ||
} | ||
|
||
f.Add([]byte(": \xea")) | ||
f.Add([]byte(nil)) | ||
f.Add([]byte("")) | ||
|
||
f.Fuzz(func(t *testing.T, b []byte) { | ||
t.Parallel() | ||
|
||
testConfigLoaderBytes(t, b) | ||
}) | ||
} |
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
Oops, something went wrong.