Help us shape the future of Go! Take the 2026 Go Developer Survey

testutils

package
v2.950.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2026 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateOpenAPIDoc

func CreateOpenAPIDoc(schemasYAML string) string

CreateOpenAPIDoc creates a full OpenAPI document with the given schemas YAML

func DeepCompare

func DeepCompare(t *testing.T, expected, actual interface{}) bool

DeepCompare performs a deep comparison of two values using reflection and prints differences

func DefaultFixes

func DefaultFixes() *config.Fixes

func IndentYAML

func IndentYAML(yaml string, indent string) string

IndentYAML indents YAML content with the given indent string

func NewDiscriminator

func NewDiscriminator(propertyName string, mappings ...*ast.DiscriminatorMapping) *ast.Discriminator

NewDiscriminator creates a new discriminator with the given property name

func NewDiscriminatorMapping

func NewDiscriminatorMapping(name string, typeDef *ast.TypeDef) *ast.DiscriminatorMapping

NewDiscriminatorMapping creates a new discriminator mapping

func NewFloatExample

func NewFloatExample(value string) *ast.Example

NewFloatExample creates a new example with the given float value

func NewIntExample

func NewIntExample(value string) *ast.Example

NewIntExample creates a new example with the given integer value

func NewSecurityAnnotation

func NewSecurityAnnotation(fieldName, secType, subType, schemeKey string, scheme, securityOption bool) *ast.SecurityAnnotation

NewSecurityAnnotation creates a security annotation with the given parameters

func WithNameOverrideFeb2026

func WithNameOverrideFeb2026(v bool) *config.Fixes

Types

type CommonTestSetup

type CommonTestSetup struct {
	DocInfo   *document.DocumentInfo
	Target    types.Target
	Config    *configuration.Config
	Subsystem *subsystem.Subsystem
	Namer     *namer.Namer
}

CommonTestSetup encapsulates the common test setup components

func SetupTestEnvironment

func SetupTestEnvironment(opts TestEnvironmentOptions) (*CommonTestSetup, error)

SetupTestEnvironment creates a complete test environment with the given configuration

type ContextStackBuilder

type ContextStackBuilder struct {
	// contains filtered or unexported fields
}

ContextStackBuilder provides a fluent interface for building context stacks

func NewContextStack

func NewContextStack() *ContextStackBuilder

NewContextStack creates a new ContextStackBuilder

func (*ContextStackBuilder) Build

Build returns the constructed context stack

func (*ContextStackBuilder) WithComponent

func (b *ContextStackBuilder) WithComponent() *ContextStackBuilder

WithComponent adds a component context frame

func (*ContextStackBuilder) WithConstProperty

func (b *ContextStackBuilder) WithConstProperty(identifier string) *ContextStackBuilder

WithConstProperty adds a constProperty context frame

func (*ContextStackBuilder) WithIdentifierForNaming

func (b *ContextStackBuilder) WithIdentifierForNaming(identifierForNaming *string) *ContextStackBuilder

WithIdentifierForNaming sets the IdentifierForNaming for the last frame in the stack

func (*ContextStackBuilder) WithInputOutput

func (b *ContextStackBuilder) WithInputOutput(suffix string) *ContextStackBuilder

WithInputOutput adds an inputOutput context frame

func (*ContextStackBuilder) WithModelNamespace

func (b *ContextStackBuilder) WithModelNamespace(namespace string) *ContextStackBuilder

WithModelNamespace adds a modelNamespace context frame

func (*ContextStackBuilder) WithOneOf

func (b *ContextStackBuilder) WithOneOf(identifier string) *ContextStackBuilder

WithOneOf adds a oneOf context frame

func (*ContextStackBuilder) WithOneOfPosition

func (b *ContextStackBuilder) WithOneOfPosition(position string, identifierForNaming *string) *ContextStackBuilder

WithOneOfPosition adds a oneOfPosition context frame

func (*ContextStackBuilder) WithRefName

func (b *ContextStackBuilder) WithRefName(refName string) *ContextStackBuilder

WithRefName adds a reference name context frame

func (*ContextStackBuilder) WithRefType

func (b *ContextStackBuilder) WithRefType(refType string) *ContextStackBuilder

WithRefType adds a reference type context frame

