Documentation
¶
Overview ¶
Package testutils provides generator-specific test utilities.
This package contains generic test utilities, marshal failure test utilities, and other common testing functionality for generator packages.
Index ¶
- Variables
- func RunStandardGeneratorTests[T any](t *testing.T, gen generator.Generator[T, yamlgenerator.Options], ...)
- func TestExistingFile[T any](t *testing.T, gen generator.Generator[T, yamlgenerator.Options], cluster T, ...)
- func TestGenerateCommon[T any](t *testing.T, tests []GenerateTestCase, createCluster func(name string) T, ...)
- func TestGeneratorMarshalError[T, M any](t *testing.T, gen generator.Generator[T, yamlgenerator.Options], cluster T, ...)
- type GenerateTestCase
- type MarshalFailer
Constants ¶
This section is empty.
Variables ¶
var ErrMarshalFailed = errors.New("marshal failed")
ErrMarshalFailed is a common error for testing marshal failures.
Functions ¶
func RunStandardGeneratorTests ¶
func RunStandardGeneratorTests[T any]( t *testing.T, gen generator.Generator[T, yamlgenerator.Options], createCluster func(name string) T, expectedFileName string, assertContent func(*testing.T, string, string), )
RunStandardGeneratorTests runs the standard generator test suite.
func TestExistingFile ¶
func TestExistingFile[T any]( t *testing.T, gen generator.Generator[T, yamlgenerator.Options], cluster T, filename string, assertContent func(*testing.T, string, string), clusterName string, force bool, )
TestExistingFile runs a common test pattern for generators with existing files.
func TestGenerateCommon ¶
func TestGenerateCommon[T any]( t *testing.T, tests []GenerateTestCase, createCluster func(name string) T, gen generator.Generator[T, yamlgenerator.Options], assertContent func(*testing.T, string, string), expectedFileName string, )
TestGenerateCommon runs the common TestGenerate pattern with shared setup and assertions.
func TestGeneratorMarshalError ¶
func TestGeneratorMarshalError[T, M any]( t *testing.T, gen generator.Generator[T, yamlgenerator.Options], cluster T, expectedErrorContains string, )
TestGeneratorMarshalError runs a generic test pattern for generator marshal errors.
Types ¶
type GenerateTestCase ¶
type GenerateTestCase struct {
Name string
ClusterName string
SetupOutput func(t *testing.T) (output string, verifyFile bool, tempDir string)
ExpectError bool
Force bool
}
GenerateTestCase represents a test case for the basic TestGenerate pattern.
func GetStandardGenerateTestCases ¶
func GetStandardGenerateTestCases(expectedFileName string) []GenerateTestCase
GetStandardGenerateTestCases returns standard test cases for generator testing.
func GetStandardGenerateTestCasesWithForce ¶
func GetStandardGenerateTestCasesWithForce(expectedFileName string) []GenerateTestCase
GetStandardGenerateTestCasesWithForce returns standard test cases including force overwrite.
type MarshalFailer ¶
type MarshalFailer[T any] struct { marshaller.Marshaller[T] }
MarshalFailer is a generic marshal failer that can be used with any config type. It embeds the marshaller interface and overrides only the Marshal method to fail.
func (MarshalFailer[T]) Marshal ¶
func (m MarshalFailer[T]) Marshal(_ T) (string, error)
Marshal always returns an error for testing purposes.