Documentation ¶
Index ¶
- Variables
- func AssertDefinitionHasExpectedShape(t *testing.T, filename string, def astmodel.TypeDefinition)
- func AssertDefinitionsHaveExpectedShapes(t *testing.T, filename string, defs astmodel.TypeDefinitionSet)
- func AssertPackagesGenerateExpectedCode(t *testing.T, definitions astmodel.TypeDefinitionSet, ...)
- func AssertPropertyCount(t *testing.T, aType astmodel.Type, expected int)
- func AssertPropertyExists(t *testing.T, aType astmodel.Type, expectedName astmodel.PropertyName) *astmodel.PropertyDefinition
- func AssertPropertyExistsWithType(t *testing.T, aType astmodel.Type, expectedName astmodel.PropertyName, ...) *astmodel.PropertyDefinition
- func AssertSingleTypeDefinitionGeneratesExpectedCode(t *testing.T, fileName string, def astmodel.TypeDefinition, ...)
- func AssertTypeDefinitionsGenerateExpectedCode(t *testing.T, name string, defs []astmodel.TypeDefinition, ...)
- func CreateARMResource(pkg astmodel.InternalPackageReference, name string, ...) astmodel.TypeDefinition
- func CreateObjectDefinition(pkg astmodel.InternalPackageReference, name string, ...) astmodel.TypeDefinition
- func CreateObjectDefinitionWithFunction(pkg astmodel.InternalPackageReference, name string, function astmodel.Function, ...) astmodel.TypeDefinition
- func CreateObjectType(properties ...*astmodel.PropertyDefinition) *astmodel.ObjectType
- func CreateResource(pkg astmodel.InternalPackageReference, name string, ...) astmodel.TypeDefinition
- func CreateSimpleResource(pkg astmodel.InternalPackageReference, name string, ...) astmodel.TypeDefinition
- func CreateSpec(pkg astmodel.InternalPackageReference, name string, ...) astmodel.TypeDefinition
- func CreateStatus(pkg astmodel.InternalPackageReference, name string, ...) astmodel.TypeDefinition
- func MakeLocalPackageReference(group string, version string) astmodel.LocalPackageReference
- func MakeSpecName(pkg astmodel.InternalPackageReference, name string) astmodel.InternalTypeName
- func MakeStatusName(pkg astmodel.InternalPackageReference, name string) astmodel.InternalTypeName
- type AssertionOption
- type FakeFunction
- func (fake *FakeFunction) AsFunc(codeGenerationContext *astmodel.CodeGenerationContext, ...) (*dst.FuncDecl, error)
- func (fake *FakeFunction) Equals(f astmodel.Function, _ astmodel.EqualityOverrides) bool
- func (fake *FakeFunction) Name() string
- func (fake *FakeFunction) References() astmodel.TypeNameSet
- func (fake *FakeFunction) RequiredPackageReferences() *astmodel.PackageReferenceSet
- func (fake *FakeFunction) ReturnType() astmodel.Type
Constants ¶
This section is empty.
Variables ¶
var ( // Common groups for testing Group = "person" BatchGroup = "batch" // Properties to simplate an actual ARM resource NameProperty = astmodel.NewPropertyDefinition("Name", "name", astmodel.StringType). WithDescription("The name of the resource") FullNameProperty = astmodel.NewPropertyDefinition("FullName", "fullName", astmodel.StringType). WithDescription("As would be used to address mail") FamilyNameProperty = astmodel.NewPropertyDefinition("FamilyName", "familyName", astmodel.StringType). WithDescription("Shared name of the family") KnownAsProperty = astmodel.NewPropertyDefinition("KnownAs", "knownAs", astmodel.StringType). WithDescription("How the person is generally known") RestrictedNameProperty = astmodel.NewPropertyDefinition("RestrictedName", "restrictedName", astmodel.NewValidatedType(astmodel.StringType, astmodel.StringValidations{MaxLength: &maxRestrictedNameLength})). WithDescription("The name of the resource, restricted to max 25 character length") FullAddressProperty = astmodel.NewPropertyDefinition("FullAddress", "fullAddress", astmodel.StringType). WithDescription("Full written address for map or postal use") SuburbProperty = astmodel.NewPropertyDefinition("Suburb", "suburb", astmodel.StringType). WithDescription("Suburb within city or town") CityProperty = astmodel.NewPropertyDefinition("City", "city", astmodel.StringType). WithDescription("City or town (or nearest)") StatusProperty = astmodel.NewPropertyDefinition("Status", "status", astmodel.StringType). WithDescription("Current status") OptionalStringProperty = astmodel.NewPropertyDefinition("OptionalString", "optionalString", astmodel.OptionalStringType). WithDescription("An optional string") PropertyBagProperty = astmodel.NewPropertyDefinition("PropertyBag", "$propertyBag", astmodel.PropertyBagType). WithDescription("Stash for extra properties") // Reference Packages for 2020 Pkg2020 = MakeLocalPackageReference(Group, "v20200101") Pkg2020s = astmodel.MakeStoragePackageReference(Pkg2020) // Reference Package 2021 preview Pkg2021Preview = MakeLocalPackageReference(Group, "v20211231preview") Pkg2021PreviewStorage = astmodel.MakeStoragePackageReference(Pkg2021Preview) // Reference Packages for 2021 Pkg2021 = MakeLocalPackageReference(Group, "v20211231") Pkg2021s = astmodel.MakeStoragePackageReference(Pkg2021) // Reference Packages for 2022 Pkg2022 = MakeLocalPackageReference(Group, "v20220630") Pkg2022s = astmodel.MakeStoragePackageReference(Pkg2022) // Reference Package Batch 2020 BatchPkg2020 = MakeLocalPackageReference(BatchGroup, "v1api20200101") BatchPkg2020s = astmodel.MakeStoragePackageReference(BatchPkg2020) // Reference Package Batch 2021 BatchPkg2021 = MakeLocalPackageReference(BatchGroup, "v1api20210101") BatchPkg2021s = astmodel.MakeStoragePackageReference(BatchPkg2021) // Objects in Pkg2020 Pkg2020APIVersion = astmodel.MakeTypeDefinition( astmodel.MakeInternalTypeName(Pkg2020, "APIVersion"), astmodel.NewEnumType(astmodel.StringType, astmodel.MakeEnumValue("v2020", `"v2020"`))) Address2021 = CreateObjectDefinition(Pkg2021, "Address", FullAddressProperty, CityProperty) ResidentialAddress2021 = astmodel.NewPropertyDefinition("ResidentialAddress", "residentialAddress", Address2021.Name()) PostalAddress2021 = astmodel.NewPropertyDefinition("PostalAddress", "postalAddress", Address2021.Name()) )
var GoModulePrefix = "github.com/Azure/azure-service-operator/testing"
Functions ¶
func AssertDefinitionHasExpectedShape ¶
func AssertDefinitionHasExpectedShape( t *testing.T, filename string, def astmodel.TypeDefinition, )
AssertDefinitionHasExpectedShape fails the test if the given definition does not have the expected shape. t is the current test. filename is the name of the golden file to write. def is the definition to be asserted.
func AssertDefinitionsHaveExpectedShapes ¶
func AssertDefinitionsHaveExpectedShapes( t *testing.T, filename string, defs astmodel.TypeDefinitionSet, )
AssertDefinitionsHaveExpectedShapes fails the test if the given definition does not have the expected shape. t is the current test. filename is the name of the golden file to write. def is the definition to be asserted.
func AssertPackagesGenerateExpectedCode ¶
func AssertPackagesGenerateExpectedCode( t *testing.T, definitions astmodel.TypeDefinitionSet, options ...AssertionOption, )
AssertPackagesGenerateExpectedCode creates a golden file for each package represented in the set of type definitions, asserting that the generated content is expected. t is the current test definitions is the set of type definitions to be asserted options is an optional set of configuration options to control the assertion
func AssertPropertyCount ¶
AssertPropertyCount fails the test if the given object does not have the expected number of properties.
func AssertPropertyExists ¶
func AssertPropertyExists( t *testing.T, aType astmodel.Type, expectedName astmodel.PropertyName, ) *astmodel.PropertyDefinition
AssertPropertyExists fails the test if the given object does not have a property with the given name and type t is the current test. atype is the type that's expected to have the property. expectedName is the name of the property we expect to be present.
func AssertPropertyExistsWithType ¶
func AssertPropertyExistsWithType( t *testing.T, aType astmodel.Type, expectedName astmodel.PropertyName, expectedType astmodel.Type, ) *astmodel.PropertyDefinition
AssertPropertyExistsWithType fails the test if the given object does not have a property with the given name and type t is the current test. atype is the type that's expected to have the property. expectedName is the name of the property we expect to be present. expectedType is the type of the property we expect to be present.
func AssertSingleTypeDefinitionGeneratesExpectedCode ¶
func AssertSingleTypeDefinitionGeneratesExpectedCode( t *testing.T, fileName string, def astmodel.TypeDefinition, options ...AssertionOption, )
AssertSingleTypeDefinitionGeneratesExpectedCode serialises the given TypeDefinition as a golden file test, checking that the expected results are generated t is the current test name is a unique name for the current assertion def is the type definition to be asserted options is an optional set of configuration options to control the assertion
func AssertTypeDefinitionsGenerateExpectedCode ¶
func AssertTypeDefinitionsGenerateExpectedCode( t *testing.T, name string, defs []astmodel.TypeDefinition, options ...AssertionOption, )
AssertTypeDefinitionsGenerateExpectedCode serialises the given FileDefinition as a golden file test, checking that the expected results are generated t is the current test name is a unique name for the current assertion defs is a set of type definitions to be asserted options is an optional set of configuration options to control the assertion
func CreateARMResource ¶
func CreateARMResource( pkg astmodel.InternalPackageReference, name string, spec astmodel.TypeDefinition, status astmodel.TypeDefinition, apiVersion astmodel.TypeDefinition, functions ...astmodel.Function, ) astmodel.TypeDefinition
func CreateObjectDefinition ¶
func CreateObjectDefinition( pkg astmodel.InternalPackageReference, name string, properties ...*astmodel.PropertyDefinition, ) astmodel.TypeDefinition
CreateObjectDefinition makes a type definition with an object for testing
func CreateObjectDefinitionWithFunction ¶
func CreateObjectDefinitionWithFunction( pkg astmodel.InternalPackageReference, name string, function astmodel.Function, properties ...*astmodel.PropertyDefinition, ) astmodel.TypeDefinition
CreateObjectDefinitionWithFunction makes an object with function for testing
func CreateObjectType ¶
func CreateObjectType(properties ...*astmodel.PropertyDefinition) *astmodel.ObjectType
func CreateResource ¶
func CreateResource( pkg astmodel.InternalPackageReference, name string, spec astmodel.TypeDefinition, status astmodel.TypeDefinition, functions ...astmodel.Function, ) astmodel.TypeDefinition
CreateResource makes a resource for testing
func CreateSimpleResource ¶
func CreateSimpleResource( pkg astmodel.InternalPackageReference, name string, specProperties ...*astmodel.PropertyDefinition, ) astmodel.TypeDefinition
func CreateSpec ¶
func CreateSpec( pkg astmodel.InternalPackageReference, name string, properties ...*astmodel.PropertyDefinition, ) astmodel.TypeDefinition
CreateSpec makes a spec for testing
func CreateStatus ¶
func CreateStatus( pkg astmodel.InternalPackageReference, name string, properties ...*astmodel.PropertyDefinition, ) astmodel.TypeDefinition
CreateStatus makes a status for testing
func MakeLocalPackageReference ¶
func MakeLocalPackageReference(group string, version string) astmodel.LocalPackageReference
MakeLocalPackageReference makes a local package reference for testing purposes
func MakeSpecName ¶
func MakeSpecName( pkg astmodel.InternalPackageReference, name string, ) astmodel.InternalTypeName
func MakeStatusName ¶
func MakeStatusName( pkg astmodel.InternalPackageReference, name string, ) astmodel.InternalTypeName
Types ¶
type AssertionOption ¶
type AssertionOption interface {
// contains filtered or unexported methods
}
AssertionOption represents options that can be used to customize the behavour of the assert
func CreateFolderForTest ¶
func CreateFolderForTest() AssertionOption
CreateFolderForTest creates an AssertionOption to create a separate folder for the test, allowing the test to generate multiple files without collision with other tests.
func DiffWith ¶
func DiffWith(defs ...astmodel.TypeDefinition) AssertionOption
DiffWith specifies the type definitions being tested should be diff'd with the provided type definitions to highlight differences. TypeDefinitionSet are matched by fully qualified name.
func DiffWithTypes ¶
func DiffWithTypes(definitions astmodel.TypeDefinitionSet) AssertionOption
DiffWithTypes specifies the type definitions being tested should be diff'd with the provided type definitions to highlight differences. TypeDefinitionSet are matched by fully qualified name.
func ExcludeCodeFiles ¶
func ExcludeCodeFiles() AssertionOption
ExcludeCodeFiles creates an AssertionOption to suppress regular code files
func IncludeTestFiles ¶
func IncludeTestFiles() AssertionOption
IncludeTestFiles creates an AssertionOption to also assert generated tests
type FakeFunction ¶
type FakeFunction struct { Imported *astmodel.PackageReferenceSet Referenced astmodel.TypeNameSet TypeReturned astmodel.Type // contains filtered or unexported fields }
FakeFunction is a fake function that can be used for testing purposes Note that there's another FakeFunction in astmodel, but we can't eliminate that one because it would cause a package reference cycle
func NewFakeFunction ¶
func NewFakeFunction(name string, idFactory astmodel.IdentifierFactory) *FakeFunction
func (*FakeFunction) AsFunc ¶
func (fake *FakeFunction) AsFunc( codeGenerationContext *astmodel.CodeGenerationContext, receiver astmodel.InternalTypeName, ) (*dst.FuncDecl, error)
func (*FakeFunction) Equals ¶
func (fake *FakeFunction) Equals(f astmodel.Function, _ astmodel.EqualityOverrides) bool
func (*FakeFunction) Name ¶
func (fake *FakeFunction) Name() string
func (*FakeFunction) References ¶
func (fake *FakeFunction) References() astmodel.TypeNameSet
func (*FakeFunction) RequiredPackageReferences ¶
func (fake *FakeFunction) RequiredPackageReferences() *astmodel.PackageReferenceSet
func (*FakeFunction) ReturnType ¶
func (fake *FakeFunction) ReturnType() astmodel.Type