func (*ContextStackBuilder) WithStandardOneOfContext

func (b *ContextStackBuilder) WithStandardOneOfContext(position string) *ContextStackBuilder

WithStandardOneOfContext adds the standard oneOf context pattern (oneOf + oneOfPosition)

type FieldDefBuilder

type FieldDefBuilder struct {
	// contains filtered or unexported fields
}

FieldDefBuilder provides a fluent interface for building FieldDef structures

func NewFieldDef

func NewFieldDef(name string, typeDef *ast.TypeDef) *FieldDefBuilder

NewFieldDef creates a new FieldDefBuilder

func (*FieldDefBuilder) Build

func (b *FieldDefBuilder) Build() *ast.FieldDef

Build returns the constructed FieldDef

func (*FieldDefBuilder) WithAnnotations

func (b *FieldDefBuilder) WithAnnotations(annotations ...ast.Annotation) *FieldDefBuilder

WithAnnotations adds annotations

func (*FieldDefBuilder) WithComments

func (b *FieldDefBuilder) WithComments(comments *ast.Comment) *FieldDefBuilder

WithComments sets the comments for the field

func (*FieldDefBuilder) WithConst

func (b *FieldDefBuilder) WithConst(constValue *ast.AnyValue) *FieldDefBuilder

WithConst sets the const value

func (*FieldDefBuilder) WithDefault

func (b *FieldDefBuilder) WithDefault(defaultValue *ast.AnyValue) *FieldDefBuilder

WithDefault sets the default value

func (*FieldDefBuilder) WithIsAdditionalProperties

func (b *FieldDefBuilder) WithIsAdditionalProperties(isAdditionalProperties bool) *FieldDefBuilder

WithIsAdditionalProperties sets the IsAdditionalProperties flag

func (*FieldDefBuilder) WithJSONAnnotation

func (b *FieldDefBuilder) WithJSONAnnotation(fieldName string) *FieldDefBuilder

WithJSONAnnotation adds a JSON annotation

func (*FieldDefBuilder) WithNullable

func (b *FieldDefBuilder) WithNullable(nullable bool) *FieldDefBuilder

WithNullable sets the nullable flag

func (*FieldDefBuilder) WithOptional

func (b *FieldDefBuilder) WithOptional(optional bool) *FieldDefBuilder

WithOptional sets the optional flag

func (*FieldDefBuilder) WithOriginalName

func (b *FieldDefBuilder) WithOriginalName(name string) *FieldDefBuilder

WithOriginalName sets the original name

func (*FieldDefBuilder) WithParameterIndex

func (b *FieldDefBuilder) WithParameterIndex(index *int) *FieldDefBuilder

WithParameterIndex sets the parameter index

type MockFeatures

type MockFeatures struct {
	// contains filtered or unexported fields
}

MockFeatures is a configurable mock implementation of the subsystem.Features interface

func NewMockFeatures

func NewMockFeatures(config *MockFeaturesConfig) *MockFeatures

NewMockFeatures creates a new MockFeatures with the given configuration

func (*MockFeatures) CollectGlobalsAndServersModels

func (m *MockFeatures) CollectGlobalsAndServersModels(ctx context.Context) bool

func (*MockFeatures) GetAutoGeneratedHeader

func (m *MockFeatures) GetAutoGeneratedHeader(ctx context.Context, generatedID string) string

func (*MockFeatures) GetAvailableFeatures

func (m *MockFeatures) GetAvailableFeatures(ctx context.Context) map[string]bool

func (*MockFeatures) GetFeatureUsage

func (m *MockFeatures) GetFeatureUsage(ctx context.Context) map[string]bool

func (*MockFeatures) GetFeatureVersion

func (m *MockFeatures) GetFeatureVersion(ctx context.Context, feature features.Feature) string

func (*MockFeatures) GetImplementedFeaturesList

func (m *MockFeatures) GetImplementedFeaturesList(ctx context.Context) []features.Feature

func (*MockFeatures) GetUsedFeatures

func (m *MockFeatures) GetUsedFeatures(ctx context.Context) map[string]string

func (*MockFeatures) IsFeatureEnabled

func (m *MockFeatures) IsFeatureEnabled(ctx context.Context, feature features.Feature) bool

func (*MockFeatures) IsFeatureIgnored

