talos/pkg/machinery/config/configloader/configloader_fuzz_test.go
Alexey Palazhchenko 95f440eaa0
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>
2021-09-27 18:44:46 +00:00

38 lines
741 B
Go

// 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)
})
}