test

package
v0.0.0-...-8ad424e Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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())
)
View Source
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 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

func AssertPropertyCount(
	t *testing.T,
	aType astmodel.Type,
	expected int,
)

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

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. 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 CreateFileDefinition

func CreateFileDefinition(definitions ...astmodel.TypeDefinition) *astmodel.FileDefinition

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

CreateResource makes a resource for testing

func CreateSimpleResource

func CreateSimpleResource(
	pkg astmodel.InternalPackageReference,
	name string,
	specProperties ...*astmodel.PropertyDefinition,
) astmodel.TypeDefinition

func CreateSpec

CreateSpec makes a spec for testing

func CreateStatus

CreateStatus makes a status for testing

func CreateTestFileDefinition

func CreateTestFileDefinition(definitions ...astmodel.TypeDefinition) *astmodel.TestFileDefinition

func MakeLocalPackageReference

func MakeLocalPackageReference(group string, version string) astmodel.LocalPackageReference

MakeLocalPackageReference makes a local package reference for testing purposes

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 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 (*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

Jump to

Keyboard shortcuts

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