func (m *MockFeatures) IsFeatureIgnored(ctx context.Context, feature features.Feature) bool

func (*MockFeatures) IsFeatureSupported

func (m *MockFeatures) IsFeatureSupported(ctx context.Context, feature features.Feature) bool

func (*MockFeatures) IsFeatureUsed

func (m *MockFeatures) IsFeatureUsed(feature features.Feature) bool

func (*MockFeatures) IsReadmeSectionIgnored

func (m *MockFeatures) IsReadmeSectionIgnored(ctx context.Context, readmeSectionID string) bool

func (*MockFeatures) IsReadmeSectionImplemented

func (m *MockFeatures) IsReadmeSectionImplemented(ctx context.Context, readmeSectionID string) bool

func (*MockFeatures) IsUnionWrapper

func (m *MockFeatures) IsUnionWrapper(ctx context.Context) bool

func (*MockFeatures) RecordFeatureUsage

func (m *MockFeatures) RecordFeatureUsage(ctx context.Context, feature features.Feature)

func (*MockFeatures) RegisterReadmeSectionTemplated

func (m *MockFeatures) RegisterReadmeSectionTemplated(readmeSectionID string, feature features.Feature)

func (*MockFeatures) ReinstateFeatureUsage

func (m *MockFeatures) ReinstateFeatureUsage(ctx context.Context, featureUsage map[string]bool)

func (*MockFeatures) Target

func (m *MockFeatures) Target() types.Target

type MockFeaturesConfig

type MockFeaturesConfig struct {
	Target                         types.Target
	SupportedFeatures              map[features.Feature]bool
	EnabledFeatures                map[features.Feature]bool
	IgnoredFeatures                map[features.Feature]bool
	FeatureVersions                map[features.Feature]string
	IsUnionWrapper                 bool
	ReadmeSectionImplemented       map[string]bool
	ReadmeSectionIgnored           map[string]bool
	AvailableFeatures              map[string]bool
	UsedFeatures                   map[features.Feature]bool
	AutoGeneratedHeader            string
	CollectGlobalsAndServersModels bool
}

MockFeaturesConfig allows configuring the behavior of MockFeatures

func NewMockFeaturesConfig

func NewMockFeaturesConfig() *MockFeaturesConfig

NewMockFeaturesConfig creates a default configuration for MockFeatures

func (*MockFeaturesConfig) WithSupportAllFeatures

func (c *MockFeaturesConfig) WithSupportAllFeatures() *MockFeaturesConfig

WithSupportAllFeatures configures the mock to support all features by default

func (*MockFeaturesConfig) WithTarget

func (c *MockFeaturesConfig) WithTarget(target types.Target) *MockFeaturesConfig

WithTarget sets the target for the mock

type SecurityBuilder

type SecurityBuilder struct {
	// contains filtered or unexported fields
}

SecurityBuilder provides a fluent interface for building Security structures

func NewSecurity

func NewSecurity() *SecurityBuilder

NewSecurity creates a new SecurityBuilder

func (*SecurityBuilder) Build

func (b *SecurityBuilder) Build() *ast.Security

Build returns the constructed Security

func (*SecurityBuilder) WithDisabled

func (b *SecurityBuilder) WithDisabled(disabled bool) *SecurityBuilder

WithDisabled sets the disabled flag

func (*SecurityBuilder) WithHoistedSecurityConfig

func (b *SecurityBuilder) WithHoistedSecurityConfig(equivalent bool, fields []ast.HoistedSecurityField) *SecurityBuilder

func (*SecurityBuilder) WithOAuth2Config

func (b *SecurityBuilder) WithOAuth2Config(schemeName string, flow string, description string, requiredScopes []string, availableScopes []ast.OAuth2Scope) *SecurityBuilder

WithOAuth2Config sets the OAuth2 config with Comments and AvailableScopes

`schemeName` is the security scheme name (e.g., "OAuth2ClientCredentials")
`flow` is the OAuth2 flow type in snake_case (e.g., "client_credentials")
`description` is the security scheme description
`requiredScopes` are the *required* OAuth2 scopes
`availableScopes` holds *available* OAuth2 scopes and their description

func (*SecurityBuilder) WithOptionalityReason

