mirror of
https://github.com/siderolabs/talos.git
synced 2025-11-01 00:41:40 +01:00
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>
38 lines
741 B
Go
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)
|
|
})
|
|
}
|