func (b *SecurityBuilder) WithOptionalityReason(reason ast.SecurityOptionalityReason) *SecurityBuilder

WithOptionalityReason sets the optionality reason

func (*SecurityBuilder) WithRequirements

func (b *SecurityBuilder) WithRequirements(reqs ...ast.SecurityRequirement) *SecurityBuilder

WithRequirements adds security requirements. Each requirement is a sorted slice of scheme keys.

func (*SecurityBuilder) WithSchemes

func (b *SecurityBuilder) WithSchemes(schemes ...string) *SecurityBuilder

WithSchemes is a convenience wrapper around WithRequirements that accepts dash-separated scheme keys (e.g. "ApiKeyAuth", "ApiKeyAuth-BasicAuth"). Each argument becomes one SecurityRequirement; dashes split into AND schemes.

func (*SecurityBuilder) WithSecurity

func (b *SecurityBuilder) WithSecurity(security *ast.FieldDef) *SecurityBuilder

WithSecurity sets the security field

type TestEnvironmentOptions

type TestEnvironmentOptions struct {
	// OpenAPI YAML content
	OpenAPIYAML string

	// Configuration fixes
	Fixes *config.Fixes

	// Feature configuration - can use either feature maps OR MockFeaturesConfig
	SupportedFeatures map[features.Feature]bool
	EnabledFeatures   map[features.Feature]bool
	MockFeatures      *MockFeaturesConfig

	Schemas *config.Schemas

	// Target language (defaults to "go")
	Target string

	// Whether to maintain OpenAPI field order (defaults to false)
	MaintainOpenAPIOrder *bool
}

TestEnvironmentOptions provides configuration options for test environment setup

type TypeDefBuilder

type TypeDefBuilder struct {
	// contains filtered or unexported fields
}

TypeDefBuilder provides a fluent interface for building TypeDef structures

func NewEnumTypeDef

func NewEnumTypeDef(enumType ast.DataType, values []string, format string) *TypeDefBuilder

NewEnumTypeDef creates a complete enum TypeDef with the given values and format

func NewTypeDef

func NewTypeDef(dataType ast.DataType) *TypeDefBuilder

NewTypeDef creates a new TypeDefBuilder with basic defaults

func NewTypeDefWithoutValidations

func NewTypeDefWithoutValidations(dataType ast.DataType) *TypeDefBuilder

NewTypeDefWithoutValidations creates a TypeDefBuilder with the given parameters

func (*TypeDefBuilder) Build

func (b *TypeDefBuilder) Build() *ast.TypeDef

Build returns the constructed TypeDef

func (*TypeDefBuilder) WithAssociatedTypes

func (b *TypeDefBuilder) WithAssociatedTypes(types ...*ast.TypeDef) *TypeDefBuilder

WithAssociatedTypes adds associated types for unions

func (*TypeDefBuilder) WithComments

func (b *TypeDefBuilder) WithComments(comments *ast.Comment) *TypeDefBuilder

WithComments sets the comments

func (*TypeDefBuilder) WithComplexAny

func (b *TypeDefBuilder) WithComplexAny(complexAny bool) *TypeDefBuilder

WithComplexAny sets the ComplexAny flag

func (*TypeDefBuilder) WithContainsNull

func (b *TypeDefBuilder) WithContainsNull(containsNull bool) *TypeDefBuilder

WithContainsNull sets the ContainsNull flag for arrays

func (*TypeDefBuilder) WithContextStack

func (b *TypeDefBuilder) WithContextStack(stack ast.ContextStack) *TypeDefBuilder

WithContextStack sets the context stack

func (*TypeDefBuilder) WithDeduplicatedContextStacks

func (b *TypeDefBuilder) WithDeduplicatedContextStacks(stacks ...ast.ContextStack) *TypeDefBuilder

WithDeduplicatedContextStacks sets the deduplicated context stacks

func (*TypeDefBuilder) WithDiscriminator

func (b *TypeDefBuilder) WithDiscriminator(discriminator *ast.Discriminator) *TypeDefBuilder

WithDiscriminator sets the discriminator

func (*TypeDefBuilder) WithEmptyFields

func (b *TypeDefBuilder) WithEmptyFields() *TypeDefBuilder

WithEmptyFields explicitly sets Fields to an empty slice (not nil)

func (*TypeDefBuilder) WithEnum

func (b *TypeDefBuilder) WithEnum(enumType *ast.TypeDef, values []string, format string) *TypeDefBuilder

WithEnum sets enum properties

func (*TypeDefBuilder) WithEnumNames

func (b *TypeDefBuilder) WithEnumNames(names []string) *TypeDefBuilder

WithEnumNames sets the names on the enum for custom enum names

func (*TypeDefBuilder) WithEnumUnderlyingLocation

func (b *TypeDefBuilder) WithEnumUnderlyingLocation(node *yaml.Node) *TypeDefBuilder

WithEnumUnderlyingLocation sets the location on the underlying type for enum TypeDefs

func (*TypeDefBuilder) WithExamples

func (b *TypeDefBuilder) WithExamples(examples ...*ast.Example) *TypeDefBuilder

WithExamples sets the examples

func (*TypeDefBuilder) WithExtensions

func (b *TypeDefBuilder) WithExtensions(extensions map[string]interface{}) *TypeDefBuilder

WithExtensions sets the extensions

func (*TypeDefBuilder) WithFields

func (b *TypeDefBuilder) WithFields(fields ...*ast.FieldDef) *TypeDefBuilder

WithFields adds fields to the type

func (*TypeDefBuilder) WithFormat

func (b *TypeDefBuilder) WithFormat(format string) *TypeDefBuilder

WithFormat sets the format

func (*TypeDefBuilder) WithInput

func (b *TypeDefBuilder) WithInput(input bool) *TypeDefBuilder

WithInput sets the Input flag

func (*TypeDefBuilder) WithIsComponent

func (b *TypeDefBuilder) WithIsComponent(isComponent bool) *TypeDefBuilder

WithIsComponent sets the IsComponent flag

func (*TypeDefBuilder) WithIsMultipartFile

func (b *TypeDefBuilder) WithIsMultipartFile(isMultipartFile bool) *TypeDefBuilder

WithIsMultipartFile sets the IsMultipartFile flag

func (*TypeDefBuilder) WithItemType

func (b *TypeDefBuilder) WithItemType(itemType *ast.TypeDef) *TypeDefBuilder

WithItemType sets the item type for arrays and maps

func (*TypeDefBuilder) WithLocation

func (b *TypeDefBuilder) WithLocation(node *yaml.Node) *TypeDefBuilder

WithLocation sets the OpenAPI location

func (*TypeDefBuilder) WithModelNamespace

func (b *TypeDefBuilder) WithModelNamespace(namespace string) *TypeDefBuilder

WithModelNamespace sets the model namespace

func (*TypeDefBuilder) WithName

func (b *TypeDefBuilder) WithName(name string) *TypeDefBuilder

WithName sets the type name

func (*TypeDefBuilder) WithOriginalName

func (b *TypeDefBuilder) WithOriginalName(originalName string) *TypeDefBuilder

WithOriginalName sets the original name separately

func (*TypeDefBuilder) WithOriginalNameFrozen

func (b *TypeDefBuilder) WithOriginalNameFrozen() *TypeDefBuilder

WithOriginalNameFrozen marks the original name as frozen

func (*TypeDefBuilder) WithOutput

func (b *TypeDefBuilder) WithOutput(output bool) *TypeDefBuilder

WithOutput sets the Output flag

func (*TypeDefBuilder) WithRegistered

func (b *TypeDefBuilder) WithRegistered() *TypeDefBuilder

WithRegistered marks the type as registered

func (*TypeDefBuilder) WithScope

func (b *TypeDefBuilder) WithScope(scope ast.Scope) *TypeDefBuilder

WithScope sets the scope

func (*TypeDefBuilder) WithTruncated

func (b *TypeDefBuilder) WithTruncated(truncated bool) *TypeDefBuilder

WithTruncated sets the Truncated flag

func (*TypeDefBuilder) WithUsedInUnion

func (b *TypeDefBuilder) WithUsedInUnion() *TypeDefBuilder

WithUsedInUnion marks the type as used in a union

func (*TypeDefBuilder) WithValidations

func (b *TypeDefBuilder) WithValidations(validations *ast.Validations) *TypeDefBuilder

WithValidations sets custom validations (overrides default)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL