From 71cfc55498c2fe63c6251f18f60b8ab9b8126ea5 Mon Sep 17 00:00:00 2001 From: Bevan Arps Date: Wed, 27 Mar 2024 16:40:16 +1300 Subject: [PATCH 01/15] Introduce ARMPackageReference --- .../astmodel/arm_package_reference.go | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 v2/tools/generator/internal/astmodel/arm_package_reference.go diff --git a/v2/tools/generator/internal/astmodel/arm_package_reference.go b/v2/tools/generator/internal/astmodel/arm_package_reference.go new file mode 100644 index 0000000000..680ee75420 --- /dev/null +++ b/v2/tools/generator/internal/astmodel/arm_package_reference.go @@ -0,0 +1,20 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT license. + */ + +package astmodel + +// IsARMPackageReference returns true if the reference is to an ARM package OR to a subpackage of +// an ARM package, false otherwise. +func IsARMPackageReference(reference PackageReference) bool { + if sub, ok := reference.(SubPackageReference); ok { + if sub.name == ARMPackageName { + return true + } + + return IsARMPackageReference(sub.parent) + } + + return false +} From 5738b506d868cc1f60ec2f70fc7747f1825fa076 Mon Sep 17 00:00:00 2001 From: Bevan Arps Date: Wed, 27 Mar 2024 16:40:48 +1300 Subject: [PATCH 02/15] Modify creation of ARM TypeNames to use a subpackage, subject to deny list --- .../generator/internal/astmodel/type_name.go | 51 ++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/v2/tools/generator/internal/astmodel/type_name.go b/v2/tools/generator/internal/astmodel/type_name.go index 7f7eed4129..c01c0eb593 100644 --- a/v2/tools/generator/internal/astmodel/type_name.go +++ b/v2/tools/generator/internal/astmodel/type_name.go @@ -5,6 +5,8 @@ package astmodel +import "github.com/Azure/azure-service-operator/v2/internal/set" + type TypeName interface { Type Name() string @@ -18,9 +20,56 @@ const ( StatusSuffix = "_STATUS" // ARMSuffix is the suffix used for all ARM types ARMSuffix = "_ARM" + // ARMPackageName is the name used for ARM subpackages + ARMPackageName = "arm" ) +var armPackageDenyList = set.Make( + "apimanagement", + "appconfiguration", + "authorization", + "batch", + "cache", + "cdn", + "compute", + "containerinstance", + "containerregistry", + "containerservice", + "datafactory", + "dataprotection", + "dbformariadb", + "dbformysql", + "dbforpostgresql", + "devices", + "documentdb", + "eventgrid", + "eventhub", + "insights", + "keyvault", + "kubernetesconfiguration", + "machinelearningservices", + "managedidentity", + "network", + "network.frontdoor", + "operationalinsights", + //"person", + "resources", + "search", + "servicebus", + "signalrservice", + "sql", + "storage", + "subscription", + "synapse", + "web") + // CreateARMTypeName creates an ARM object type name func CreateARMTypeName(name InternalTypeName) InternalTypeName { - return MakeInternalTypeName(name.InternalPackageReference(), name.Name()+ARMSuffix) + pkg := name.InternalPackageReference() + if armPackageDenyList.Contains(pkg.Group()) { + return MakeInternalTypeName(pkg, name.Name()+ARMSuffix) + } + + armPackage := MakeSubPackageReference(ARMPackageName, name.InternalPackageReference()) + return MakeInternalTypeName(armPackage, name.Name()) } From 9a6cc41717e4ad7f528265aa5d7cc6c9edec1499 Mon Sep 17 00:00:00 2001 From: Bevan Arps Date: Wed, 27 Mar 2024 16:41:02 +1300 Subject: [PATCH 03/15] Update IsARMType --- v2/tools/generator/internal/astmodel/internal_type_name.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/v2/tools/generator/internal/astmodel/internal_type_name.go b/v2/tools/generator/internal/astmodel/internal_type_name.go index 3aa47b1786..c2fdc71b5e 100644 --- a/v2/tools/generator/internal/astmodel/internal_type_name.go +++ b/v2/tools/generator/internal/astmodel/internal_type_name.go @@ -186,6 +186,10 @@ func (tn InternalTypeName) IsStatus() bool { // IsARMType returns true if the TypeName identifies an ARM specific type, false otherwise. func (tn InternalTypeName) IsARMType() bool { + if IsARMPackageReference(tn.InternalPackageReference()) { + return true + } + return strings.HasSuffix(tn.Name(), ARMSuffix) } From 273851ae89e1b11eb669a552c684112352c1ef62 Mon Sep 17 00:00:00 2001 From: Bevan Arps Date: Wed, 27 Mar 2024 16:41:31 +1300 Subject: [PATCH 04/15] Set name of ARM subpackage imports --- v2/tools/generator/internal/astmodel/file_definition.go | 1 + 1 file changed, 1 insertion(+) diff --git a/v2/tools/generator/internal/astmodel/file_definition.go b/v2/tools/generator/internal/astmodel/file_definition.go index 41ceac41e3..aede3f7c52 100644 --- a/v2/tools/generator/internal/astmodel/file_definition.go +++ b/v2/tools/generator/internal/astmodel/file_definition.go @@ -154,6 +154,7 @@ func (file *FileDefinition) generateImports() *PackageImportSet { // TODO: Make this configurable requiredImports.ApplyName(MetaV1Reference, "metav1") requiredImports.ApplyName(APIMachineryErrorsReference, "kerrors") + requiredImports.ApplyName(MakeSubPackageReference(ARMPackageName, file.packageReference), "arm") return requiredImports } From 5c95f6b77fcc1ea735edb2596a0686c7afc3ecc4 Mon Sep 17 00:00:00 2001 From: Matthew Christopher Date: Wed, 22 May 2024 13:35:13 -0700 Subject: [PATCH 05/15] Fix ARM conversion code to use package scoped conversion if needed --- .../convert_from_arm_function_builder.go | 2 +- .../convert_to_arm_function_builder.go | 2 +- .../internal/armconversion/shared.go | 20 +++++++++++++++---- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/v2/tools/generator/internal/armconversion/convert_from_arm_function_builder.go b/v2/tools/generator/internal/armconversion/convert_from_arm_function_builder.go index c6d6dc8158..b1ee95f236 100644 --- a/v2/tools/generator/internal/armconversion/convert_from_arm_function_builder.go +++ b/v2/tools/generator/internal/armconversion/convert_from_arm_function_builder.go @@ -153,7 +153,7 @@ func (builder *convertFromARMBuilder) assertInputTypeIsARM(needsResult bool) []d typeAssert := astbuilder.TypeAssert( dst.NewIdent(dest), dst.NewIdent(builder.inputIdent), - dst.NewIdent(builder.sourceTypeIdent())) + builder.sourceTypeIdent()) // Check the result of the type assert // if !ok { diff --git a/v2/tools/generator/internal/armconversion/convert_to_arm_function_builder.go b/v2/tools/generator/internal/armconversion/convert_to_arm_function_builder.go index 717eb91e9a..e6a4d1d069 100644 --- a/v2/tools/generator/internal/armconversion/convert_to_arm_function_builder.go +++ b/v2/tools/generator/internal/armconversion/convert_to_arm_function_builder.go @@ -119,7 +119,7 @@ func (builder *convertToARMBuilder) functionBodyStatements() ([]dst.Stmt, error) decl := astbuilder.ShortDeclaration( builder.resultIdent, - astbuilder.AddrOf(astbuilder.NewCompositeLiteralBuilder(dst.NewIdent(builder.destinationTypeIdent())).Build())) + astbuilder.AddrOf(astbuilder.NewCompositeLiteralBuilder(builder.destinationTypeIdent()).Build())) // Each ARM object property needs to be filled out conversions, err := generateTypeConversionAssignments( diff --git a/v2/tools/generator/internal/armconversion/shared.go b/v2/tools/generator/internal/armconversion/shared.go index 85accbffea..899280fa8e 100644 --- a/v2/tools/generator/internal/armconversion/shared.go +++ b/v2/tools/generator/internal/armconversion/shared.go @@ -44,12 +44,24 @@ const ( TypeKindStatus ) -func (builder conversionBuilder) sourceTypeIdent() string { - return builder.sourceTypeName.Name() +func (builder conversionBuilder) sourceTypeIdent() dst.Expr { + // If the source type is in this package, return it without qualification + sourceTypePkg := builder.sourceTypeName.InternalPackageReference() + if sourceTypePkg.Equals(builder.codeGenerationContext.CurrentPackage()) { + return dst.NewIdent(builder.sourceTypeName.Name()) + } + sourceTypeImport := builder.codeGenerationContext.MustGetImportedPackageName(sourceTypePkg) + return astbuilder.QualifiedTypeName(sourceTypeImport, builder.sourceTypeName.Name()) } -func (builder conversionBuilder) destinationTypeIdent() string { - return builder.destinationTypeName.Name() +func (builder conversionBuilder) destinationTypeIdent() dst.Expr { + // If the destination type is in this package, return it without qualification + destinationTypePkg := builder.destinationTypeName.InternalPackageReference() + if destinationTypePkg.Equals(builder.codeGenerationContext.CurrentPackage()) { + return dst.NewIdent(builder.destinationTypeName.Name()) + } + destinationTypeImport := builder.codeGenerationContext.MustGetImportedPackageName(destinationTypePkg) + return astbuilder.QualifiedTypeName(destinationTypeImport, builder.destinationTypeName.Name()) } func (builder conversionBuilder) propertyConversionHandler( From c171be2b85388169438f30f96e85e1085be58edf Mon Sep 17 00:00:00 2001 From: Bevan Arps Date: Wed, 29 May 2024 14:16:08 +1200 Subject: [PATCH 06/15] Include the ARM type in the references from the ARM conversion function --- .../internal/armconversion/arm_conversion_function.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/v2/tools/generator/internal/armconversion/arm_conversion_function.go b/v2/tools/generator/internal/armconversion/arm_conversion_function.go index 8660b9cfbd..5bac8bb5c0 100644 --- a/v2/tools/generator/internal/armconversion/arm_conversion_function.go +++ b/v2/tools/generator/internal/armconversion/arm_conversion_function.go @@ -52,6 +52,7 @@ func (c *ARMConversionFunction) RequiredPackageReferences() *astmodel.PackageRef // We need these because we're going to be constructing/casting to the types // of the properties in the ARM object, so we need to import those. result := astmodel.NewPackageReferenceSet( + c.armTypeName.PackageReference(), astmodel.GenRuntimeReference, astmodel.GitHubErrorsReference, astmodel.MakeExternalPackageReference("fmt")) @@ -63,7 +64,9 @@ func (c *ARMConversionFunction) RequiredPackageReferences() *astmodel.PackageRef // SHOULD include any types which this function references but its receiver doesn't. // SHOULD NOT include the receiver of this function. func (c *ARMConversionFunction) References() astmodel.TypeNameSet { - return c.armType.References() + result := astmodel.NewTypeNameSet(c.armTypeName) + result.AddAll(c.armType.References()) + return result } // AsFunc returns the function as a Go AST From b5f79e0c0111cacd24f971c0ba61d788a53846fb Mon Sep 17 00:00:00 2001 From: Bevan Arps Date: Wed, 29 May 2024 14:18:53 +1200 Subject: [PATCH 07/15] Use subpackage name as "VersionOnly" import alias --- .../person-v20200101.golden | 9 +++++---- .../person-v20200101.golden | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/v2/tools/generator/internal/codegen/pipeline/testdata/Test_RenameProperties_PopulatesExpectedARMProperty/person-v20200101.golden b/v2/tools/generator/internal/codegen/pipeline/testdata/Test_RenameProperties_PopulatesExpectedARMProperty/person-v20200101.golden index e0451f9beb..24268ee9a8 100644 --- a/v2/tools/generator/internal/codegen/pipeline/testdata/Test_RenameProperties_PopulatesExpectedARMProperty/person-v20200101.golden +++ b/v2/tools/generator/internal/codegen/pipeline/testdata/Test_RenameProperties_PopulatesExpectedARMProperty/person-v20200101.golden @@ -5,6 +5,7 @@ import ( "fmt" + arm "github.com/Azure/azure-service-operator/testing/person/v20200101/arm" "github.com/Azure/azure-service-operator/v2/pkg/genruntime" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -108,7 +109,7 @@ if person == nil { return nil, nil } - result := &Person_Spec_ARM{} + result := &arm.Person_Spec{} // Set property "APIVersion": if person.APIVersion != nil { @@ -133,7 +134,7 @@ // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (person *Person_Spec) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &Person_Spec_ARM{} + return &arm.Person_Spec{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object @@ -189,12 +190,12 @@ // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (person *Person_STATUS) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &Person_STATUS_ARM{} + return &arm.Person_STATUS{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (person *Person_STATUS) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(Person_STATUS_ARM) + typedInput, ok := armInput.(arm.Person_STATUS) if !ok { return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected Person_STATUS_ARM, got %T", armInput) } diff --git a/v2/tools/generator/internal/codegen/pipeline/testdata/Test_RenameProperties_WhenFlattening_PopulatesExpectedARMProperty/person-v20200101.golden b/v2/tools/generator/internal/codegen/pipeline/testdata/Test_RenameProperties_WhenFlattening_PopulatesExpectedARMProperty/person-v20200101.golden index bc50f2a29e..f45ef061dc 100644 --- a/v2/tools/generator/internal/codegen/pipeline/testdata/Test_RenameProperties_WhenFlattening_PopulatesExpectedARMProperty/person-v20200101.golden +++ b/v2/tools/generator/internal/codegen/pipeline/testdata/Test_RenameProperties_WhenFlattening_PopulatesExpectedARMProperty/person-v20200101.golden @@ -5,6 +5,7 @@ import ( "fmt" + arm "github.com/Azure/azure-service-operator/testing/person/v20200101/arm" "github.com/Azure/azure-service-operator/v2/pkg/genruntime" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -24,7 +25,7 @@ if address == nil { return nil, nil } - result := &Address_ARM{} + result := &arm.Address{} // Set property "City": result.City = address.City @@ -36,12 +37,12 @@ // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (address *Address) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &Address_ARM{} + return &arm.Address{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (address *Address) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(Address_ARM) + typedInput, ok := armInput.(arm.Address) if !ok { return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected Address_ARM, got %T", armInput) } @@ -170,7 +171,7 @@ if person == nil { return nil, nil } - result := &Person_Spec_ARM{} + result := &arm.Person_Spec{} // Set property "APIVersion": if person.APIVersion != nil { From a06937be2c448be32cf220f6cce00bdb7990fd55 Mon Sep 17 00:00:00 2001 From: Bevan Arps Date: Wed, 29 May 2024 14:37:11 +1200 Subject: [PATCH 08/15] Fix dodgy error generation --- .../internal/armconversion/convert_from_arm_function_builder.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/v2/tools/generator/internal/armconversion/convert_from_arm_function_builder.go b/v2/tools/generator/internal/armconversion/convert_from_arm_function_builder.go index b1ee95f236..262ac25be3 100644 --- a/v2/tools/generator/internal/armconversion/convert_from_arm_function_builder.go +++ b/v2/tools/generator/internal/armconversion/convert_from_arm_function_builder.go @@ -164,7 +164,7 @@ func (builder *convertFromARMBuilder) assertInputTypeIsARM(needsResult bool) []d fmtPackage, fmt.Sprintf("unexpected type supplied for %s() function. Expected %s, got %%T", builder.methodName, - builder.sourceTypeIdent()), + builder.sourceTypeString()), dst.NewIdent(builder.inputIdent))) return astbuilder.Statements(typeAssert, returnIfNotOk) From 2f217dbd90a1402694a393519f6e6768f1db7b65 Mon Sep 17 00:00:00 2001 From: Bevan Arps Date: Wed, 29 May 2024 14:38:16 +1200 Subject: [PATCH 09/15] Modify asserts to generate a file per package --- v2/tools/generator/internal/test/asserts.go | 34 +++--- .../internal/test/file_definition.go | 75 +++++++++---- .../generator/internal/test/type_asserter.go | 104 ++++++++++++++---- 3 files changed, 156 insertions(+), 57 deletions(-) diff --git a/v2/tools/generator/internal/test/asserts.go b/v2/tools/generator/internal/test/asserts.go index e6d1d6cbad..c5cf72081f 100644 --- a/v2/tools/generator/internal/test/asserts.go +++ b/v2/tools/generator/internal/test/asserts.go @@ -7,7 +7,6 @@ package test import ( "bytes" - "strings" "testing" "github.com/Azure/azure-service-operator/v2/tools/generator/internal/reporting" @@ -27,20 +26,13 @@ func AssertPackagesGenerateExpectedCode( options ...AssertionOption, ) { t.Helper() - // Group type definitions by package - groups := make(map[astmodel.PackageReference][]astmodel.TypeDefinition, len(definitions)) - for _, def := range definitions { - ref := def.Name().PackageReference() - groups[ref] = append(groups[ref], def) - } - // Write a file for each package - for _, defs := range groups { - ref := defs[0].Name().InternalPackageReference() - fileName := strings.ReplaceAll(ref.FolderPath(), "/", "-") + defs := definitions.AsSlice() + packages := createSetOfPackages(defs) - AssertTypeDefinitionsGenerateExpectedCode(t, fileName, defs, options...) - } + asserter := newTypeAsserter(t) + asserter.configure(options) + asserter.assert("", defs, packages) } // AssertTypeDefinitionsGenerateExpectedCode serialises the given FileDefinition as a golden file test, checking that the expected @@ -56,9 +48,12 @@ func AssertTypeDefinitionsGenerateExpectedCode( options ...AssertionOption, ) { t.Helper() + + packages := createSetOfPackages(defs) + asserter := newTypeAsserter(t) asserter.configure(options) - asserter.assert(name, defs...) + asserter.assert(name, defs, packages) } // AssertSingleTypeDefinitionGeneratesExpectedCode serialises the given TypeDefinition as a golden file test, checking @@ -74,9 +69,16 @@ func AssertSingleTypeDefinitionGeneratesExpectedCode( options ...AssertionOption, ) { t.Helper() + + defs := []astmodel.TypeDefinition{ + def, + } + + packages := createSetOfPackages(defs) + asserter := newTypeAsserter(t) asserter.configure(options) - asserter.assert(fileName, def) + asserter.assert(fileName, defs, packages) } // AssertDefinitionHasExpectedShape fails the test if the given definition does not have the expected shape. @@ -132,7 +134,7 @@ func AssertPropertyExists( return property } -// AssertPropertyExists fails the test if the given object does not have a property with the given name and type +// 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. diff --git a/v2/tools/generator/internal/test/file_definition.go b/v2/tools/generator/internal/test/file_definition.go index e36f7a1122..d932d9a781 100644 --- a/v2/tools/generator/internal/test/file_definition.go +++ b/v2/tools/generator/internal/test/file_definition.go @@ -9,38 +9,75 @@ import ( "github.com/Azure/azure-service-operator/v2/tools/generator/internal/astmodel" ) -func CreateFileDefinition(definitions ...astmodel.TypeDefinition) *astmodel.FileDefinition { - ref := definitions[0].Name().InternalPackageReference() - pkgDefinition := astmodel.NewPackageDefinition(ref) - for _, def := range definitions { - pkgDefinition.AddDefinition(def) - } +type goSourceFileFactory func(pkg astmodel.InternalPackageReference, + definitions []astmodel.TypeDefinition, + packages map[astmodel.InternalPackageReference]*astmodel.PackageDefinition, +) astmodel.GoSourceFile + +var _ goSourceFileFactory = createFileDefinition - packages := map[astmodel.InternalPackageReference]*astmodel.PackageDefinition{ - ref: pkgDefinition, +// createFileDefinition creates a code file containing the passed definitions. +// pkg is the package we're generating +// definitions is the set of type definitions to include in the file. +// packages is a map of all other packages being generated (to allow for cross-package references). +func createFileDefinition( + pkg astmodel.InternalPackageReference, + definitions []astmodel.TypeDefinition, + packages map[astmodel.InternalPackageReference]*astmodel.PackageDefinition, +) astmodel.GoSourceFile { + defs := make([]astmodel.TypeDefinition, 0, len(definitions)) + for _, def := range definitions { + if def.Name().InternalPackageReference() == pkg { + defs = append(defs, def) + } } // put all definitions in one file, regardless. // the package reference isn't really used here. - fileDef := astmodel.NewFileDefinition(ref, definitions, packages) + fileDef := astmodel.NewFileDefinition(pkg, defs, packages) return fileDef } -func CreateTestFileDefinition(definitions ...astmodel.TypeDefinition) *astmodel.TestFileDefinition { - // Use the package reference of the first definition for the whole file - ref := definitions[0].Name().InternalPackageReference() +var _ goSourceFileFactory = createTestFileDefinition - pkgDefinition := astmodel.NewPackageDefinition(ref) +// createTestFileDefinition creates a test file containing tests for the passed definitions. +// pkg is the package we're generating +// definitions is the set of type definitions from which we select definitions to include in the file. +// packages is a map of all other packages being generated (to allow for cross-package references). +func createTestFileDefinition( + pkg astmodel.InternalPackageReference, + definitions []astmodel.TypeDefinition, + packages map[astmodel.InternalPackageReference]*astmodel.PackageDefinition, +) astmodel.GoSourceFile { + defs := make([]astmodel.TypeDefinition, 0, len(definitions)) for _, def := range definitions { - pkgDefinition.AddDefinition(def) - } - - packages := map[astmodel.InternalPackageReference]*astmodel.PackageDefinition{ - ref: pkgDefinition, + if def.Name().InternalPackageReference() == pkg { + defs = append(defs, def) + } } // put all definitions in one file, regardless. // the package reference isn't really used here. - fileDef := astmodel.NewTestFileDefinition(ref, definitions, packages) + fileDef := astmodel.NewTestFileDefinition(pkg, defs, packages) return fileDef } + +func createSetOfPackages( + definitions []astmodel.TypeDefinition, +) map[astmodel.InternalPackageReference]*astmodel.PackageDefinition { + // Create a set of package definitions, one for each package required by the supplied definitions + packages := make(map[astmodel.InternalPackageReference]*astmodel.PackageDefinition, 2) + for _, def := range definitions { + pkg := def.Name().InternalPackageReference() + pkgDef, ok := packages[pkg] + if !ok { + // Need to create a new package definition + pkgDef = astmodel.NewPackageDefinition(pkg) + packages[pkg] = pkgDef + } + + pkgDef.AddDefinition(def) + } + + return packages +} diff --git a/v2/tools/generator/internal/test/type_asserter.go b/v2/tools/generator/internal/test/type_asserter.go index 1626f7785b..5b80883363 100644 --- a/v2/tools/generator/internal/test/type_asserter.go +++ b/v2/tools/generator/internal/test/type_asserter.go @@ -18,10 +18,10 @@ import ( ) type typeAsserter struct { - t *testing.T - writeCode bool - writeTests bool - reference astmodel.TypeDefinitionSet + t *testing.T // t is the test we're running + writeCode bool // writeCode controls whether we write the generated code to a golden file + writeTests bool // writeTests controls whether we write the generated tests to a golden file + reference astmodel.TypeDefinitionSet // reference is a set of definitions to compare against } func newTypeAsserter(t *testing.T) *typeAsserter { @@ -39,28 +39,44 @@ func (a *typeAsserter) configure(options []AssertionOption) { } } -func (a *typeAsserter) assert(name string, defs ...astmodel.TypeDefinition) { +func (a *typeAsserter) assert( + namePrefix string, + defs []astmodel.TypeDefinition, + packages map[astmodel.InternalPackageReference]*astmodel.PackageDefinition, +) { g := goldie.New(a.t) err := g.WithTestNameForDir(true) if err != nil { a.t.Fatalf("Unable to configure goldie output folder %s", err) } - refs := a.findReferenceTypes(defs) + for ref, pkg := range packages { + referenceTypes := a.findReferenceTypes(pkg.Definitions()) - if a.writeCode { - a.assertFile(g, name, defs, refs, a.renderDefsAsCode) - } + // Use namePrefix as the filename if it's set, and if we're only generating for one package + // otherwise include the folder path to disambiguate + fileName := namePrefix + if fileName == "" || len(packages) > 1 { + fileName += strings.ReplaceAll(ref.FolderPath(), "/", "-") + } + + if a.writeCode { + a.assertFile(g, fileName, ref, defs, referenceTypes, packages, createFileDefinition) + } - if a.writeTests { - a.assertFile(g, name+"_test", defs, refs, a.renderDefsAsTests) + if a.writeTests { + a.assertFile(g, fileName+"_test", ref, defs, referenceTypes, packages, createTestFileDefinition) + } } } -func (a *typeAsserter) findReferenceTypes(defs []astmodel.TypeDefinition) []astmodel.TypeDefinition { - var result []astmodel.TypeDefinition - for _, def := range defs { - if r, ok := a.reference[def.Name()]; ok { +// findReferenceTypes finds the reference versions of each of the definitions passed in. +func (a *typeAsserter) findReferenceTypes( + defs astmodel.TypeDefinitionSet, +) []astmodel.TypeDefinition { + result := make([]astmodel.TypeDefinition, 0, len(defs)) + for name := range defs { + if r, ok := a.reference[name]; ok { result = append(result, r) } } @@ -71,18 +87,22 @@ func (a *typeAsserter) findReferenceTypes(defs []astmodel.TypeDefinition) []astm func (a *typeAsserter) assertFile( g *goldie.Goldie, name string, + pkg astmodel.InternalPackageReference, defs []astmodel.TypeDefinition, refs []astmodel.TypeDefinition, - renderer func(defs []astmodel.TypeDefinition) (string, error), + packages map[astmodel.InternalPackageReference]*astmodel.PackageDefinition, + renderer goSourceFileFactory, ) { - content, err := renderer(defs) + a.t.Helper() + + content, err := a.renderDefs(pkg, defs, packages, renderer) if err != nil { a.t.Fatalf("rendering content: %s", err) return } if len(refs) > 0 { - base, err := renderer(refs) + base, err := a.renderDefs(pkg, refs, packages, renderer) if err != nil { a.t.Fatalf("rendering content: %s", err) return @@ -106,9 +126,18 @@ func (a *typeAsserter) addReferences(defs ...astmodel.TypeDefinition) { a.reference.AddAll(defs...) } -func (a *typeAsserter) renderDefsAsCode(defs []astmodel.TypeDefinition) (string, error) { +// renderDefsAsCode renders the passed definitions as Go code. +// It returns the generated code as a string. +// pkg is the package we're generating. +// defs is the set of type definitions to render. +// packages is a map of all other packages being generated (to allow for cross-package references). +func (a *typeAsserter) renderDefsAsCode( + pkg astmodel.InternalPackageReference, + defs []astmodel.TypeDefinition, + packages map[astmodel.InternalPackageReference]*astmodel.PackageDefinition, +) (string, error) { buf := &bytes.Buffer{} - file := CreateFileDefinition(defs...) + file := createFileDefinition(pkg, defs, packages) fileWriter := astmodel.NewGoSourceFileWriter(file) err := fileWriter.SaveToWriter(buf) if err != nil { @@ -118,9 +147,18 @@ func (a *typeAsserter) renderDefsAsCode(defs []astmodel.TypeDefinition) (string, return buf.String(), nil } -func (a *typeAsserter) renderDefsAsTests(defs []astmodel.TypeDefinition) (string, error) { +// renderDefsAsTests renders the passed definitions as Go tests. +// It returns the generated tests as a string. +// pkg is the package we're generating. +// defs is the set of type definitions to render. +// packages is a map of all other packages being generated (to allow for cross-package references). +func (a *typeAsserter) renderDefsAsTests( + pkg astmodel.InternalPackageReference, + defs []astmodel.TypeDefinition, + packages map[astmodel.InternalPackageReference]*astmodel.PackageDefinition, +) (string, error) { buf := &bytes.Buffer{} - file := CreateTestFileDefinition(defs...) + file := createTestFileDefinition(pkg, defs, packages) fileWriter := astmodel.NewGoSourceFileWriter(file) err := fileWriter.SaveToWriter(buf) if err != nil { @@ -129,3 +167,25 @@ func (a *typeAsserter) renderDefsAsTests(defs []astmodel.TypeDefinition) (string return buf.String(), nil } + +// renderDefsAsCode renders the passed definitions as Go code. +// It returns the generated code as a string. +// pkg is the package we're generating. +// defs is the set of type definitions to render. +// packages is a map of all other packages being generated (to allow for cross-package references). +func (a *typeAsserter) renderDefs( + pkg astmodel.InternalPackageReference, + defs []astmodel.TypeDefinition, + packages map[astmodel.InternalPackageReference]*astmodel.PackageDefinition, + renderer goSourceFileFactory, +) (string, error) { + buf := &bytes.Buffer{} + file := renderer(pkg, defs, packages) + fileWriter := astmodel.NewGoSourceFileWriter(file) + err := fileWriter.SaveToWriter(buf) + if err != nil { + return "", errors.Wrap(err, "could not generate code file") + } + + return buf.String(), nil +} From 8147ade8a3edac0036ecb78fa3767a44b3a36b2c Mon Sep 17 00:00:00 2001 From: Bevan Arps Date: Wed, 27 Mar 2024 16:42:12 +1300 Subject: [PATCH 10/15] Code gardening --- v2/pkg/genruntime/secrets/collector.go | 12 ++++---- .../armconversion/arm_conversion_function.go | 2 +- .../internal/armconversion/shared.go | 28 +++++++++++++++++++ .../internal/astmodel/file_definition.go | 7 +++-- .../internal/astmodel/test_file_definition.go | 3 ++ .../pipeline/add_arm_conversion_interface.go | 5 +++- .../functions/new_empty_arm_value_function.go | 18 ++++++++---- 7 files changed, 61 insertions(+), 14 deletions(-) diff --git a/v2/pkg/genruntime/secrets/collector.go b/v2/pkg/genruntime/secrets/collector.go index 3b8638fd19..ec7c14ef9f 100644 --- a/v2/pkg/genruntime/secrets/collector.go +++ b/v2/pkg/genruntime/secrets/collector.go @@ -6,7 +6,8 @@ package secrets import ( - "sort" + "cmp" + "slices" "github.com/pkg/errors" "golang.org/x/exp/maps" @@ -115,11 +116,12 @@ func (c *Collector) Values() ([]*v1.Secret, error) { result := maps.Values(c.secrets) // Force a deterministic ordering - sort.Slice(result, func(i, j int) bool { - left := result[i] - right := result[j] + slices.SortFunc(result, func(left, right *v1.Secret) int { + if c := cmp.Compare(left.Namespace, right.Namespace); c != 0 { + return c + } - return left.Namespace < right.Namespace || (left.Namespace == right.Namespace && left.Name < right.Name) + return cmp.Compare(left.Name, right.Name) }) return result, nil diff --git a/v2/tools/generator/internal/armconversion/arm_conversion_function.go b/v2/tools/generator/internal/armconversion/arm_conversion_function.go index 5bac8bb5c0..fde6d046cd 100644 --- a/v2/tools/generator/internal/armconversion/arm_conversion_function.go +++ b/v2/tools/generator/internal/armconversion/arm_conversion_function.go @@ -55,7 +55,7 @@ func (c *ARMConversionFunction) RequiredPackageReferences() *astmodel.PackageRef c.armTypeName.PackageReference(), astmodel.GenRuntimeReference, astmodel.GitHubErrorsReference, - astmodel.MakeExternalPackageReference("fmt")) + astmodel.FmtReference) result.Merge(c.armType.RequiredPackageReferences()) return result } diff --git a/v2/tools/generator/internal/armconversion/shared.go b/v2/tools/generator/internal/armconversion/shared.go index 899280fa8e..8f4344d27e 100644 --- a/v2/tools/generator/internal/armconversion/shared.go +++ b/v2/tools/generator/internal/armconversion/shared.go @@ -44,26 +44,54 @@ const ( TypeKindStatus ) +// sourceTypeIdent returns a dst.Expr that refers to the source type. func (builder conversionBuilder) sourceTypeIdent() dst.Expr { // If the source type is in this package, return it without qualification sourceTypePkg := builder.sourceTypeName.InternalPackageReference() if sourceTypePkg.Equals(builder.codeGenerationContext.CurrentPackage()) { return dst.NewIdent(builder.sourceTypeName.Name()) } + sourceTypeImport := builder.codeGenerationContext.MustGetImportedPackageName(sourceTypePkg) return astbuilder.QualifiedTypeName(sourceTypeImport, builder.sourceTypeName.Name()) } +// destinationTypeIdent returns a dst.Expr that refers to the destination type. func (builder conversionBuilder) destinationTypeIdent() dst.Expr { // If the destination type is in this package, return it without qualification destinationTypePkg := builder.destinationTypeName.InternalPackageReference() if destinationTypePkg.Equals(builder.codeGenerationContext.CurrentPackage()) { return dst.NewIdent(builder.destinationTypeName.Name()) } + destinationTypeImport := builder.codeGenerationContext.MustGetImportedPackageName(destinationTypePkg) return astbuilder.QualifiedTypeName(destinationTypeImport, builder.destinationTypeName.Name()) } +// sourceTypeString returns a string that refers to the source type. +func (builder conversionBuilder) sourceTypeString() string { + // If the source type is in this package, return it without qualification + sourceTypePkg := builder.sourceTypeName.InternalPackageReference() + if sourceTypePkg.Equals(builder.codeGenerationContext.CurrentPackage()) { + return builder.sourceTypeName.Name() + } + + sourceTypeImport := builder.codeGenerationContext.MustGetImportedPackageName(sourceTypePkg) + return fmt.Sprintf("%s.%s", sourceTypeImport, builder.sourceTypeName.Name()) +} + +// destinationTypeString returns a string that refers to the destination type. +func (builder conversionBuilder) destinationTypeString() string { + // If the destination type is in this package, return it without qualification + destinationTypePkg := builder.destinationTypeName.InternalPackageReference() + if destinationTypePkg.Equals(builder.codeGenerationContext.CurrentPackage()) { + return builder.destinationTypeName.Name() + } + + destinationTypeImport := builder.codeGenerationContext.MustGetImportedPackageName(destinationTypePkg) + return fmt.Sprintf("%s.%s", destinationTypeImport, builder.destinationTypeName.Name()) +} + func (builder conversionBuilder) propertyConversionHandler( toProp *astmodel.PropertyDefinition, fromType *astmodel.ObjectType, diff --git a/v2/tools/generator/internal/astmodel/file_definition.go b/v2/tools/generator/internal/astmodel/file_definition.go index aede3f7c52..0a3873968f 100644 --- a/v2/tools/generator/internal/astmodel/file_definition.go +++ b/v2/tools/generator/internal/astmodel/file_definition.go @@ -25,13 +25,16 @@ type FileDefinition struct { // definitions to include in this file definitions []TypeDefinition - // other packages whose references may be needed for code generation + // other generated packages whose references may be needed for code generation generatedPackages map[InternalPackageReference]*PackageDefinition } var _ GoSourceFile = &FileDefinition{} -// NewFileDefinition creates a file definition containing specified definitions +// NewFileDefinition creates a file definition containing specified definitions. +// packageRef is the package to which this file belongs. +// definitions are the type definitions to include in this specific file. +// generatedPackages is a map of all other packages being generated (to allow for cross-package references). func NewFileDefinition( packageRef InternalPackageReference, definitions []TypeDefinition, diff --git a/v2/tools/generator/internal/astmodel/test_file_definition.go b/v2/tools/generator/internal/astmodel/test_file_definition.go index 949ca9ea25..5ca8097791 100644 --- a/v2/tools/generator/internal/astmodel/test_file_definition.go +++ b/v2/tools/generator/internal/astmodel/test_file_definition.go @@ -29,6 +29,9 @@ type TestFileDefinition struct { var _ GoSourceFile = &TestFileDefinition{} // NewTestFileDefinition creates a file definition containing test cases from the specified definitions +// packageRef is the package to which this file belongs. +// definitions are the type definitions to include in this specific file. +// generatedPackages is a map of all other packages being generated (to allow for cross-package references). func NewTestFileDefinition( packageRef InternalPackageReference, definitions []TypeDefinition, diff --git a/v2/tools/generator/internal/codegen/pipeline/add_arm_conversion_interface.go b/v2/tools/generator/internal/codegen/pipeline/add_arm_conversion_interface.go index 52299e3285..c167a135c2 100644 --- a/v2/tools/generator/internal/codegen/pipeline/add_arm_conversion_interface.go +++ b/v2/tools/generator/internal/codegen/pipeline/add_arm_conversion_interface.go @@ -40,7 +40,10 @@ func ApplyARMConversionInterface(idFactory astmodel.IdentifierFactory, config *c // GetARMTypeDefinition gets the ARM type definition for a given Kubernetes type name. // If no matching definition can be found an error is returned. -func GetARMTypeDefinition(defs astmodel.TypeDefinitionSet, name astmodel.InternalTypeName) (astmodel.TypeDefinition, error) { +func GetARMTypeDefinition( + defs astmodel.TypeDefinitionSet, + name astmodel.InternalTypeName, +) (astmodel.TypeDefinition, error) { armDefinition, ok := defs[astmodel.CreateARMTypeName(name)] if !ok { return astmodel.TypeDefinition{}, errors.Errorf("couldn't find ARM definition matching kube name %q", name) diff --git a/v2/tools/generator/internal/functions/new_empty_arm_value_function.go b/v2/tools/generator/internal/functions/new_empty_arm_value_function.go index 05be30a0e8..e3243ba603 100644 --- a/v2/tools/generator/internal/functions/new_empty_arm_value_function.go +++ b/v2/tools/generator/internal/functions/new_empty_arm_value_function.go @@ -16,7 +16,7 @@ import ( // NewNewEmptyARMValueFunc returns a function that creates an empty value suitable for using with PopulateFromARM. // It should be equivalent to ConvertToARM("") on a default struct value. func NewNewEmptyARMValueFunc( - armType astmodel.TypeName, + armType astmodel.InternalTypeName, idFactory astmodel.IdentifierFactory, ) astmodel.Function { result := NewObjectFunction( @@ -24,10 +24,12 @@ func NewNewEmptyARMValueFunc( idFactory, newEmptyARMValueBody(armType)) + result.AddPackageReference(armType.InternalPackageReference()) + return result } -func newEmptyARMValueBody(instanceType astmodel.TypeName) ObjectFunctionHandler { +func newEmptyARMValueBody(instanceType astmodel.InternalTypeName) ObjectFunctionHandler { return func( fn *ObjectFunction, genContext *astmodel.CodeGenerationContext, @@ -35,15 +37,21 @@ func newEmptyARMValueBody(instanceType astmodel.TypeName) ObjectFunctionHandler methodName string, ) (*dst.FuncDecl, error) { receiverName := fn.IdFactory().CreateReceiver(receiver.Name()) - receiverType, err := receiver.AsTypeExpr(genContext) + receiverTypeExpr, err := receiver.AsTypeExpr(genContext) if err != nil { return nil, errors.Wrapf(err, "creating type expression for %s", receiver) } + receiverTypeExpr = astbuilder.PointerTo(receiverTypeExpr) - receiverTypeExpr := astbuilder.PointerTo(receiverType) + // return &{} + instanceTypeExpr, err := instanceType.AsTypeExpr(genContext) + if err != nil { + return nil, errors.Wrapf(err, "creating type expression for %s", instanceType) + } - instance := astbuilder.NewCompositeLiteralBuilder(dst.NewIdent(instanceType.Name())) + instance := astbuilder.NewCompositeLiteralBuilder(instanceTypeExpr) returnInstance := astbuilder.Returns(astbuilder.AddrOf(instance.Build())) + details := &astbuilder.FuncDetails{ Name: "NewEmptyARMValue", ReceiverIdent: receiverName, From fa5289d8a2a8f7a2c17fe5dbc637be926ace11a5 Mon Sep 17 00:00:00 2001 From: Bevan Arps Date: Wed, 29 May 2024 14:38:59 +1200 Subject: [PATCH 11/15] Change subpackages to use the subpackage name as the simplest import --- v2/tools/generator/internal/astmodel/sub_package_reference.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/v2/tools/generator/internal/astmodel/sub_package_reference.go b/v2/tools/generator/internal/astmodel/sub_package_reference.go index dbb78229a4..dc061eda87 100644 --- a/v2/tools/generator/internal/astmodel/sub_package_reference.go +++ b/v2/tools/generator/internal/astmodel/sub_package_reference.go @@ -113,7 +113,7 @@ func (s SubPackageReference) ImportAlias(style PackageImportStyle) string { case Name: return s.name case VersionOnly: - return base + s.name[0:1] + return s.name case GroupOnly: return base case GroupAndVersion: From b3527f18c9eca0b6f53f9f98d1e02d4426b2fc5d Mon Sep 17 00:00:00 2001 From: Bevan Arps Date: Fri, 31 May 2024 09:08:18 +1200 Subject: [PATCH 12/15] Add PackageImportStyle "Name" --- v2/tools/generator/internal/astmodel/sub_package_reference.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/v2/tools/generator/internal/astmodel/sub_package_reference.go b/v2/tools/generator/internal/astmodel/sub_package_reference.go index dc061eda87..dbb78229a4 100644 --- a/v2/tools/generator/internal/astmodel/sub_package_reference.go +++ b/v2/tools/generator/internal/astmodel/sub_package_reference.go @@ -113,7 +113,7 @@ func (s SubPackageReference) ImportAlias(style PackageImportStyle) string { case Name: return s.name case VersionOnly: - return s.name + return base + s.name[0:1] case GroupOnly: return base case GroupAndVersion: From d2d42032d8d823377f3fee2db0ac573bdba30b3a Mon Sep 17 00:00:00 2001 From: Bevan Arps Date: Wed, 27 Mar 2024 16:44:24 +1300 Subject: [PATCH 13/15] Update golden files --- .../person-v20200101-arm.golden | 20 +- .../person-v20200101.golden | 67 ++----- .../person-v20200101-arm.golden | 20 +- .../person-v20200101.golden | 70 ++----- .../person-v20200101-arm.golden | 20 +- .../person-v20200101.golden | 56 +----- .../person-v20200101-arm.golden | 20 +- .../person-v20200101.golden | 55 +---- .../person-v20200101-arm.golden | 20 +- .../person-v20200101.golden | 56 +----- .../person-v1beta20200101.golden | 43 ---- .../person-v20200101.golden | 51 ----- .../person-v20200101_test.golden | 60 ++++++ .../person-v20211231-storage_test.golden | 40 ++-- .../person-v20200101-storage_test.golden | 56 +++--- .../person-v20211231_test.golden | 6 +- .../person-v20200101-arm.golden | 122 ++++++------ .../person-v20200101.golden | 68 +------ .../person-v20200101-arm.golden | 18 +- .../person-v20200101.golden | 102 ++-------- ...n_arm_type_only_azure_v1api20200101.golden | 50 +++-- ...e_and_ownership_azure_v1api20200101.golden | 188 +++++++++++------- ...ource_reference_azure_v1api20200101.golden | 66 +++--- ...urce_references_azure_v1api20200101.golden | 66 +++--- ...rray_properties_azure_v1api20200101.golden | 111 ++++++----- ...plex_properties_azure_v1api20200101.golden | 82 +++++--- ...rce_json_fields_azure_v1api20200101.golden | 50 +++-- ..._map_properties_azure_v1api20200101.golden | 119 ++++++----- ...ce_renders_spec_azure_v1api20200101.golden | 50 +++-- ..._type_simple_resource_v1api20200101.golden | 94 +++++---- ...ulti_valued_enum_name_v1api20200101.golden | 57 ++++-- ...ngle_valued_enum_name_v1api20200101.golden | 50 +++-- 32 files changed, 911 insertions(+), 1042 deletions(-) delete mode 100644 v2/tools/generator/internal/codegen/pipeline/testdata/TestGolden_CreateBackwardCompatibilityTypes/person-v1beta20200101.golden delete mode 100644 v2/tools/generator/internal/codegen/pipeline/testdata/TestGolden_CreateBackwardCompatibilityTypes/person-v20200101.golden diff --git a/v2/tools/generator/internal/codegen/pipeline/testdata/TestCreateARMTypeWithConfigMap_CreatesExpectedConversions/person-v20200101-arm.golden b/v2/tools/generator/internal/codegen/pipeline/testdata/TestCreateARMTypeWithConfigMap_CreatesExpectedConversions/person-v20200101-arm.golden index ef5dd95466..49bc90d699 100644 --- a/v2/tools/generator/internal/codegen/pipeline/testdata/TestCreateARMTypeWithConfigMap_CreatesExpectedConversions/person-v20200101-arm.golden +++ b/v2/tools/generator/internal/codegen/pipeline/testdata/TestCreateARMTypeWithConfigMap_CreatesExpectedConversions/person-v20200101-arm.golden @@ -5,35 +5,35 @@ package arm import "github.com/Azure/azure-service-operator/v2/pkg/genruntime" -type Person_Spec_BOOMBABOOMBA struct { +type Person_Spec struct { // Name: The name of the resource - Name string `json:"name,omitempty"` - Properties *PersonProperties_BOOMBABOOMBA `json:"properties,omitempty"` + Name string `json:"name,omitempty"` + Properties *PersonProperties `json:"properties,omitempty"` } -var _ genruntime.ARMResourceSpec = &Person_Spec_BOOMBABOOMBA{} +var _ genruntime.ARMResourceSpec = &Person_Spec{} // GetAPIVersion returns the ARM API version of the resource. This is always v2020 -func (boombaboomba Person_Spec_BOOMBABOOMBA) GetAPIVersion() string { +func (person Person_Spec) GetAPIVersion() string { return string(APIVersion_v2020) } // GetName returns the Name of the resource -func (boombaboomba *Person_Spec_BOOMBABOOMBA) GetName() string { - return boombaboomba.Name +func (person *Person_Spec) GetName() string { + return person.Name } // GetType returns the ARM Type of the resource. This is always "" -func (boombaboomba *Person_Spec_BOOMBABOOMBA) GetType() string { +func (person *Person_Spec) GetType() string { return "" } -type Person_STATUS_BOOMBABOOMBA struct { +type Person_STATUS struct { // Status: Current status Status string `json:"status,omitempty"` } -type PersonProperties_BOOMBABOOMBA struct { +type PersonProperties struct { // FamilyName: Shared name of the family FamilyName *string `json:"familyName,omitempty" optionalConfigMapPair:"FamilyName"` diff --git a/v2/tools/generator/internal/codegen/pipeline/testdata/TestCreateARMTypeWithConfigMap_CreatesExpectedConversions/person-v20200101.golden b/v2/tools/generator/internal/codegen/pipeline/testdata/TestCreateARMTypeWithConfigMap_CreatesExpectedConversions/person-v20200101.golden index cc73b878f6..05c7188a45 100644 --- a/v2/tools/generator/internal/codegen/pipeline/testdata/TestCreateARMTypeWithConfigMap_CreatesExpectedConversions/person-v20200101.golden +++ b/v2/tools/generator/internal/codegen/pipeline/testdata/TestCreateARMTypeWithConfigMap_CreatesExpectedConversions/person-v20200101.golden @@ -5,6 +5,7 @@ package v20200101 import ( "fmt" + arm "github.com/Azure/azure-service-operator/testing/person/v20200101/arm" "github.com/Azure/azure-service-operator/v2/pkg/genruntime" "github.com/pkg/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -26,34 +27,6 @@ type PersonList struct { Items []Person `json:"items"` } -type Person_Spec_ARM struct { - // Name: The name of the resource - Name string `json:"name,omitempty"` - Properties *PersonProperties_ARM `json:"properties,omitempty"` -} - -var _ genruntime.ARMResourceSpec = &Person_Spec_ARM{} - -// GetAPIVersion returns the ARM API version of the resource. This is always v2020 -func (person Person_Spec_ARM) GetAPIVersion() string { - return string(APIVersion_v2020) -} - -// GetName returns the Name of the resource -func (person *Person_Spec_ARM) GetName() string { - return person.Name -} - -// GetType returns the ARM Type of the resource. This is always "" -func (person *Person_Spec_ARM) GetType() string { - return "" -} - -type Person_STATUS_ARM struct { - // Status: Current status - Status string `json:"status,omitempty"` -} - // +kubebuilder:validation:Enum={v2020} type APIVersion string @@ -73,7 +46,7 @@ func (person *Person_Spec) ConvertToARM(resolved genruntime.ConvertToARMResolved if person == nil { return nil, nil } - result := &Person_Spec_ARM{} + result := &arm.Person_Spec{} // Set property "Name": result.Name = resolved.Name @@ -84,7 +57,7 @@ func (person *Person_Spec) ConvertToARM(resolved genruntime.ConvertToARMResolved if err != nil { return nil, err } - properties := *properties_ARM.(*PersonProperties_ARM) + properties := *properties_ARM.(*arm.PersonProperties) result.Properties = &properties } return result, nil @@ -92,14 +65,14 @@ func (person *Person_Spec) ConvertToARM(resolved genruntime.ConvertToARMResolved // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (person *Person_Spec) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &Person_Spec_ARM{} + return &arm.Person_Spec{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (person *Person_Spec) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(Person_Spec_ARM) + typedInput, ok := armInput.(arm.Person_Spec) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected Person_Spec_ARM, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.Person_Spec, got %T", armInput) } // Set property "AzureName": @@ -129,14 +102,14 @@ var _ genruntime.FromARMConverter = &Person_STATUS{} // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (person *Person_STATUS) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &Person_STATUS_ARM{} + return &arm.Person_STATUS{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (person *Person_STATUS) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(Person_STATUS_ARM) + typedInput, ok := armInput.(arm.Person_STATUS) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected Person_STATUS_ARM, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.Person_STATUS, got %T", armInput) } // Set property "Status": @@ -146,20 +119,6 @@ func (person *Person_STATUS) PopulateFromARM(owner genruntime.ArbitraryOwnerRefe return nil } -type PersonProperties_ARM struct { - // FamilyName: Shared name of the family - FamilyName *string `json:"familyName,omitempty" optionalConfigMapPair:"FamilyName"` - - // FullName: As would be used to address mail - FullName string `json:"fullName,omitempty"` - - // KnownAs: How the person is generally known - KnownAs string `json:"knownAs,omitempty"` - - // RestrictedName: The name of the resource, restricted to max 25 character length - RestrictedName *string `json:"restrictedName,omitempty" optionalConfigMapPair:"RestrictedName"` -} - type PersonProperties struct { // FamilyName: Shared name of the family FamilyName *string `json:"familyName,omitempty" optionalConfigMapPair:"FamilyName"` @@ -188,7 +147,7 @@ func (properties *PersonProperties) ConvertToARM(resolved genruntime.ConvertToAR if properties == nil { return nil, nil } - result := &PersonProperties_ARM{} + result := &arm.PersonProperties{} // Set property "FamilyName": if properties.FamilyName != nil { @@ -232,14 +191,14 @@ func (properties *PersonProperties) ConvertToARM(resolved genruntime.ConvertToAR // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (properties *PersonProperties) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &PersonProperties_ARM{} + return &arm.PersonProperties{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (properties *PersonProperties) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(PersonProperties_ARM) + typedInput, ok := armInput.(arm.PersonProperties) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected PersonProperties_ARM, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.PersonProperties, got %T", armInput) } // Set property "FamilyName": diff --git a/v2/tools/generator/internal/codegen/pipeline/testdata/TestCreateARMTypeWithSecret_CreatesExpectedConversions/person-v20200101-arm.golden b/v2/tools/generator/internal/codegen/pipeline/testdata/TestCreateARMTypeWithSecret_CreatesExpectedConversions/person-v20200101-arm.golden index a24ba0b5b0..64102f7cc9 100644 --- a/v2/tools/generator/internal/codegen/pipeline/testdata/TestCreateARMTypeWithSecret_CreatesExpectedConversions/person-v20200101-arm.golden +++ b/v2/tools/generator/internal/codegen/pipeline/testdata/TestCreateARMTypeWithSecret_CreatesExpectedConversions/person-v20200101-arm.golden @@ -5,35 +5,35 @@ package arm import "github.com/Azure/azure-service-operator/v2/pkg/genruntime" -type Person_Spec_BOOMBABOOMBA struct { +type Person_Spec struct { // Name: The name of the resource - Name string `json:"name,omitempty"` - Properties *PersonProperties_BOOMBABOOMBA `json:"properties,omitempty"` + Name string `json:"name,omitempty"` + Properties *PersonProperties `json:"properties,omitempty"` } -var _ genruntime.ARMResourceSpec = &Person_Spec_BOOMBABOOMBA{} +var _ genruntime.ARMResourceSpec = &Person_Spec{} // GetAPIVersion returns the ARM API version of the resource. This is always v2020 -func (boombaboomba Person_Spec_BOOMBABOOMBA) GetAPIVersion() string { +func (person Person_Spec) GetAPIVersion() string { return string(APIVersion_v2020) } // GetName returns the Name of the resource -func (boombaboomba *Person_Spec_BOOMBABOOMBA) GetName() string { - return boombaboomba.Name +func (person *Person_Spec) GetName() string { + return person.Name } // GetType returns the ARM Type of the resource. This is always "" -func (boombaboomba *Person_Spec_BOOMBABOOMBA) GetType() string { +func (person *Person_Spec) GetType() string { return "" } -type Person_STATUS_BOOMBABOOMBA struct { +type Person_STATUS struct { // Status: Current status Status string `json:"status,omitempty"` } -type PersonProperties_BOOMBABOOMBA struct { +type PersonProperties struct { // FamilyName: Shared name of the family FamilyName string `json:"familyName,omitempty"` diff --git a/v2/tools/generator/internal/codegen/pipeline/testdata/TestCreateARMTypeWithSecret_CreatesExpectedConversions/person-v20200101.golden b/v2/tools/generator/internal/codegen/pipeline/testdata/TestCreateARMTypeWithSecret_CreatesExpectedConversions/person-v20200101.golden index a4117450eb..c3b0a3fd58 100644 --- a/v2/tools/generator/internal/codegen/pipeline/testdata/TestCreateARMTypeWithSecret_CreatesExpectedConversions/person-v20200101.golden +++ b/v2/tools/generator/internal/codegen/pipeline/testdata/TestCreateARMTypeWithSecret_CreatesExpectedConversions/person-v20200101.golden @@ -5,6 +5,7 @@ package v20200101 import ( "fmt" + arm "github.com/Azure/azure-service-operator/testing/person/v20200101/arm" "github.com/Azure/azure-service-operator/v2/pkg/genruntime" "github.com/pkg/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -26,34 +27,6 @@ type PersonList struct { Items []Person `json:"items"` } -type Person_Spec_ARM struct { - // Name: The name of the resource - Name string `json:"name,omitempty"` - Properties *PersonProperties_ARM `json:"properties,omitempty"` -} - -var _ genruntime.ARMResourceSpec = &Person_Spec_ARM{} - -// GetAPIVersion returns the ARM API version of the resource. This is always v2020 -func (person Person_Spec_ARM) GetAPIVersion() string { - return string(APIVersion_v2020) -} - -// GetName returns the Name of the resource -func (person *Person_Spec_ARM) GetName() string { - return person.Name -} - -// GetType returns the ARM Type of the resource. This is always "" -func (person *Person_Spec_ARM) GetType() string { - return "" -} - -type Person_STATUS_ARM struct { - // Status: Current status - Status string `json:"status,omitempty"` -} - // +kubebuilder:validation:Enum={v2020} type APIVersion string @@ -73,7 +46,7 @@ func (person *Person_Spec) ConvertToARM(resolved genruntime.ConvertToARMResolved if person == nil { return nil, nil } - result := &Person_Spec_ARM{} + result := &arm.Person_Spec{} // Set property "Name": result.Name = resolved.Name @@ -84,7 +57,7 @@ func (person *Person_Spec) ConvertToARM(resolved genruntime.ConvertToARMResolved if err != nil { return nil, err } - properties := *properties_ARM.(*PersonProperties_ARM) + properties := *properties_ARM.(*arm.PersonProperties) result.Properties = &properties } return result, nil @@ -92,14 +65,14 @@ func (person *Person_Spec) ConvertToARM(resolved genruntime.ConvertToARMResolved // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (person *Person_Spec) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &Person_Spec_ARM{} + return &arm.Person_Spec{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (person *Person_Spec) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(Person_Spec_ARM) + typedInput, ok := armInput.(arm.Person_Spec) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected Person_Spec_ARM, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.Person_Spec, got %T", armInput) } // Set property "AzureName": @@ -129,14 +102,14 @@ var _ genruntime.FromARMConverter = &Person_STATUS{} // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (person *Person_STATUS) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &Person_STATUS_ARM{} + return &arm.Person_STATUS{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (person *Person_STATUS) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(Person_STATUS_ARM) + typedInput, ok := armInput.(arm.Person_STATUS) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected Person_STATUS_ARM, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.Person_STATUS, got %T", armInput) } // Set property "Status": @@ -146,23 +119,6 @@ func (person *Person_STATUS) PopulateFromARM(owner genruntime.ArbitraryOwnerRefe return nil } -type PersonProperties_ARM struct { - // FamilyName: Shared name of the family - FamilyName string `json:"familyName,omitempty"` - - // FullName: As would be used to address mail - FullName string `json:"fullName,omitempty"` - - // KnownAs: How the person is generally known - KnownAs string `json:"knownAs,omitempty"` - - // SecretData: Secret data - SecretData map[string]string `json:"secretData,omitempty"` - - // SecretSlice: Secret data - SecretSlice []string `json:"secretSlice,omitempty"` -} - type PersonProperties struct { // FamilyName: Shared name of the family FamilyName string `json:"familyName,omitempty"` @@ -187,7 +143,7 @@ func (properties *PersonProperties) ConvertToARM(resolved genruntime.ConvertToAR if properties == nil { return nil, nil } - result := &PersonProperties_ARM{} + result := &arm.PersonProperties{} // Set property "FamilyName": result.FamilyName = properties.FamilyName @@ -226,14 +182,14 @@ func (properties *PersonProperties) ConvertToARM(resolved genruntime.ConvertToAR // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (properties *PersonProperties) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &PersonProperties_ARM{} + return &arm.PersonProperties{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (properties *PersonProperties) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(PersonProperties_ARM) + typedInput, ok := armInput.(arm.PersonProperties) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected PersonProperties_ARM, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.PersonProperties, got %T", armInput) } // Set property "FamilyName": diff --git a/v2/tools/generator/internal/codegen/pipeline/testdata/TestCreateFlattenedARMTypeWithConfigMap_CreatesExpectedConversions/person-v20200101-arm.golden b/v2/tools/generator/internal/codegen/pipeline/testdata/TestCreateFlattenedARMTypeWithConfigMap_CreatesExpectedConversions/person-v20200101-arm.golden index e06f3476a9..be71033500 100644 --- a/v2/tools/generator/internal/codegen/pipeline/testdata/TestCreateFlattenedARMTypeWithConfigMap_CreatesExpectedConversions/person-v20200101-arm.golden +++ b/v2/tools/generator/internal/codegen/pipeline/testdata/TestCreateFlattenedARMTypeWithConfigMap_CreatesExpectedConversions/person-v20200101-arm.golden @@ -5,35 +5,35 @@ package arm import "github.com/Azure/azure-service-operator/v2/pkg/genruntime" -type Person_Spec_BOOMBABOOMBA struct { +type Person_Spec struct { // Name: The name of the resource - Name string `json:"name,omitempty"` - Properties *PersonProperties_BOOMBABOOMBA `json:"properties,omitempty"` + Name string `json:"name,omitempty"` + Properties *PersonProperties `json:"properties,omitempty"` } -var _ genruntime.ARMResourceSpec = &Person_Spec_BOOMBABOOMBA{} +var _ genruntime.ARMResourceSpec = &Person_Spec{} // GetAPIVersion returns the ARM API version of the resource. This is always v2020 -func (boombaboomba Person_Spec_BOOMBABOOMBA) GetAPIVersion() string { +func (person Person_Spec) GetAPIVersion() string { return string(APIVersion_v2020) } // GetName returns the Name of the resource -func (boombaboomba *Person_Spec_BOOMBABOOMBA) GetName() string { - return boombaboomba.Name +func (person *Person_Spec) GetName() string { + return person.Name } // GetType returns the ARM Type of the resource. This is always "" -func (boombaboomba *Person_Spec_BOOMBABOOMBA) GetType() string { +func (person *Person_Spec) GetType() string { return "" } -type Person_STATUS_BOOMBABOOMBA struct { +type Person_STATUS struct { // Status: Current status Status string `json:"status,omitempty"` } -type PersonProperties_BOOMBABOOMBA struct { +type PersonProperties struct { // FamilyName: Shared name of the family FamilyName *string `json:"familyName,omitempty" optionalConfigMapPair:"FamilyName"` diff --git a/v2/tools/generator/internal/codegen/pipeline/testdata/TestCreateFlattenedARMTypeWithConfigMap_CreatesExpectedConversions/person-v20200101.golden b/v2/tools/generator/internal/codegen/pipeline/testdata/TestCreateFlattenedARMTypeWithConfigMap_CreatesExpectedConversions/person-v20200101.golden index 5af21f7cbd..65ef991fdc 100644 --- a/v2/tools/generator/internal/codegen/pipeline/testdata/TestCreateFlattenedARMTypeWithConfigMap_CreatesExpectedConversions/person-v20200101.golden +++ b/v2/tools/generator/internal/codegen/pipeline/testdata/TestCreateFlattenedARMTypeWithConfigMap_CreatesExpectedConversions/person-v20200101.golden @@ -5,6 +5,7 @@ package v20200101 import ( "fmt" + arm "github.com/Azure/azure-service-operator/testing/person/v20200101/arm" "github.com/Azure/azure-service-operator/v2/pkg/genruntime" "github.com/pkg/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -26,34 +27,6 @@ type PersonList struct { Items []Person `json:"items"` } -type Person_Spec_ARM struct { - // Name: The name of the resource - Name string `json:"name,omitempty"` - Properties *PersonProperties_ARM `json:"properties,omitempty"` -} - -var _ genruntime.ARMResourceSpec = &Person_Spec_ARM{} - -// GetAPIVersion returns the ARM API version of the resource. This is always v2020 -func (person Person_Spec_ARM) GetAPIVersion() string { - return string(APIVersion_v2020) -} - -// GetName returns the Name of the resource -func (person *Person_Spec_ARM) GetName() string { - return person.Name -} - -// GetType returns the ARM Type of the resource. This is always "" -func (person *Person_Spec_ARM) GetType() string { - return "" -} - -type Person_STATUS_ARM struct { - // Status: Current status - Status string `json:"status,omitempty"` -} - // +kubebuilder:validation:Enum={v2020} type APIVersion string @@ -84,7 +57,7 @@ func (person *Person_Spec) ConvertToARM(resolved genruntime.ConvertToARMResolved if person == nil { return nil, nil } - result := &Person_Spec_ARM{} + result := &arm.Person_Spec{} // Set property "Name": result.Name = resolved.Name @@ -94,7 +67,7 @@ func (person *Person_Spec) ConvertToARM(resolved genruntime.ConvertToARMResolved person.FamilyNameFromConfig != nil || person.FullName != nil || person.KnownAs != nil { - result.Properties = &PersonProperties_ARM{} + result.Properties = &arm.PersonProperties{} } if person.FamilyName != nil { familyName := *person.FamilyName @@ -125,14 +98,14 @@ func (person *Person_Spec) ConvertToARM(resolved genruntime.ConvertToARMResolved // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (person *Person_Spec) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &Person_Spec_ARM{} + return &arm.Person_Spec{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (person *Person_Spec) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(Person_Spec_ARM) + typedInput, ok := armInput.(arm.Person_Spec) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected Person_Spec_ARM, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.Person_Spec, got %T", armInput) } // Set property "AzureName": @@ -170,14 +143,14 @@ var _ genruntime.FromARMConverter = &Person_STATUS{} // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (person *Person_STATUS) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &Person_STATUS_ARM{} + return &arm.Person_STATUS{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (person *Person_STATUS) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(Person_STATUS_ARM) + typedInput, ok := armInput.(arm.Person_STATUS) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected Person_STATUS_ARM, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.Person_STATUS, got %T", armInput) } // Set property "Status": @@ -187,17 +160,6 @@ func (person *Person_STATUS) PopulateFromARM(owner genruntime.ArbitraryOwnerRefe return nil } -type PersonProperties_ARM struct { - // FamilyName: Shared name of the family - FamilyName *string `json:"familyName,omitempty" optionalConfigMapPair:"FamilyName"` - - // FullName: As would be used to address mail - FullName string `json:"fullName,omitempty"` - - // KnownAs: How the person is generally known - KnownAs string `json:"knownAs,omitempty"` -} - func init() { SchemeBuilder.Register(&Person{}, &PersonList{}) } diff --git a/v2/tools/generator/internal/codegen/pipeline/testdata/TestCreateFlattenedARMTypeWithResourceRef_CreatesExpectedConversions/person-v20200101-arm.golden b/v2/tools/generator/internal/codegen/pipeline/testdata/TestCreateFlattenedARMTypeWithResourceRef_CreatesExpectedConversions/person-v20200101-arm.golden index b247ecfe92..d06e595b67 100644 --- a/v2/tools/generator/internal/codegen/pipeline/testdata/TestCreateFlattenedARMTypeWithResourceRef_CreatesExpectedConversions/person-v20200101-arm.golden +++ b/v2/tools/generator/internal/codegen/pipeline/testdata/TestCreateFlattenedARMTypeWithResourceRef_CreatesExpectedConversions/person-v20200101-arm.golden @@ -5,35 +5,35 @@ package arm import "github.com/Azure/azure-service-operator/v2/pkg/genruntime" -type Person_Spec_BOOMBABOOMBA struct { +type Person_Spec struct { // Name: The name of the resource - Name string `json:"name,omitempty"` - Properties *PersonProperties_BOOMBABOOMBA `json:"properties,omitempty"` + Name string `json:"name,omitempty"` + Properties *PersonProperties `json:"properties,omitempty"` } -var _ genruntime.ARMResourceSpec = &Person_Spec_BOOMBABOOMBA{} +var _ genruntime.ARMResourceSpec = &Person_Spec{} // GetAPIVersion returns the ARM API version of the resource. This is always v2020 -func (boombaboomba Person_Spec_BOOMBABOOMBA) GetAPIVersion() string { +func (person Person_Spec) GetAPIVersion() string { return string(APIVersion_v2020) } // GetName returns the Name of the resource -func (boombaboomba *Person_Spec_BOOMBABOOMBA) GetName() string { - return boombaboomba.Name +func (person *Person_Spec) GetName() string { + return person.Name } // GetType returns the ARM Type of the resource. This is always "" -func (boombaboomba *Person_Spec_BOOMBABOOMBA) GetType() string { +func (person *Person_Spec) GetType() string { return "" } -type Person_STATUS_BOOMBABOOMBA struct { +type Person_STATUS struct { // Status: Current status Status string `json:"status,omitempty"` } -type PersonProperties_BOOMBABOOMBA struct { +type PersonProperties struct { FamilyName *string `json:"familyName,omitempty"` // FullName: As would be used to address mail diff --git a/v2/tools/generator/internal/codegen/pipeline/testdata/TestCreateFlattenedARMTypeWithResourceRef_CreatesExpectedConversions/person-v20200101.golden b/v2/tools/generator/internal/codegen/pipeline/testdata/TestCreateFlattenedARMTypeWithResourceRef_CreatesExpectedConversions/person-v20200101.golden index dafc753f92..72eddba587 100644 --- a/v2/tools/generator/internal/codegen/pipeline/testdata/TestCreateFlattenedARMTypeWithResourceRef_CreatesExpectedConversions/person-v20200101.golden +++ b/v2/tools/generator/internal/codegen/pipeline/testdata/TestCreateFlattenedARMTypeWithResourceRef_CreatesExpectedConversions/person-v20200101.golden @@ -5,6 +5,7 @@ package v20200101 import ( "fmt" + arm "github.com/Azure/azure-service-operator/testing/person/v20200101/arm" "github.com/Azure/azure-service-operator/v2/pkg/genruntime" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -25,34 +26,6 @@ type PersonList struct { Items []Person `json:"items"` } -type Person_Spec_ARM struct { - // Name: The name of the resource - Name string `json:"name,omitempty"` - Properties *PersonProperties_ARM `json:"properties,omitempty"` -} - -var _ genruntime.ARMResourceSpec = &Person_Spec_ARM{} - -// GetAPIVersion returns the ARM API version of the resource. This is always v2020 -func (person Person_Spec_ARM) GetAPIVersion() string { - return string(APIVersion_v2020) -} - -// GetName returns the Name of the resource -func (person *Person_Spec_ARM) GetName() string { - return person.Name -} - -// GetType returns the ARM Type of the resource. This is always "" -func (person *Person_Spec_ARM) GetType() string { - return "" -} - -type Person_STATUS_ARM struct { - // Status: Current status - Status string `json:"status,omitempty"` -} - // +kubebuilder:validation:Enum={v2020} type APIVersion string @@ -80,7 +53,7 @@ func (person *Person_Spec) ConvertToARM(resolved genruntime.ConvertToARMResolved if person == nil { return nil, nil } - result := &Person_Spec_ARM{} + result := &arm.Person_Spec{} // Set property "Name": result.Name = resolved.Name @@ -89,7 +62,7 @@ func (person *Person_Spec) ConvertToARM(resolved genruntime.ConvertToARMResolved if person.FamilyNameReference != nil || person.FullName != nil || person.KnownAs != nil { - result.Properties = &PersonProperties_ARM{} + result.Properties = &arm.PersonProperties{} } if person.FamilyNameReference != nil { familyNameARMID, err := resolved.ResolvedReferences.Lookup(*person.FamilyNameReference) @@ -110,14 +83,14 @@ func (person *Person_Spec) ConvertToARM(resolved genruntime.ConvertToARMResolved // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (person *Person_Spec) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &Person_Spec_ARM{} + return &arm.Person_Spec{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (person *Person_Spec) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(Person_Spec_ARM) + typedInput, ok := armInput.(arm.Person_Spec) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected Person_Spec_ARM, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.Person_Spec, got %T", armInput) } // Set property "AzureName": @@ -150,14 +123,14 @@ var _ genruntime.FromARMConverter = &Person_STATUS{} // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (person *Person_STATUS) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &Person_STATUS_ARM{} + return &arm.Person_STATUS{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (person *Person_STATUS) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(Person_STATUS_ARM) + typedInput, ok := armInput.(arm.Person_STATUS) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected Person_STATUS_ARM, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.Person_STATUS, got %T", armInput) } // Set property "Status": @@ -167,16 +140,6 @@ func (person *Person_STATUS) PopulateFromARM(owner genruntime.ArbitraryOwnerRefe return nil } -type PersonProperties_ARM struct { - FamilyName *string `json:"familyName,omitempty"` - - // FullName: As would be used to address mail - FullName string `json:"fullName,omitempty"` - - // KnownAs: How the person is generally known - KnownAs string `json:"knownAs,omitempty"` -} - func init() { SchemeBuilder.Register(&Person{}, &PersonList{}) } diff --git a/v2/tools/generator/internal/codegen/pipeline/testdata/TestCreateFlattenedARMType_CreatesExpectedConversions/person-v20200101-arm.golden b/v2/tools/generator/internal/codegen/pipeline/testdata/TestCreateFlattenedARMType_CreatesExpectedConversions/person-v20200101-arm.golden index 213b18767d..44ddeb9fd7 100644 --- a/v2/tools/generator/internal/codegen/pipeline/testdata/TestCreateFlattenedARMType_CreatesExpectedConversions/person-v20200101-arm.golden +++ b/v2/tools/generator/internal/codegen/pipeline/testdata/TestCreateFlattenedARMType_CreatesExpectedConversions/person-v20200101-arm.golden @@ -5,35 +5,35 @@ package arm import "github.com/Azure/azure-service-operator/v2/pkg/genruntime" -type Person_Spec_BOOMBABOOMBA struct { +type Person_Spec struct { // Name: The name of the resource - Name string `json:"name,omitempty"` - Properties *PersonProperties_BOOMBABOOMBA `json:"properties,omitempty"` + Name string `json:"name,omitempty"` + Properties *PersonProperties `json:"properties,omitempty"` } -var _ genruntime.ARMResourceSpec = &Person_Spec_BOOMBABOOMBA{} +var _ genruntime.ARMResourceSpec = &Person_Spec{} // GetAPIVersion returns the ARM API version of the resource. This is always v2020 -func (boombaboomba Person_Spec_BOOMBABOOMBA) GetAPIVersion() string { +func (person Person_Spec) GetAPIVersion() string { return string(APIVersion_v2020) } // GetName returns the Name of the resource -func (boombaboomba *Person_Spec_BOOMBABOOMBA) GetName() string { - return boombaboomba.Name +func (person *Person_Spec) GetName() string { + return person.Name } // GetType returns the ARM Type of the resource. This is always "" -func (boombaboomba *Person_Spec_BOOMBABOOMBA) GetType() string { +func (person *Person_Spec) GetType() string { return "" } -type Person_STATUS_BOOMBABOOMBA struct { +type Person_STATUS struct { // Status: Current status Status string `json:"status,omitempty"` } -type PersonProperties_BOOMBABOOMBA struct { +type PersonProperties struct { // FamilyName: Shared name of the family FamilyName string `json:"familyName,omitempty"` diff --git a/v2/tools/generator/internal/codegen/pipeline/testdata/TestCreateFlattenedARMType_CreatesExpectedConversions/person-v20200101.golden b/v2/tools/generator/internal/codegen/pipeline/testdata/TestCreateFlattenedARMType_CreatesExpectedConversions/person-v20200101.golden index 119a86cddc..112428c8cf 100644 --- a/v2/tools/generator/internal/codegen/pipeline/testdata/TestCreateFlattenedARMType_CreatesExpectedConversions/person-v20200101.golden +++ b/v2/tools/generator/internal/codegen/pipeline/testdata/TestCreateFlattenedARMType_CreatesExpectedConversions/person-v20200101.golden @@ -5,6 +5,7 @@ package v20200101 import ( "fmt" + arm "github.com/Azure/azure-service-operator/testing/person/v20200101/arm" "github.com/Azure/azure-service-operator/v2/pkg/genruntime" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -25,34 +26,6 @@ type PersonList struct { Items []Person `json:"items"` } -type Person_Spec_ARM struct { - // Name: The name of the resource - Name string `json:"name,omitempty"` - Properties *PersonProperties_ARM `json:"properties,omitempty"` -} - -var _ genruntime.ARMResourceSpec = &Person_Spec_ARM{} - -// GetAPIVersion returns the ARM API version of the resource. This is always v2020 -func (person Person_Spec_ARM) GetAPIVersion() string { - return string(APIVersion_v2020) -} - -// GetName returns the Name of the resource -func (person *Person_Spec_ARM) GetName() string { - return person.Name -} - -// GetType returns the ARM Type of the resource. This is always "" -func (person *Person_Spec_ARM) GetType() string { - return "" -} - -type Person_STATUS_ARM struct { - // Status: Current status - Status string `json:"status,omitempty"` -} - // +kubebuilder:validation:Enum={v2020} type APIVersion string @@ -80,7 +53,7 @@ func (person *Person_Spec) ConvertToARM(resolved genruntime.ConvertToARMResolved if person == nil { return nil, nil } - result := &Person_Spec_ARM{} + result := &arm.Person_Spec{} // Set property "Name": result.Name = resolved.Name @@ -89,7 +62,7 @@ func (person *Person_Spec) ConvertToARM(resolved genruntime.ConvertToARMResolved if person.FamilyName != nil || person.FullName != nil || person.KnownAs != nil { - result.Properties = &PersonProperties_ARM{} + result.Properties = &arm.PersonProperties{} } if person.FamilyName != nil { result.Properties.FamilyName = *person.FamilyName @@ -105,14 +78,14 @@ func (person *Person_Spec) ConvertToARM(resolved genruntime.ConvertToARMResolved // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (person *Person_Spec) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &Person_Spec_ARM{} + return &arm.Person_Spec{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (person *Person_Spec) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(Person_Spec_ARM) + typedInput, ok := armInput.(arm.Person_Spec) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected Person_Spec_ARM, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.Person_Spec, got %T", armInput) } // Set property "AzureName": @@ -149,14 +122,14 @@ var _ genruntime.FromARMConverter = &Person_STATUS{} // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (person *Person_STATUS) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &Person_STATUS_ARM{} + return &arm.Person_STATUS{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (person *Person_STATUS) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(Person_STATUS_ARM) + typedInput, ok := armInput.(arm.Person_STATUS) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected Person_STATUS_ARM, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.Person_STATUS, got %T", armInput) } // Set property "Status": @@ -166,17 +139,6 @@ func (person *Person_STATUS) PopulateFromARM(owner genruntime.ArbitraryOwnerRefe return nil } -type PersonProperties_ARM struct { - // FamilyName: Shared name of the family - FamilyName string `json:"familyName,omitempty"` - - // FullName: As would be used to address mail - FullName string `json:"fullName,omitempty"` - - // KnownAs: How the person is generally known - KnownAs string `json:"knownAs,omitempty"` -} - func init() { SchemeBuilder.Register(&Person{}, &PersonList{}) } diff --git a/v2/tools/generator/internal/codegen/pipeline/testdata/TestGolden_CreateBackwardCompatibilityTypes/person-v1beta20200101.golden b/v2/tools/generator/internal/codegen/pipeline/testdata/TestGolden_CreateBackwardCompatibilityTypes/person-v1beta20200101.golden deleted file mode 100644 index fd759d228b..0000000000 --- a/v2/tools/generator/internal/codegen/pipeline/testdata/TestGolden_CreateBackwardCompatibilityTypes/person-v1beta20200101.golden +++ /dev/null @@ -1,43 +0,0 @@ -// Code generated by azure-service-operator-codegen. DO NOT EDIT. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. -package v1beta20200101 - -import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - -// +kubebuilder:object:root=true -// +kubebuilder:subresource:status -// Deprecated version of Person. Use v20200101.Person instead -type Person struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - Spec Person_Spec `json:"spec,omitempty"` - Status Person_STATUS `json:"status,omitempty"` -} - -// +kubebuilder:object:root=true -// Deprecated version of Person. Use v20200101.Person instead -type PersonList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata,omitempty"` - Items []Person `json:"items"` -} - -// Deprecated version of Person_Spec. Use v20200101.Person_Spec instead -type Person_Spec struct { - FamilyName string `json:"familyName,omitempty"` - FullName string `json:"fullName,omitempty"` - KnownAs string `json:"knownAs,omitempty"` -} - -// Deprecated version of Person_STATUS. Use v20200101.Person_STATUS instead -type Person_STATUS struct { - FamilyName string `json:"familyName,omitempty"` - FullName string `json:"fullName,omitempty"` - KnownAs string `json:"knownAs,omitempty"` - Status string `json:"status,omitempty"` -} - -func init() { - SchemeBuilder.Register(&Person{}, &PersonList{}) -} diff --git a/v2/tools/generator/internal/codegen/pipeline/testdata/TestGolden_CreateBackwardCompatibilityTypes/person-v20200101.golden b/v2/tools/generator/internal/codegen/pipeline/testdata/TestGolden_CreateBackwardCompatibilityTypes/person-v20200101.golden deleted file mode 100644 index ef715bf1f2..0000000000 --- a/v2/tools/generator/internal/codegen/pipeline/testdata/TestGolden_CreateBackwardCompatibilityTypes/person-v20200101.golden +++ /dev/null @@ -1,51 +0,0 @@ -// Code generated by azure-service-operator-codegen. DO NOT EDIT. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. -package v20200101 - -import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - -// +kubebuilder:object:root=true -// +kubebuilder:subresource:status -type Person struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - Spec Person_Spec `json:"spec,omitempty"` - Status Person_STATUS `json:"status,omitempty"` -} - -// +kubebuilder:object:root=true -type PersonList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata,omitempty"` - Items []Person `json:"items"` -} - -type Person_Spec struct { - // FamilyName: Shared name of the family - FamilyName string `json:"familyName,omitempty"` - - // FullName: As would be used to address mail - FullName string `json:"fullName,omitempty"` - - // KnownAs: How the person is generally known - KnownAs string `json:"knownAs,omitempty"` -} - -type Person_STATUS struct { - // FamilyName: Shared name of the family - FamilyName string `json:"familyName,omitempty"` - - // FullName: As would be used to address mail - FullName string `json:"fullName,omitempty"` - - // KnownAs: How the person is generally known - KnownAs string `json:"knownAs,omitempty"` - - // Status: Current status - Status string `json:"status,omitempty"` -} - -func init() { - SchemeBuilder.Register(&Person{}, &PersonList{}) -} diff --git a/v2/tools/generator/internal/codegen/pipeline/testdata/TestGolden_InjectJsonSerializationTests/person-v20200101_test.golden b/v2/tools/generator/internal/codegen/pipeline/testdata/TestGolden_InjectJsonSerializationTests/person-v20200101_test.golden index 0de52ff9c1..5fc750541d 100644 --- a/v2/tools/generator/internal/codegen/pipeline/testdata/TestGolden_InjectJsonSerializationTests/person-v20200101_test.golden +++ b/v2/tools/generator/internal/codegen/pipeline/testdata/TestGolden_InjectJsonSerializationTests/person-v20200101_test.golden @@ -138,6 +138,66 @@ func AddIndependentPropertyGeneratorsForPerson_STATUS(gens map[string]gopter.Gen gens["Status"] = gen.AlphaString() } +func Test_Person_STATUS_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { + t.Parallel() + parameters := gopter.DefaultTestParameters() + parameters.MinSuccessfulTests = 80 + parameters.MaxSize = 3 + properties := gopter.NewProperties(parameters) + properties.Property( + "Round trip of Person_STATUS via JSON returns original", + prop.ForAll(RunJSONSerializationTestForPerson_STATUS, Person_STATUSGenerator())) + properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout)) +} + +// RunJSONSerializationTestForPerson_STATUS runs a test to see if a specific instance of Person_STATUS round trips to JSON and back losslessly +func RunJSONSerializationTestForPerson_STATUS(subject Person_STATUS) string { + // Serialize to JSON + bin, err := json.Marshal(subject) + if err != nil { + return err.Error() + } + + // Deserialize back into memory + var actual Person_STATUS + err = json.Unmarshal(bin, &actual) + if err != nil { + return err.Error() + } + + // Check for outcome + match := cmp.Equal(subject, actual, cmpopts.EquateEmpty()) + if !match { + actualFmt := pretty.Sprint(actual) + subjectFmt := pretty.Sprint(subject) + result := diff.Diff(subjectFmt, actualFmt) + return result + } + + return "" +} + +// Generator of Person_STATUS instances for property testing - lazily instantiated by Person_STATUSGenerator() +var person_STATUSGenerator gopter.Gen + +// Person_STATUSGenerator returns a generator of Person_STATUS instances for property testing. +func Person_STATUSGenerator() gopter.Gen { + if person_STATUSGenerator != nil { + return person_STATUSGenerator + } + + generators := make(map[string]gopter.Gen) + AddIndependentPropertyGeneratorsForPerson_STATUS(generators) + person_STATUSGenerator = gen.Struct(reflect.TypeOf(Person_STATUS{}), generators) + + return person_STATUSGenerator +} + +// AddIndependentPropertyGeneratorsForPerson_STATUS is a factory method for creating gopter generators +func AddIndependentPropertyGeneratorsForPerson_STATUS(gens map[string]gopter.Gen) { + gens["Status"] = gen.AlphaString() +} + func Test_Person_Spec_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { t.Parallel() parameters := gopter.DefaultTestParameters() diff --git a/v2/tools/generator/internal/codegen/pipeline/testdata/TestGolden_InjectJsonSerializationTests/person-v20211231-storage_test.golden b/v2/tools/generator/internal/codegen/pipeline/testdata/TestGolden_InjectJsonSerializationTests/person-v20211231-storage_test.golden index cbec87bd95..42e5126129 100644 --- a/v2/tools/generator/internal/codegen/pipeline/testdata/TestGolden_InjectJsonSerializationTests/person-v20211231-storage_test.golden +++ b/v2/tools/generator/internal/codegen/pipeline/testdata/TestGolden_InjectJsonSerializationTests/person-v20211231-storage_test.golden @@ -81,17 +81,17 @@ func AddIndependentPropertyGeneratorsForAddress(gens map[string]gopter.Gen) { func Test_Person_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { t.Parallel() parameters := gopter.DefaultTestParameters() - parameters.MinSuccessfulTests = 20 + parameters.MinSuccessfulTests = 100 parameters.MaxSize = 3 properties := gopter.NewProperties(parameters) properties.Property( - "Round trip of Person via JSON returns original", - prop.ForAll(RunJSONSerializationTestForPerson, PersonGenerator())) + "Round trip of Address via JSON returns original", + prop.ForAll(RunJSONSerializationTestForAddress, AddressGenerator())) properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout)) } -// RunJSONSerializationTestForPerson runs a test to see if a specific instance of Person round trips to JSON and back losslessly -func RunJSONSerializationTestForPerson(subject Person) string { +// RunJSONSerializationTestForAddress runs a test to see if a specific instance of Address round trips to JSON and back losslessly +func RunJSONSerializationTestForAddress(subject Address) string { // Serialize to JSON bin, err := json.Marshal(subject) if err != nil { @@ -99,7 +99,7 @@ func RunJSONSerializationTestForPerson(subject Person) string { } // Deserialize back into memory - var actual Person + var actual Address err = json.Unmarshal(bin, &actual) if err != nil { return err.Error() @@ -117,32 +117,32 @@ func RunJSONSerializationTestForPerson(subject Person) string { return "" } -// Generator of Person instances for property testing - lazily instantiated by PersonGenerator() -var personGenerator gopter.Gen +// Generator of Address instances for property testing - lazily instantiated by AddressGenerator() +var addressGenerator gopter.Gen -// PersonGenerator returns a generator of Person instances for property testing. -func PersonGenerator() gopter.Gen { - if personGenerator != nil { - return personGenerator +// AddressGenerator returns a generator of Address instances for property testing. +func AddressGenerator() gopter.Gen { + if addressGenerator != nil { + return addressGenerator } generators := make(map[string]gopter.Gen) - AddRelatedPropertyGeneratorsForPerson(generators) - personGenerator = gen.Struct(reflect.TypeOf(Person{}), generators) + AddIndependentPropertyGeneratorsForAddress(generators) + addressGenerator = gen.Struct(reflect.TypeOf(Address{}), generators) - return personGenerator + return addressGenerator } -// AddRelatedPropertyGeneratorsForPerson is a factory method for creating gopter generators -func AddRelatedPropertyGeneratorsForPerson(gens map[string]gopter.Gen) { - gens["Spec"] = Person_SpecGenerator() - gens["Status"] = Person_STATUSGenerator() +// AddIndependentPropertyGeneratorsForAddress is a factory method for creating gopter generators +func AddIndependentPropertyGeneratorsForAddress(gens map[string]gopter.Gen) { + gens["City"] = gen.PtrOf(gen.AlphaString()) + gens["FullAddress"] = gen.PtrOf(gen.AlphaString()) } func Test_Person_STATUS_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { t.Parallel() parameters := gopter.DefaultTestParameters() - parameters.MinSuccessfulTests = 80 + parameters.MinSuccessfulTests = 20 parameters.MaxSize = 3 properties := gopter.NewProperties(parameters) properties.Property( diff --git a/v2/tools/generator/internal/codegen/pipeline/testdata/TestGolden_InjectResourceConversionTestCases/person-v20200101-storage_test.golden b/v2/tools/generator/internal/codegen/pipeline/testdata/TestGolden_InjectResourceConversionTestCases/person-v20200101-storage_test.golden index 8a946bdf8f..2657d78c6c 100644 --- a/v2/tools/generator/internal/codegen/pipeline/testdata/TestGolden_InjectResourceConversionTestCases/person-v20200101-storage_test.golden +++ b/v2/tools/generator/internal/codegen/pipeline/testdata/TestGolden_InjectResourceConversionTestCases/person-v20200101-storage_test.golden @@ -164,32 +164,32 @@ func AddRelatedPropertyGeneratorsForPerson(gens map[string]gopter.Gen) { gens["Status"] = Person_STATUSGenerator() } -func Test_Person_STATUS_WhenPropertiesConverted_RoundTripsWithoutLoss(t *testing.T) { +func Test_Person_Spec_WhenPropertiesConverted_RoundTripsWithoutLoss(t *testing.T) { t.Parallel() parameters := gopter.DefaultTestParameters() parameters.MaxSize = 10 properties := gopter.NewProperties(parameters) properties.Property( - "Round trip from Person_STATUS to Person_STATUS via AssignProperties_To_Person_STATUS & AssignProperties_From_Person_STATUS returns original", - prop.ForAll(RunPropertyAssignmentTestForPerson_STATUS, Person_STATUSGenerator())) + "Round trip from Person_Spec to Person_Spec via AssignProperties_To_Person_Spec & AssignProperties_From_Person_Spec returns original", + prop.ForAll(RunPropertyAssignmentTestForPerson_Spec, Person_SpecGenerator())) properties.TestingRun(t, gopter.NewFormatedReporter(false, 240, os.Stdout)) } -// RunPropertyAssignmentTestForPerson_STATUS tests if a specific instance of Person_STATUS can be assigned to storage and back losslessly -func RunPropertyAssignmentTestForPerson_STATUS(subject Person_STATUS) string { +// RunPropertyAssignmentTestForPerson_Spec tests if a specific instance of Person_Spec can be assigned to storage and back losslessly +func RunPropertyAssignmentTestForPerson_Spec(subject Person_Spec) string { // Copy subject to make sure assignment doesn't modify it copied := subject.DeepCopy() // Use AssignPropertiesTo() for the first stage of conversion - var other storage.Person_STATUS - err := copied.AssignProperties_To_Person_STATUS(&other) + var other storage.Person_Spec + err := copied.AssignProperties_To_Person_Spec(&other) if err != nil { return err.Error() } // Use AssignPropertiesFrom() to convert back to our original type - var actual Person_STATUS - err = actual.AssignProperties_From_Person_STATUS(&other) + var actual Person_Spec + err = actual.AssignProperties_From_Person_Spec(&other) if err != nil { return err.Error() } @@ -206,20 +206,20 @@ func RunPropertyAssignmentTestForPerson_STATUS(subject Person_STATUS) string { return "" } -func Test_Person_STATUS_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { +func Test_Person_Spec_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { t.Parallel() parameters := gopter.DefaultTestParameters() parameters.MinSuccessfulTests = 80 parameters.MaxSize = 3 properties := gopter.NewProperties(parameters) properties.Property( - "Round trip of Person_STATUS via JSON returns original", - prop.ForAll(RunJSONSerializationTestForPerson_STATUS, Person_STATUSGenerator())) + "Round trip of Person_Spec via JSON returns original", + prop.ForAll(RunJSONSerializationTestForPerson_Spec, Person_SpecGenerator())) properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout)) } -// RunJSONSerializationTestForPerson_STATUS runs a test to see if a specific instance of Person_STATUS round trips to JSON and back losslessly -func RunJSONSerializationTestForPerson_STATUS(subject Person_STATUS) string { +// RunJSONSerializationTestForPerson_Spec runs a test to see if a specific instance of Person_Spec round trips to JSON and back losslessly +func RunJSONSerializationTestForPerson_Spec(subject Person_Spec) string { // Serialize to JSON bin, err := json.Marshal(subject) if err != nil { @@ -227,7 +227,7 @@ func RunJSONSerializationTestForPerson_STATUS(subject Person_STATUS) string { } // Deserialize back into memory - var actual Person_STATUS + var actual Person_Spec err = json.Unmarshal(bin, &actual) if err != nil { return err.Error() @@ -245,25 +245,27 @@ func RunJSONSerializationTestForPerson_STATUS(subject Person_STATUS) string { return "" } -// Generator of Person_STATUS instances for property testing - lazily instantiated by Person_STATUSGenerator() -var person_STATUSGenerator gopter.Gen +// Generator of Person_Spec instances for property testing - lazily instantiated by Person_SpecGenerator() +var person_SpecGenerator gopter.Gen -// Person_STATUSGenerator returns a generator of Person_STATUS instances for property testing. -func Person_STATUSGenerator() gopter.Gen { - if person_STATUSGenerator != nil { - return person_STATUSGenerator +// Person_SpecGenerator returns a generator of Person_Spec instances for property testing. +func Person_SpecGenerator() gopter.Gen { + if person_SpecGenerator != nil { + return person_SpecGenerator } generators := make(map[string]gopter.Gen) - AddIndependentPropertyGeneratorsForPerson_STATUS(generators) - person_STATUSGenerator = gen.Struct(reflect.TypeOf(Person_STATUS{}), generators) + AddIndependentPropertyGeneratorsForPerson_Spec(generators) + person_SpecGenerator = gen.Struct(reflect.TypeOf(Person_Spec{}), generators) - return person_STATUSGenerator + return person_SpecGenerator } -// AddIndependentPropertyGeneratorsForPerson_STATUS is a factory method for creating gopter generators -func AddIndependentPropertyGeneratorsForPerson_STATUS(gens map[string]gopter.Gen) { - gens["Status"] = gen.PtrOf(gen.AlphaString()) +// AddIndependentPropertyGeneratorsForPerson_Spec is a factory method for creating gopter generators +func AddIndependentPropertyGeneratorsForPerson_Spec(gens map[string]gopter.Gen) { + gens["FamilyName"] = gen.PtrOf(gen.AlphaString()) + gens["FullName"] = gen.PtrOf(gen.AlphaString()) + gens["KnownAs"] = gen.PtrOf(gen.AlphaString()) } func Test_Person_Spec_WhenPropertiesConverted_RoundTripsWithoutLoss(t *testing.T) { diff --git a/v2/tools/generator/internal/codegen/pipeline/testdata/TestGolden_InjectResourceConversionTestCases/person-v20211231_test.golden b/v2/tools/generator/internal/codegen/pipeline/testdata/TestGolden_InjectResourceConversionTestCases/person-v20211231_test.golden index 6db5bc1c24..9225f7f767 100644 --- a/v2/tools/generator/internal/codegen/pipeline/testdata/TestGolden_InjectResourceConversionTestCases/person-v20211231_test.golden +++ b/v2/tools/generator/internal/codegen/pipeline/testdata/TestGolden_InjectResourceConversionTestCases/person-v20211231_test.golden @@ -194,7 +194,7 @@ func RunPropertyAssignmentTestForPerson(subject Person) string { return err.Error() } - // Check for a match + // Check for outcome match := cmp.Equal(subject, actual, cmpopts.EquateEmpty()) if !match { actualFmt := pretty.Sprint(actual) @@ -233,7 +233,7 @@ func RunJSONSerializationTestForPerson(subject Person) string { return err.Error() } - // Check for outcome + // Compare actual with what we started with match := cmp.Equal(subject, actual, cmpopts.EquateEmpty()) if !match { actualFmt := pretty.Sprint(actual) @@ -312,7 +312,7 @@ func RunPropertyAssignmentTestForPerson_STATUS(subject Person_STATUS) string { func Test_Person_STATUS_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { t.Parallel() parameters := gopter.DefaultTestParameters() - parameters.MinSuccessfulTests = 80 + parameters.MinSuccessfulTests = 20 parameters.MaxSize = 3 properties := gopter.NewProperties(parameters) properties.Property( diff --git a/v2/tools/generator/internal/codegen/pipeline/testdata/Test_RenameProperties_PopulatesExpectedARMProperty/person-v20200101-arm.golden b/v2/tools/generator/internal/codegen/pipeline/testdata/Test_RenameProperties_PopulatesExpectedARMProperty/person-v20200101-arm.golden index 1be5539453..09cc558a98 100644 --- a/v2/tools/generator/internal/codegen/pipeline/testdata/Test_RenameProperties_PopulatesExpectedARMProperty/person-v20200101-arm.golden +++ b/v2/tools/generator/internal/codegen/pipeline/testdata/Test_RenameProperties_PopulatesExpectedARMProperty/person-v20200101-arm.golden @@ -1,59 +1,63 @@ -// Code generated by azure-service-operator-codegen. DO NOT EDIT. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. -package arm - -import ( - v20200101 "github.com/Azure/azure-service-operator/testing/person/v20200101" - "github.com/Azure/azure-service-operator/v2/pkg/genruntime" -) - -type Person_Spec_BOOMBABOOMBA struct { - APIVersion *v20200101.APIVersion `json:"apiVersion,omitempty"` - - // FamilyName: Shared name of the family - FamilyName string `json:"familyName,omitempty"` - - // FullName: As would be used to address mail - FullName string `json:"fullName,omitempty"` - - // KnownAs: How the person is generally known - KnownAs string `json:"knownAs,omitempty"` - - // Name: The name of the resource - Name string `json:"name,omitempty"` -} - -var _ genruntime.ARMResourceSpec = &Person_Spec_BOOMBABOOMBA{} - -// GetAPIVersion returns the ARM API version of the resource. This is always 2020-06-01 -func (boombaboomba Person_Spec_BOOMBABOOMBA) GetAPIVersion() string { - return string(APIVersion_apiVersion) -} - -// GetName returns the Name of the resource -func (boombaboomba *Person_Spec_BOOMBABOOMBA) GetName() string { - return boombaboomba.Name -} - -// GetType returns the ARM Type of the resource. This is always "" -func (boombaboomba *Person_Spec_BOOMBABOOMBA) GetType() string { - return "" -} - -type Person_STATUS_BOOMBABOOMBA struct { - // FamilyName: Shared name of the family - FamilyName string `json:"familyName,omitempty"` - - // FullName: As would be used to address mail - FullName string `json:"fullName,omitempty"` - - // KnownAs: How the person is generally known - KnownAs string `json:"knownAs,omitempty"` - - // Name: The name of the resource - Name string `json:"name,omitempty"` - - // Status: Current status - Status string `json:"status,omitempty"` -} + // Code generated by azure-service-operator-codegen. DO NOT EDIT. + // Copyright (c) Microsoft Corporation. + // Licensed under the MIT license. + package arm + + import ( + v20200101 "github.com/Azure/azure-service-operator/testing/person/v20200101" + "github.com/Azure/azure-service-operator/v2/pkg/genruntime" + ) + + type Person_Spec struct { + APIVersion *v20200101.APIVersion `json:"apiVersion,omitempty"` + ++ // Alias: How the person is generally known ++ Alias string `json:"alias,omitempty"` ++ + // FamilyName: Shared name of the family + FamilyName string `json:"familyName,omitempty"` + + // FullName: As would be used to address mail + FullName string `json:"fullName,omitempty"` + +- // KnownAs: How the person is generally known +- KnownAs string `json:"knownAs,omitempty"` +- + // Name: The name of the resource + Name string `json:"name,omitempty"` + } + + var _ genruntime.ARMResourceSpec = &Person_Spec{} + + // GetAPIVersion returns the ARM API version of the resource. This is always 2020-06-01 + func (person Person_Spec) GetAPIVersion() string { + return string(APIVersion_apiVersion) + } + + // GetName returns the Name of the resource + func (person *Person_Spec) GetName() string { + return person.Name + } + + // GetType returns the ARM Type of the resource. This is always "" + func (person *Person_Spec) GetType() string { + return "" + } + + type Person_STATUS struct { + // FamilyName: Shared name of the family + FamilyName string `json:"familyName,omitempty"` + + // FullName: As would be used to address mail + FullName string `json:"fullName,omitempty"` + + // KnownAs: How the person is generally known + KnownAs string `json:"knownAs,omitempty"` + + // Name: The name of the resource + Name string `json:"name,omitempty"` + + // Status: Current status + Status string `json:"status,omitempty"` + } + diff --git a/v2/tools/generator/internal/codegen/pipeline/testdata/Test_RenameProperties_PopulatesExpectedARMProperty/person-v20200101.golden b/v2/tools/generator/internal/codegen/pipeline/testdata/Test_RenameProperties_PopulatesExpectedARMProperty/person-v20200101.golden index 24268ee9a8..1bdcc7b505 100644 --- a/v2/tools/generator/internal/codegen/pipeline/testdata/Test_RenameProperties_PopulatesExpectedARMProperty/person-v20200101.golden +++ b/v2/tools/generator/internal/codegen/pipeline/testdata/Test_RenameProperties_PopulatesExpectedARMProperty/person-v20200101.golden @@ -26,56 +26,6 @@ Items []Person `json:"items"` } - type Person_Spec_ARM struct { - APIVersion *APIVersion `json:"apiVersion,omitempty"` - - // FamilyName: Shared name of the family - FamilyName string `json:"familyName,omitempty"` - - // FullName: As would be used to address mail - FullName string `json:"fullName,omitempty"` - - // KnownAs: How the person is generally known - KnownAs string `json:"knownAs,omitempty"` - - // Name: The name of the resource - Name string `json:"name,omitempty"` - } - - var _ genruntime.ARMResourceSpec = &Person_Spec_ARM{} - - // GetAPIVersion returns the ARM API version of the resource. This is always 2020-06-01 - func (person Person_Spec_ARM) GetAPIVersion() string { - return string(APIVersion_apiVersion) - } - - // GetName returns the Name of the resource - func (person *Person_Spec_ARM) GetName() string { - return person.Name - } - - // GetType returns the ARM Type of the resource. This is always "" - func (person *Person_Spec_ARM) GetType() string { - return "" - } - - type Person_STATUS_ARM struct { - // FamilyName: Shared name of the family - FamilyName string `json:"familyName,omitempty"` - - // FullName: As would be used to address mail - FullName string `json:"fullName,omitempty"` - - // KnownAs: How the person is generally known - KnownAs string `json:"knownAs,omitempty"` - - // Name: The name of the resource - Name string `json:"name,omitempty"` - - // Status: Current status - Status string `json:"status,omitempty"` - } - // +kubebuilder:validation:Enum={2020-06-01} type APIVersion string @@ -124,8 +74,7 @@ result.FullName = person.FullName // Set property "KnownAs": -- result.KnownAs = person.KnownAs -+ result.KnownAs = person.Alias + result.KnownAs = person.Alias // Set property "Name": result.Name = resolved.Name @@ -139,9 +88,9 @@ // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (person *Person_Spec) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(Person_Spec_ARM) + typedInput, ok := armInput.(arm.Person_Spec) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected Person_Spec_ARM, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.Person_Spec, got %T", armInput) } // Set property "APIVersion": @@ -150,9 +99,9 @@ person.APIVersion = &apiVersion } -+ // Set property "Alias": -+ person.Alias = typedInput.KnownAs -+ + // Set property "Alias": + person.Alias = typedInput.KnownAs + // Set property "AzureName": person.SetAzureName(genruntime.ExtractKubernetesResourceNameFromARMName(typedInput.Name)) @@ -162,9 +111,6 @@ // Set property "FullName": person.FullName = typedInput.FullName -- // Set property "KnownAs": -- person.KnownAs = typedInput.KnownAs -- // No error return nil } @@ -197,7 +143,7 @@ func (person *Person_STATUS) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { typedInput, ok := armInput.(arm.Person_STATUS) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected Person_STATUS_ARM, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.Person_STATUS, got %T", armInput) } // Set property "FamilyName": diff --git a/v2/tools/generator/internal/codegen/pipeline/testdata/Test_RenameProperties_WhenFlattening_PopulatesExpectedARMProperty/person-v20200101-arm.golden b/v2/tools/generator/internal/codegen/pipeline/testdata/Test_RenameProperties_WhenFlattening_PopulatesExpectedARMProperty/person-v20200101-arm.golden index 5b8fdce229..08dd839157 100644 --- a/v2/tools/generator/internal/codegen/pipeline/testdata/Test_RenameProperties_WhenFlattening_PopulatesExpectedARMProperty/person-v20200101-arm.golden +++ b/v2/tools/generator/internal/codegen/pipeline/testdata/Test_RenameProperties_WhenFlattening_PopulatesExpectedARMProperty/person-v20200101-arm.golden @@ -8,9 +8,9 @@ import ( "github.com/Azure/azure-service-operator/v2/pkg/genruntime" ) -type Person_Spec_BOOMBABOOMBA struct { +type Person_Spec struct { APIVersion *v20200101.APIVersion `json:"apiVersion,omitempty"` - Address *Address_BOOMBABOOMBA `json:"address,omitempty"` + Address *Address `json:"address,omitempty"` // FamilyName: Shared name of the family FamilyName string `json:"familyName,omitempty"` @@ -25,24 +25,24 @@ type Person_Spec_BOOMBABOOMBA struct { Name string `json:"name,omitempty"` } -var _ genruntime.ARMResourceSpec = &Person_Spec_BOOMBABOOMBA{} +var _ genruntime.ARMResourceSpec = &Person_Spec{} // GetAPIVersion returns the ARM API version of the resource. This is always 2020-06-01 -func (boombaboomba Person_Spec_BOOMBABOOMBA) GetAPIVersion() string { +func (person Person_Spec) GetAPIVersion() string { return string(APIVersion_apiVersion) } // GetName returns the Name of the resource -func (boombaboomba *Person_Spec_BOOMBABOOMBA) GetName() string { - return boombaboomba.Name +func (person *Person_Spec) GetName() string { + return person.Name } // GetType returns the ARM Type of the resource. This is always "" -func (boombaboomba *Person_Spec_BOOMBABOOMBA) GetType() string { +func (person *Person_Spec) GetType() string { return "" } -type Person_STATUS_BOOMBABOOMBA struct { +type Person_STATUS struct { // FamilyName: Shared name of the family FamilyName string `json:"familyName,omitempty"` @@ -59,7 +59,7 @@ type Person_STATUS_BOOMBABOOMBA struct { Status string `json:"status,omitempty"` } -type Address_BOOMBABOOMBA struct { +type Address struct { // City: City or town (or nearest) City string `json:"city,omitempty"` diff --git a/v2/tools/generator/internal/codegen/pipeline/testdata/Test_RenameProperties_WhenFlattening_PopulatesExpectedARMProperty/person-v20200101.golden b/v2/tools/generator/internal/codegen/pipeline/testdata/Test_RenameProperties_WhenFlattening_PopulatesExpectedARMProperty/person-v20200101.golden index f45ef061dc..ad92460d05 100644 --- a/v2/tools/generator/internal/codegen/pipeline/testdata/Test_RenameProperties_WhenFlattening_PopulatesExpectedARMProperty/person-v20200101.golden +++ b/v2/tools/generator/internal/codegen/pipeline/testdata/Test_RenameProperties_WhenFlattening_PopulatesExpectedARMProperty/person-v20200101.golden @@ -44,7 +44,7 @@ func (address *Address) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { typedInput, ok := armInput.(arm.Address) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected Address_ARM, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.Address, got %T", armInput) } // Set property "City": @@ -73,65 +73,6 @@ Items []Person `json:"items"` } - type Person_Spec_ARM struct { - APIVersion *APIVersion `json:"apiVersion,omitempty"` - Address *Address_ARM `json:"address,omitempty"` - - // FamilyName: Shared name of the family - FamilyName string `json:"familyName,omitempty"` - - // FullName: As would be used to address mail - FullName string `json:"fullName,omitempty"` - - // KnownAs: How the person is generally known - KnownAs string `json:"knownAs,omitempty"` - - // Name: The name of the resource - Name string `json:"name,omitempty"` - } - - var _ genruntime.ARMResourceSpec = &Person_Spec_ARM{} - - // GetAPIVersion returns the ARM API version of the resource. This is always 2020-06-01 - func (person Person_Spec_ARM) GetAPIVersion() string { - return string(APIVersion_apiVersion) - } - - // GetName returns the Name of the resource - func (person *Person_Spec_ARM) GetName() string { - return person.Name - } - - // GetType returns the ARM Type of the resource. This is always "" - func (person *Person_Spec_ARM) GetType() string { - return "" - } - - type Person_STATUS_ARM struct { - // FamilyName: Shared name of the family - FamilyName string `json:"familyName,omitempty"` - - // FullName: As would be used to address mail - FullName string `json:"fullName,omitempty"` - - // KnownAs: How the person is generally known - KnownAs string `json:"knownAs,omitempty"` - - // Name: The name of the resource - Name string `json:"name,omitempty"` - - // Status: Current status - Status string `json:"status,omitempty"` - } - - type Address_ARM struct { - // City: City or town (or nearest) - City string `json:"city,omitempty"` - - // FullAddress: Full written address for map or postal use - FullAddress string `json:"fullAddress,omitempty"` - } - // +kubebuilder:validation:Enum={2020-06-01} type APIVersion string @@ -180,17 +121,14 @@ } // Set property "Address": -- if person.City != nil || person.FullAddress != nil { -+ if person.City != nil || person.PostalAddress != nil { - result.Address = &Address_ARM{} + if person.City != nil || person.PostalAddress != nil { + result.Address = &arm.Address{} } if person.City != nil { result.Address.City = *person.City } -- if person.FullAddress != nil { -- result.Address.FullAddress = *person.FullAddress -+ if person.PostalAddress != nil { -+ result.Address.FullAddress = *person.PostalAddress + if person.PostalAddress != nil { + result.Address.FullAddress = *person.PostalAddress } // Set property "FamilyName": @@ -209,14 +147,14 @@ // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (person *Person_Spec) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &Person_Spec_ARM{} + return &arm.Person_Spec{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (person *Person_Spec) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(Person_Spec_ARM) + typedInput, ok := armInput.(arm.Person_Spec) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected Person_Spec_ARM, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.Person_Spec, got %T", armInput) } // Set property "APIVersion": @@ -237,24 +175,18 @@ // Set property "FamilyName": person.FamilyName = typedInput.FamilyName -- // Set property "FullAddress": -- // copying flattened property: -- if typedInput.Address != nil { -- person.FullAddress = &typedInput.Address.FullAddress -- } -- // Set property "FullName": person.FullName = typedInput.FullName // Set property "KnownAs": person.KnownAs = typedInput.KnownAs -+ // Set property "PostalAddress": -+ // copying flattened property: -+ if typedInput.Address != nil { -+ person.PostalAddress = &typedInput.Address.FullAddress -+ } -+ + // Set property "PostalAddress": + // copying flattened property: + if typedInput.Address != nil { + person.PostalAddress = &typedInput.Address.FullAddress + } + // No error return nil } @@ -280,14 +212,14 @@ // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (person *Person_STATUS) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &Person_STATUS_ARM{} + return &arm.Person_STATUS{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (person *Person_STATUS) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(Person_STATUS_ARM) + typedInput, ok := armInput.(arm.Person_STATUS) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected Person_STATUS_ARM, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.Person_STATUS, got %T", armInput) } // Set property "FamilyName": diff --git a/v2/tools/generator/internal/codegen/testdata/ArmResource/Arm_oneof_resource_conversion_on_arm_type_only_azure_v1api20200101.golden b/v2/tools/generator/internal/codegen/testdata/ArmResource/Arm_oneof_resource_conversion_on_arm_type_only_azure_v1api20200101.golden index 6acf7c3be2..b7babdc250 100644 --- a/v2/tools/generator/internal/codegen/testdata/ArmResource/Arm_oneof_resource_conversion_on_arm_type_only_azure_v1api20200101.golden +++ b/v2/tools/generator/internal/codegen/testdata/ArmResource/Arm_oneof_resource_conversion_on_arm_type_only_azure_v1api20200101.golden @@ -5,8 +5,8 @@ package v1api20200101 import ( "fmt" - v20200101a "github.com/Azure/azure-service-operator/testing/test/v1api20200101/arm" - v20200101s "github.com/Azure/azure-service-operator/testing/test/v1api20200101/storage" + arm "github.com/Azure/azure-service-operator/testing/test/v1api20200101/arm" + storage "github.com/Azure/azure-service-operator/testing/test/v1api20200101/storage" "github.com/Azure/azure-service-operator/v2/internal/reflecthelpers" "github.com/Azure/azure-service-operator/v2/pkg/genruntime" "github.com/Azure/azure-service-operator/v2/pkg/genruntime/conditions" @@ -46,7 +46,7 @@ var _ conversion.Convertible = &FakeResource{} // ConvertFrom populates our FakeResource from the provided hub FakeResource func (resource *FakeResource) ConvertFrom(hub conversion.Hub) error { - source, ok := hub.(*v20200101s.FakeResource) + source, ok := hub.(*storage.FakeResource) if !ok { return fmt.Errorf("expected test/v1api20200101/storage/FakeResource but received %T instead", hub) } @@ -56,7 +56,7 @@ func (resource *FakeResource) ConvertFrom(hub conversion.Hub) error { // ConvertTo populates the provided hub FakeResource from our FakeResource func (resource *FakeResource) ConvertTo(hub conversion.Hub) error { - destination, ok := hub.(*v20200101s.FakeResource) + destination, ok := hub.(*storage.FakeResource) if !ok { return fmt.Errorf("expected test/v1api20200101/storage/FakeResource but received %T instead", hub) } @@ -211,7 +211,7 @@ func (resource *FakeResource) validateWriteOnceProperties(old runtime.Object) (a } // AssignProperties_From_FakeResource populates our FakeResource from the provided source FakeResource -func (resource *FakeResource) AssignProperties_From_FakeResource(source *v20200101s.FakeResource) error { +func (resource *FakeResource) AssignProperties_From_FakeResource(source *storage.FakeResource) error { // ObjectMeta resource.ObjectMeta = *source.ObjectMeta.DeepCopy() @@ -229,13 +229,13 @@ func (resource *FakeResource) AssignProperties_From_FakeResource(source *v202001 } // AssignProperties_To_FakeResource populates the provided destination FakeResource from our FakeResource -func (resource *FakeResource) AssignProperties_To_FakeResource(destination *v20200101s.FakeResource) error { +func (resource *FakeResource) AssignProperties_To_FakeResource(destination *storage.FakeResource) error { // ObjectMeta destination.ObjectMeta = *resource.ObjectMeta.DeepCopy() // Spec - var spec v20200101s.FakeResource_Spec + var spec storage.FakeResource_Spec err := resource.Spec.AssignProperties_To_FakeResource_Spec(&spec) if err != nil { return errors.Wrap(err, "calling AssignProperties_To_FakeResource_Spec() to populate field Spec") @@ -293,7 +293,7 @@ func (resource *FakeResource_Spec) ConvertToARM(resolved genruntime.ConvertToARM if resource == nil { return nil, nil } - result := &FakeResource_Spec{} + result := &arm.FakeResource_Spec{} // Set property "APIVersion": result.APIVersion = resource.APIVersion @@ -308,14 +308,14 @@ func (resource *FakeResource_Spec) ConvertToARM(resolved genruntime.ConvertToARM // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (resource *FakeResource_Spec) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &v20200101a.FakeResource_Spec{} + return &arm.FakeResource_Spec{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (resource *FakeResource_Spec) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(FakeResource_Spec) + typedInput, ok := armInput.(arm.FakeResource_Spec) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected FakeResource_Spec, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.FakeResource_Spec, got %T", armInput) } // Set property "APIVersion": @@ -341,14 +341,14 @@ var _ genruntime.ConvertibleSpec = &FakeResource_Spec{} // ConvertSpecFrom populates our FakeResource_Spec from the provided source func (resource *FakeResource_Spec) ConvertSpecFrom(source genruntime.ConvertibleSpec) error { - src, ok := source.(*v20200101s.FakeResource_Spec) + src, ok := source.(*storage.FakeResource_Spec) if ok { // Populate our instance from source return resource.AssignProperties_From_FakeResource_Spec(src) } // Convert to an intermediate form - src = &v20200101s.FakeResource_Spec{} + src = &storage.FakeResource_Spec{} err := src.ConvertSpecFrom(source) if err != nil { return errors.Wrap(err, "initial step of conversion in ConvertSpecFrom()") @@ -365,14 +365,14 @@ func (resource *FakeResource_Spec) ConvertSpecFrom(source genruntime.Convertible // ConvertSpecTo populates the provided destination from our FakeResource_Spec func (resource *FakeResource_Spec) ConvertSpecTo(destination genruntime.ConvertibleSpec) error { - dst, ok := destination.(*v20200101s.FakeResource_Spec) + dst, ok := destination.(*storage.FakeResource_Spec) if ok { // Populate destination from our instance return resource.AssignProperties_To_FakeResource_Spec(dst) } // Convert to an intermediate form - dst = &v20200101s.FakeResource_Spec{} + dst = &storage.FakeResource_Spec{} err := resource.AssignProperties_To_FakeResource_Spec(dst) if err != nil { return errors.Wrap(err, "initial step of conversion in ConvertSpecTo()") @@ -388,11 +388,12 @@ func (resource *FakeResource_Spec) ConvertSpecTo(destination genruntime.Converti } // AssignProperties_From_FakeResource_Spec populates our FakeResource_Spec from the provided source FakeResource_Spec -func (resource *FakeResource_Spec) AssignProperties_From_FakeResource_Spec(source *v20200101s.FakeResource_Spec) error { +func (resource *FakeResource_Spec) AssignProperties_From_FakeResource_Spec(source *storage.FakeResource_Spec) error { // APIVersion if source.APIVersion != nil { - resource.APIVersion = FakeResource_APIVersion_Spec(*source.APIVersion) + apiVersion := *source.APIVersion + resource.APIVersion = genruntime.ToEnum(apiVersion, fakeResource_APIVersion_Spec_Values) } else { resource.APIVersion = "" } @@ -410,7 +411,8 @@ func (resource *FakeResource_Spec) AssignProperties_From_FakeResource_Spec(sourc // Type if source.Type != nil { - resource.Type = FakeResource_Type_Spec(*source.Type) + typeVar := *source.Type + resource.Type = genruntime.ToEnum(typeVar, fakeResource_Type_Spec_Values) } else { resource.Type = "" } @@ -420,7 +422,7 @@ func (resource *FakeResource_Spec) AssignProperties_From_FakeResource_Spec(sourc } // AssignProperties_To_FakeResource_Spec populates the provided destination FakeResource_Spec from our FakeResource_Spec -func (resource *FakeResource_Spec) AssignProperties_To_FakeResource_Spec(destination *v20200101s.FakeResource_Spec) error { +func (resource *FakeResource_Spec) AssignProperties_To_FakeResource_Spec(destination *storage.FakeResource_Spec) error { // Create a new property bag propertyBag := genruntime.NewPropertyBag() @@ -470,11 +472,21 @@ type FakeResource_APIVersion_Spec string const FakeResource_APIVersion_Spec_20200601 = FakeResource_APIVersion_Spec("2020-06-01") +// Mapping from string to FakeResource_APIVersion_Spec +var fakeResource_APIVersion_Spec_Values = map[string]FakeResource_APIVersion_Spec{ + "2020-06-01": FakeResource_APIVersion_Spec_20200601, +} + // +kubebuilder:validation:Enum={"Microsoft.Azure/FakeResource"} type FakeResource_Type_Spec string const FakeResource_Type_Spec_MicrosoftAzureFakeResource = FakeResource_Type_Spec("Microsoft.Azure/FakeResource") +// Mapping from string to FakeResource_Type_Spec +var fakeResource_Type_Spec_Values = map[string]FakeResource_Type_Spec{ + "microsoft.azure/fakeresource": FakeResource_Type_Spec_MicrosoftAzureFakeResource, +} + func init() { SchemeBuilder.Register(&FakeResource{}, &FakeResourceList{}) } diff --git a/v2/tools/generator/internal/codegen/testdata/ArmResource/Arm_test_dependent_resource_and_ownership_azure_v1api20200101.golden b/v2/tools/generator/internal/codegen/testdata/ArmResource/Arm_test_dependent_resource_and_ownership_azure_v1api20200101.golden index 144ae829ec..d597aa32cf 100644 --- a/v2/tools/generator/internal/codegen/testdata/ArmResource/Arm_test_dependent_resource_and_ownership_azure_v1api20200101.golden +++ b/v2/tools/generator/internal/codegen/testdata/ArmResource/Arm_test_dependent_resource_and_ownership_azure_v1api20200101.golden @@ -5,8 +5,8 @@ package v1api20200101 import ( "fmt" - v20200101a "github.com/Azure/azure-service-operator/testing/test/v1api20200101/arm" - v20200101s "github.com/Azure/azure-service-operator/testing/test/v1api20200101/storage" + arm "github.com/Azure/azure-service-operator/testing/test/v1api20200101/arm" + storage "github.com/Azure/azure-service-operator/testing/test/v1api20200101/storage" "github.com/Azure/azure-service-operator/v2/internal/reflecthelpers" "github.com/Azure/azure-service-operator/v2/pkg/genruntime" "github.com/Azure/azure-service-operator/v2/pkg/genruntime/conditions" @@ -44,7 +44,7 @@ var _ conversion.Convertible = &A{} // ConvertFrom populates our A from the provided hub A func (a *A) ConvertFrom(hub conversion.Hub) error { - source, ok := hub.(*v20200101s.A) + source, ok := hub.(*storage.A) if !ok { return fmt.Errorf("expected test/v1api20200101/storage/A but received %T instead", hub) } @@ -54,7 +54,7 @@ func (a *A) ConvertFrom(hub conversion.Hub) error { // ConvertTo populates the provided hub A from our A func (a *A) ConvertTo(hub conversion.Hub) error { - destination, ok := hub.(*v20200101s.A) + destination, ok := hub.(*storage.A) if !ok { return fmt.Errorf("expected test/v1api20200101/storage/A but received %T instead", hub) } @@ -209,7 +209,7 @@ func (a *A) validateWriteOnceProperties(old runtime.Object) (admission.Warnings, } // AssignProperties_From_A populates our A from the provided source A -func (a *A) AssignProperties_From_A(source *v20200101s.A) error { +func (a *A) AssignProperties_From_A(source *storage.A) error { // ObjectMeta a.ObjectMeta = *source.ObjectMeta.DeepCopy() @@ -227,13 +227,13 @@ func (a *A) AssignProperties_From_A(source *v20200101s.A) error { } // AssignProperties_To_A populates the provided destination A from our A -func (a *A) AssignProperties_To_A(destination *v20200101s.A) error { +func (a *A) AssignProperties_To_A(destination *storage.A) error { // ObjectMeta destination.ObjectMeta = *a.ObjectMeta.DeepCopy() // Spec - var spec v20200101s.A_Spec + var spec storage.A_Spec err := a.Spec.AssignProperties_To_A_Spec(&spec) if err != nil { return errors.Wrap(err, "calling AssignProperties_To_A_Spec() to populate field Spec") @@ -287,7 +287,7 @@ var _ conversion.Convertible = &B{} // ConvertFrom populates our B from the provided hub B func (b *B) ConvertFrom(hub conversion.Hub) error { - source, ok := hub.(*v20200101s.B) + source, ok := hub.(*storage.B) if !ok { return fmt.Errorf("expected test/v1api20200101/storage/B but received %T instead", hub) } @@ -297,7 +297,7 @@ func (b *B) ConvertFrom(hub conversion.Hub) error { // ConvertTo populates the provided hub B from our B func (b *B) ConvertTo(hub conversion.Hub) error { - destination, ok := hub.(*v20200101s.B) + destination, ok := hub.(*storage.B) if !ok { return fmt.Errorf("expected test/v1api20200101/storage/B but received %T instead", hub) } @@ -452,7 +452,7 @@ func (b *B) validateWriteOnceProperties(old runtime.Object) (admission.Warnings, } // AssignProperties_From_B populates our B from the provided source B -func (b *B) AssignProperties_From_B(source *v20200101s.B) error { +func (b *B) AssignProperties_From_B(source *storage.B) error { // ObjectMeta b.ObjectMeta = *source.ObjectMeta.DeepCopy() @@ -470,13 +470,13 @@ func (b *B) AssignProperties_From_B(source *v20200101s.B) error { } // AssignProperties_To_B populates the provided destination B from our B -func (b *B) AssignProperties_To_B(destination *v20200101s.B) error { +func (b *B) AssignProperties_To_B(destination *storage.B) error { // ObjectMeta destination.ObjectMeta = *b.ObjectMeta.DeepCopy() // Spec - var spec v20200101s.B_Spec + var spec storage.B_Spec err := b.Spec.AssignProperties_To_B_Spec(&spec) if err != nil { return errors.Wrap(err, "calling AssignProperties_To_B_Spec() to populate field Spec") @@ -530,7 +530,7 @@ var _ conversion.Convertible = &C{} // ConvertFrom populates our C from the provided hub C func (c *C) ConvertFrom(hub conversion.Hub) error { - source, ok := hub.(*v20200101s.C) + source, ok := hub.(*storage.C) if !ok { return fmt.Errorf("expected test/v1api20200101/storage/C but received %T instead", hub) } @@ -540,7 +540,7 @@ func (c *C) ConvertFrom(hub conversion.Hub) error { // ConvertTo populates the provided hub C from our C func (c *C) ConvertTo(hub conversion.Hub) error { - destination, ok := hub.(*v20200101s.C) + destination, ok := hub.(*storage.C) if !ok { return fmt.Errorf("expected test/v1api20200101/storage/C but received %T instead", hub) } @@ -695,7 +695,7 @@ func (c *C) validateWriteOnceProperties(old runtime.Object) (admission.Warnings, } // AssignProperties_From_C populates our C from the provided source C -func (c *C) AssignProperties_From_C(source *v20200101s.C) error { +func (c *C) AssignProperties_From_C(source *storage.C) error { // ObjectMeta c.ObjectMeta = *source.ObjectMeta.DeepCopy() @@ -713,13 +713,13 @@ func (c *C) AssignProperties_From_C(source *v20200101s.C) error { } // AssignProperties_To_C populates the provided destination C from our C -func (c *C) AssignProperties_To_C(destination *v20200101s.C) error { +func (c *C) AssignProperties_To_C(destination *storage.C) error { // ObjectMeta destination.ObjectMeta = *c.ObjectMeta.DeepCopy() // Spec - var spec v20200101s.C_Spec + var spec storage.C_Spec err := c.Spec.AssignProperties_To_C_Spec(&spec) if err != nil { return errors.Wrap(err, "calling AssignProperties_To_C_Spec() to populate field Spec") @@ -773,7 +773,7 @@ var _ conversion.Convertible = &D{} // ConvertFrom populates our D from the provided hub D func (d *D) ConvertFrom(hub conversion.Hub) error { - source, ok := hub.(*v20200101s.D) + source, ok := hub.(*storage.D) if !ok { return fmt.Errorf("expected test/v1api20200101/storage/D but received %T instead", hub) } @@ -783,7 +783,7 @@ func (d *D) ConvertFrom(hub conversion.Hub) error { // ConvertTo populates the provided hub D from our D func (d *D) ConvertTo(hub conversion.Hub) error { - destination, ok := hub.(*v20200101s.D) + destination, ok := hub.(*storage.D) if !ok { return fmt.Errorf("expected test/v1api20200101/storage/D but received %T instead", hub) } @@ -938,7 +938,7 @@ func (d *D) validateWriteOnceProperties(old runtime.Object) (admission.Warnings, } // AssignProperties_From_D populates our D from the provided source D -func (d *D) AssignProperties_From_D(source *v20200101s.D) error { +func (d *D) AssignProperties_From_D(source *storage.D) error { // ObjectMeta d.ObjectMeta = *source.ObjectMeta.DeepCopy() @@ -956,13 +956,13 @@ func (d *D) AssignProperties_From_D(source *v20200101s.D) error { } // AssignProperties_To_D populates the provided destination D from our D -func (d *D) AssignProperties_To_D(destination *v20200101s.D) error { +func (d *D) AssignProperties_To_D(destination *storage.D) error { // ObjectMeta destination.ObjectMeta = *d.ObjectMeta.DeepCopy() // Spec - var spec v20200101s.D_Spec + var spec storage.D_Spec err := d.Spec.AssignProperties_To_D_Spec(&spec) if err != nil { return errors.Wrap(err, "calling AssignProperties_To_D_Spec() to populate field Spec") @@ -1015,7 +1015,7 @@ func (a *A_Spec) ConvertToARM(resolved genruntime.ConvertToARMResolvedDetails) ( if a == nil { return nil, nil } - result := &A_Spec{} + result := &arm.A_Spec{} // Set property "APIVersion": result.APIVersion = a.APIVersion @@ -1030,14 +1030,14 @@ func (a *A_Spec) ConvertToARM(resolved genruntime.ConvertToARMResolvedDetails) ( // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (a *A_Spec) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &v20200101a.A_Spec{} + return &arm.A_Spec{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (a *A_Spec) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(A_Spec) + typedInput, ok := armInput.(arm.A_Spec) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected A_Spec, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.A_Spec, got %T", armInput) } // Set property "APIVersion": @@ -1063,14 +1063,14 @@ var _ genruntime.ConvertibleSpec = &A_Spec{} // ConvertSpecFrom populates our A_Spec from the provided source func (a *A_Spec) ConvertSpecFrom(source genruntime.ConvertibleSpec) error { - src, ok := source.(*v20200101s.A_Spec) + src, ok := source.(*storage.A_Spec) if ok { // Populate our instance from source return a.AssignProperties_From_A_Spec(src) } // Convert to an intermediate form - src = &v20200101s.A_Spec{} + src = &storage.A_Spec{} err := src.ConvertSpecFrom(source) if err != nil { return errors.Wrap(err, "initial step of conversion in ConvertSpecFrom()") @@ -1087,14 +1087,14 @@ func (a *A_Spec) ConvertSpecFrom(source genruntime.ConvertibleSpec) error { // ConvertSpecTo populates the provided destination from our A_Spec func (a *A_Spec) ConvertSpecTo(destination genruntime.ConvertibleSpec) error { - dst, ok := destination.(*v20200101s.A_Spec) + dst, ok := destination.(*storage.A_Spec) if ok { // Populate destination from our instance return a.AssignProperties_To_A_Spec(dst) } // Convert to an intermediate form - dst = &v20200101s.A_Spec{} + dst = &storage.A_Spec{} err := a.AssignProperties_To_A_Spec(dst) if err != nil { return errors.Wrap(err, "initial step of conversion in ConvertSpecTo()") @@ -1110,11 +1110,12 @@ func (a *A_Spec) ConvertSpecTo(destination genruntime.ConvertibleSpec) error { } // AssignProperties_From_A_Spec populates our A_Spec from the provided source A_Spec -func (a *A_Spec) AssignProperties_From_A_Spec(source *v20200101s.A_Spec) error { +func (a *A_Spec) AssignProperties_From_A_Spec(source *storage.A_Spec) error { // APIVersion if source.APIVersion != nil { - a.APIVersion = A_APIVersion_Spec(*source.APIVersion) + apiVersion := *source.APIVersion + a.APIVersion = genruntime.ToEnum(apiVersion, a_APIVersion_Spec_Values) } else { a.APIVersion = "" } @@ -1132,7 +1133,8 @@ func (a *A_Spec) AssignProperties_From_A_Spec(source *v20200101s.A_Spec) error { // Type if source.Type != nil { - a.Type = A_Type_Spec(*source.Type) + typeVar := *source.Type + a.Type = genruntime.ToEnum(typeVar, a_Type_Spec_Values) } else { a.Type = "" } @@ -1142,7 +1144,7 @@ func (a *A_Spec) AssignProperties_From_A_Spec(source *v20200101s.A_Spec) error { } // AssignProperties_To_A_Spec populates the provided destination A_Spec from our A_Spec -func (a *A_Spec) AssignProperties_To_A_Spec(destination *v20200101s.A_Spec) error { +func (a *A_Spec) AssignProperties_To_A_Spec(destination *storage.A_Spec) error { // Create a new property bag propertyBag := genruntime.NewPropertyBag() @@ -1217,7 +1219,7 @@ func (b *B_Spec) ConvertToARM(resolved genruntime.ConvertToARMResolvedDetails) ( if b == nil { return nil, nil } - result := &B_Spec{} + result := &arm.B_Spec{} // Set property "APIVersion": result.APIVersion = b.APIVersion @@ -1232,14 +1234,14 @@ func (b *B_Spec) ConvertToARM(resolved genruntime.ConvertToARMResolvedDetails) ( // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (b *B_Spec) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &v20200101a.B_Spec{} + return &arm.B_Spec{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (b *B_Spec) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(B_Spec) + typedInput, ok := armInput.(arm.B_Spec) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected B_Spec, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.B_Spec, got %T", armInput) } // Set property "APIVersion": @@ -1265,14 +1267,14 @@ var _ genruntime.ConvertibleSpec = &B_Spec{} // ConvertSpecFrom populates our B_Spec from the provided source func (b *B_Spec) ConvertSpecFrom(source genruntime.ConvertibleSpec) error { - src, ok := source.(*v20200101s.B_Spec) + src, ok := source.(*storage.B_Spec) if ok { // Populate our instance from source return b.AssignProperties_From_B_Spec(src) } // Convert to an intermediate form - src = &v20200101s.B_Spec{} + src = &storage.B_Spec{} err := src.ConvertSpecFrom(source) if err != nil { return errors.Wrap(err, "initial step of conversion in ConvertSpecFrom()") @@ -1289,14 +1291,14 @@ func (b *B_Spec) ConvertSpecFrom(source genruntime.ConvertibleSpec) error { // ConvertSpecTo populates the provided destination from our B_Spec func (b *B_Spec) ConvertSpecTo(destination genruntime.ConvertibleSpec) error { - dst, ok := destination.(*v20200101s.B_Spec) + dst, ok := destination.(*storage.B_Spec) if ok { // Populate destination from our instance return b.AssignProperties_To_B_Spec(dst) } // Convert to an intermediate form - dst = &v20200101s.B_Spec{} + dst = &storage.B_Spec{} err := b.AssignProperties_To_B_Spec(dst) if err != nil { return errors.Wrap(err, "initial step of conversion in ConvertSpecTo()") @@ -1312,11 +1314,12 @@ func (b *B_Spec) ConvertSpecTo(destination genruntime.ConvertibleSpec) error { } // AssignProperties_From_B_Spec populates our B_Spec from the provided source B_Spec -func (b *B_Spec) AssignProperties_From_B_Spec(source *v20200101s.B_Spec) error { +func (b *B_Spec) AssignProperties_From_B_Spec(source *storage.B_Spec) error { // APIVersion if source.APIVersion != nil { - b.APIVersion = B_APIVersion_Spec(*source.APIVersion) + apiVersion := *source.APIVersion + b.APIVersion = genruntime.ToEnum(apiVersion, b_APIVersion_Spec_Values) } else { b.APIVersion = "" } @@ -1334,7 +1337,8 @@ func (b *B_Spec) AssignProperties_From_B_Spec(source *v20200101s.B_Spec) error { // Type if source.Type != nil { - b.Type = B_Type_Spec(*source.Type) + typeVar := *source.Type + b.Type = genruntime.ToEnum(typeVar, b_Type_Spec_Values) } else { b.Type = "" } @@ -1344,7 +1348,7 @@ func (b *B_Spec) AssignProperties_From_B_Spec(source *v20200101s.B_Spec) error { } // AssignProperties_To_B_Spec populates the provided destination B_Spec from our B_Spec -func (b *B_Spec) AssignProperties_To_B_Spec(destination *v20200101s.B_Spec) error { +func (b *B_Spec) AssignProperties_To_B_Spec(destination *storage.B_Spec) error { // Create a new property bag propertyBag := genruntime.NewPropertyBag() @@ -1414,7 +1418,7 @@ func (c *C_Spec) ConvertToARM(resolved genruntime.ConvertToARMResolvedDetails) ( if c == nil { return nil, nil } - result := &C_Spec{} + result := &arm.C_Spec{} // Set property "APIVersion": result.APIVersion = c.APIVersion @@ -1429,14 +1433,14 @@ func (c *C_Spec) ConvertToARM(resolved genruntime.ConvertToARMResolvedDetails) ( // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (c *C_Spec) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &v20200101a.C_Spec{} + return &arm.C_Spec{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (c *C_Spec) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(C_Spec) + typedInput, ok := armInput.(arm.C_Spec) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected C_Spec, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.C_Spec, got %T", armInput) } // Set property "APIVersion": @@ -1462,14 +1466,14 @@ var _ genruntime.ConvertibleSpec = &C_Spec{} // ConvertSpecFrom populates our C_Spec from the provided source func (c *C_Spec) ConvertSpecFrom(source genruntime.ConvertibleSpec) error { - src, ok := source.(*v20200101s.C_Spec) + src, ok := source.(*storage.C_Spec) if ok { // Populate our instance from source return c.AssignProperties_From_C_Spec(src) } // Convert to an intermediate form - src = &v20200101s.C_Spec{} + src = &storage.C_Spec{} err := src.ConvertSpecFrom(source) if err != nil { return errors.Wrap(err, "initial step of conversion in ConvertSpecFrom()") @@ -1486,14 +1490,14 @@ func (c *C_Spec) ConvertSpecFrom(source genruntime.ConvertibleSpec) error { // ConvertSpecTo populates the provided destination from our C_Spec func (c *C_Spec) ConvertSpecTo(destination genruntime.ConvertibleSpec) error { - dst, ok := destination.(*v20200101s.C_Spec) + dst, ok := destination.(*storage.C_Spec) if ok { // Populate destination from our instance return c.AssignProperties_To_C_Spec(dst) } // Convert to an intermediate form - dst = &v20200101s.C_Spec{} + dst = &storage.C_Spec{} err := c.AssignProperties_To_C_Spec(dst) if err != nil { return errors.Wrap(err, "initial step of conversion in ConvertSpecTo()") @@ -1509,11 +1513,12 @@ func (c *C_Spec) ConvertSpecTo(destination genruntime.ConvertibleSpec) error { } // AssignProperties_From_C_Spec populates our C_Spec from the provided source C_Spec -func (c *C_Spec) AssignProperties_From_C_Spec(source *v20200101s.C_Spec) error { +func (c *C_Spec) AssignProperties_From_C_Spec(source *storage.C_Spec) error { // APIVersion if source.APIVersion != nil { - c.APIVersion = C_APIVersion_Spec(*source.APIVersion) + apiVersion := *source.APIVersion + c.APIVersion = genruntime.ToEnum(apiVersion, c_APIVersion_Spec_Values) } else { c.APIVersion = "" } @@ -1531,7 +1536,8 @@ func (c *C_Spec) AssignProperties_From_C_Spec(source *v20200101s.C_Spec) error { // Type if source.Type != nil { - c.Type = C_Type_Spec(*source.Type) + typeVar := *source.Type + c.Type = genruntime.ToEnum(typeVar, c_Type_Spec_Values) } else { c.Type = "" } @@ -1541,7 +1547,7 @@ func (c *C_Spec) AssignProperties_From_C_Spec(source *v20200101s.C_Spec) error { } // AssignProperties_To_C_Spec populates the provided destination C_Spec from our C_Spec -func (c *C_Spec) AssignProperties_To_C_Spec(destination *v20200101s.C_Spec) error { +func (c *C_Spec) AssignProperties_To_C_Spec(destination *storage.C_Spec) error { // Create a new property bag propertyBag := genruntime.NewPropertyBag() @@ -1611,7 +1617,7 @@ func (d *D_Spec) ConvertToARM(resolved genruntime.ConvertToARMResolvedDetails) ( if d == nil { return nil, nil } - result := &D_Spec{} + result := &arm.D_Spec{} // Set property "APIVersion": result.APIVersion = d.APIVersion @@ -1626,14 +1632,14 @@ func (d *D_Spec) ConvertToARM(resolved genruntime.ConvertToARMResolvedDetails) ( // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (d *D_Spec) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &v20200101a.D_Spec{} + return &arm.D_Spec{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (d *D_Spec) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(D_Spec) + typedInput, ok := armInput.(arm.D_Spec) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected D_Spec, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.D_Spec, got %T", armInput) } // Set property "APIVersion": @@ -1659,14 +1665,14 @@ var _ genruntime.ConvertibleSpec = &D_Spec{} // ConvertSpecFrom populates our D_Spec from the provided source func (d *D_Spec) ConvertSpecFrom(source genruntime.ConvertibleSpec) error { - src, ok := source.(*v20200101s.D_Spec) + src, ok := source.(*storage.D_Spec) if ok { // Populate our instance from source return d.AssignProperties_From_D_Spec(src) } // Convert to an intermediate form - src = &v20200101s.D_Spec{} + src = &storage.D_Spec{} err := src.ConvertSpecFrom(source) if err != nil { return errors.Wrap(err, "initial step of conversion in ConvertSpecFrom()") @@ -1683,14 +1689,14 @@ func (d *D_Spec) ConvertSpecFrom(source genruntime.ConvertibleSpec) error { // ConvertSpecTo populates the provided destination from our D_Spec func (d *D_Spec) ConvertSpecTo(destination genruntime.ConvertibleSpec) error { - dst, ok := destination.(*v20200101s.D_Spec) + dst, ok := destination.(*storage.D_Spec) if ok { // Populate destination from our instance return d.AssignProperties_To_D_Spec(dst) } // Convert to an intermediate form - dst = &v20200101s.D_Spec{} + dst = &storage.D_Spec{} err := d.AssignProperties_To_D_Spec(dst) if err != nil { return errors.Wrap(err, "initial step of conversion in ConvertSpecTo()") @@ -1706,11 +1712,12 @@ func (d *D_Spec) ConvertSpecTo(destination genruntime.ConvertibleSpec) error { } // AssignProperties_From_D_Spec populates our D_Spec from the provided source D_Spec -func (d *D_Spec) AssignProperties_From_D_Spec(source *v20200101s.D_Spec) error { +func (d *D_Spec) AssignProperties_From_D_Spec(source *storage.D_Spec) error { // APIVersion if source.APIVersion != nil { - d.APIVersion = D_APIVersion_Spec(*source.APIVersion) + apiVersion := *source.APIVersion + d.APIVersion = genruntime.ToEnum(apiVersion, d_APIVersion_Spec_Values) } else { d.APIVersion = "" } @@ -1728,7 +1735,8 @@ func (d *D_Spec) AssignProperties_From_D_Spec(source *v20200101s.D_Spec) error { // Type if source.Type != nil { - d.Type = D_Type_Spec(*source.Type) + typeVar := *source.Type + d.Type = genruntime.ToEnum(typeVar, d_Type_Spec_Values) } else { d.Type = "" } @@ -1738,7 +1746,7 @@ func (d *D_Spec) AssignProperties_From_D_Spec(source *v20200101s.D_Spec) error { } // AssignProperties_To_D_Spec populates the provided destination D_Spec from our D_Spec -func (d *D_Spec) AssignProperties_To_D_Spec(destination *v20200101s.D_Spec) error { +func (d *D_Spec) AssignProperties_To_D_Spec(destination *storage.D_Spec) error { // Create a new property bag propertyBag := genruntime.NewPropertyBag() @@ -1788,41 +1796,81 @@ type A_APIVersion_Spec string const A_APIVersion_Spec_20200601 = A_APIVersion_Spec("2020-06-01") +// Mapping from string to A_APIVersion_Spec +var a_APIVersion_Spec_Values = map[string]A_APIVersion_Spec{ + "2020-06-01": A_APIVersion_Spec_20200601, +} + // +kubebuilder:validation:Enum={"Microsoft.Azure/A"} type A_Type_Spec string const A_Type_Spec_MicrosoftAzureA = A_Type_Spec("Microsoft.Azure/A") +// Mapping from string to A_Type_Spec +var a_Type_Spec_Values = map[string]A_Type_Spec{ + "microsoft.azure/a": A_Type_Spec_MicrosoftAzureA, +} + // +kubebuilder:validation:Enum={"2020-06-01"} type B_APIVersion_Spec string const B_APIVersion_Spec_20200601 = B_APIVersion_Spec("2020-06-01") +// Mapping from string to B_APIVersion_Spec +var b_APIVersion_Spec_Values = map[string]B_APIVersion_Spec{ + "2020-06-01": B_APIVersion_Spec_20200601, +} + // +kubebuilder:validation:Enum={"Microsoft.Azure/B"} type B_Type_Spec string const B_Type_Spec_MicrosoftAzureB = B_Type_Spec("Microsoft.Azure/B") +// Mapping from string to B_Type_Spec +var b_Type_Spec_Values = map[string]B_Type_Spec{ + "microsoft.azure/b": B_Type_Spec_MicrosoftAzureB, +} + // +kubebuilder:validation:Enum={"2020-06-01"} type C_APIVersion_Spec string const C_APIVersion_Spec_20200601 = C_APIVersion_Spec("2020-06-01") +// Mapping from string to C_APIVersion_Spec +var c_APIVersion_Spec_Values = map[string]C_APIVersion_Spec{ + "2020-06-01": C_APIVersion_Spec_20200601, +} + // +kubebuilder:validation:Enum={"Microsoft.Azure/C"} type C_Type_Spec string const C_Type_Spec_MicrosoftAzureC = C_Type_Spec("Microsoft.Azure/C") +// Mapping from string to C_Type_Spec +var c_Type_Spec_Values = map[string]C_Type_Spec{ + "microsoft.azure/c": C_Type_Spec_MicrosoftAzureC, +} + // +kubebuilder:validation:Enum={"2020-06-01"} type D_APIVersion_Spec string const D_APIVersion_Spec_20200601 = D_APIVersion_Spec("2020-06-01") +// Mapping from string to D_APIVersion_Spec +var d_APIVersion_Spec_Values = map[string]D_APIVersion_Spec{ + "2020-06-01": D_APIVersion_Spec_20200601, +} + // +kubebuilder:validation:Enum={"Microsoft.Azure/D"} type D_Type_Spec string const D_Type_Spec_MicrosoftAzureD = D_Type_Spec("Microsoft.Azure/D") +// Mapping from string to D_Type_Spec +var d_Type_Spec_Values = map[string]D_Type_Spec{ + "microsoft.azure/d": D_Type_Spec_MicrosoftAzureD, +} + func init() { SchemeBuilder.Register(&A{}, &AList{}, &B{}, &BList{}, &C{}, &CList{}, &D{}, &DList{}) } diff --git a/v2/tools/generator/internal/codegen/testdata/ArmResource/Arm_test_id_resource_reference_azure_v1api20200101.golden b/v2/tools/generator/internal/codegen/testdata/ArmResource/Arm_test_id_resource_reference_azure_v1api20200101.golden index 8e09b4a0a6..b11e810f3a 100644 --- a/v2/tools/generator/internal/codegen/testdata/ArmResource/Arm_test_id_resource_reference_azure_v1api20200101.golden +++ b/v2/tools/generator/internal/codegen/testdata/ArmResource/Arm_test_id_resource_reference_azure_v1api20200101.golden @@ -5,8 +5,8 @@ package v1api20200101 import ( "fmt" - v20200101a "github.com/Azure/azure-service-operator/testing/test/v1api20200101/arm" - v20200101s "github.com/Azure/azure-service-operator/testing/test/v1api20200101/storage" + arm "github.com/Azure/azure-service-operator/testing/test/v1api20200101/arm" + storage "github.com/Azure/azure-service-operator/testing/test/v1api20200101/storage" "github.com/Azure/azure-service-operator/v2/internal/reflecthelpers" "github.com/Azure/azure-service-operator/v2/pkg/genruntime" "github.com/Azure/azure-service-operator/v2/pkg/genruntime/conditions" @@ -46,7 +46,7 @@ var _ conversion.Convertible = &FakeResource{} // ConvertFrom populates our FakeResource from the provided hub FakeResource func (resource *FakeResource) ConvertFrom(hub conversion.Hub) error { - source, ok := hub.(*v20200101s.FakeResource) + source, ok := hub.(*storage.FakeResource) if !ok { return fmt.Errorf("expected test/v1api20200101/storage/FakeResource but received %T instead", hub) } @@ -56,7 +56,7 @@ func (resource *FakeResource) ConvertFrom(hub conversion.Hub) error { // ConvertTo populates the provided hub FakeResource from our FakeResource func (resource *FakeResource) ConvertTo(hub conversion.Hub) error { - destination, ok := hub.(*v20200101s.FakeResource) + destination, ok := hub.(*storage.FakeResource) if !ok { return fmt.Errorf("expected test/v1api20200101/storage/FakeResource but received %T instead", hub) } @@ -211,7 +211,7 @@ func (resource *FakeResource) validateWriteOnceProperties(old runtime.Object) (a } // AssignProperties_From_FakeResource populates our FakeResource from the provided source FakeResource -func (resource *FakeResource) AssignProperties_From_FakeResource(source *v20200101s.FakeResource) error { +func (resource *FakeResource) AssignProperties_From_FakeResource(source *storage.FakeResource) error { // ObjectMeta resource.ObjectMeta = *source.ObjectMeta.DeepCopy() @@ -229,13 +229,13 @@ func (resource *FakeResource) AssignProperties_From_FakeResource(source *v202001 } // AssignProperties_To_FakeResource populates the provided destination FakeResource from our FakeResource -func (resource *FakeResource) AssignProperties_To_FakeResource(destination *v20200101s.FakeResource) error { +func (resource *FakeResource) AssignProperties_To_FakeResource(destination *storage.FakeResource) error { // ObjectMeta destination.ObjectMeta = *resource.ObjectMeta.DeepCopy() // Spec - var spec v20200101s.FakeResource_Spec + var spec storage.FakeResource_Spec err := resource.Spec.AssignProperties_To_FakeResource_Spec(&spec) if err != nil { return errors.Wrap(err, "calling AssignProperties_To_FakeResource_Spec() to populate field Spec") @@ -296,7 +296,7 @@ func (resource *FakeResource_Spec) ConvertToARM(resolved genruntime.ConvertToARM if resource == nil { return nil, nil } - result := &FakeResource_Spec{} + result := &arm.FakeResource_Spec{} // Set property "APIVersion": result.APIVersion = resource.APIVersion @@ -310,7 +310,7 @@ func (resource *FakeResource_Spec) ConvertToARM(resolved genruntime.ConvertToARM if err != nil { return nil, err } - properties := *properties_ARM.(*v20200101a.FakeResourceProperties) + properties := *properties_ARM.(*arm.FakeResourceProperties) result.Properties = &properties } @@ -321,14 +321,14 @@ func (resource *FakeResource_Spec) ConvertToARM(resolved genruntime.ConvertToARM // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (resource *FakeResource_Spec) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &v20200101a.FakeResource_Spec{} + return &arm.FakeResource_Spec{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (resource *FakeResource_Spec) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(FakeResource_Spec) + typedInput, ok := armInput.(arm.FakeResource_Spec) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected FakeResource_Spec, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.FakeResource_Spec, got %T", armInput) } // Set property "APIVersion": @@ -365,14 +365,14 @@ var _ genruntime.ConvertibleSpec = &FakeResource_Spec{} // ConvertSpecFrom populates our FakeResource_Spec from the provided source func (resource *FakeResource_Spec) ConvertSpecFrom(source genruntime.ConvertibleSpec) error { - src, ok := source.(*v20200101s.FakeResource_Spec) + src, ok := source.(*storage.FakeResource_Spec) if ok { // Populate our instance from source return resource.AssignProperties_From_FakeResource_Spec(src) } // Convert to an intermediate form - src = &v20200101s.FakeResource_Spec{} + src = &storage.FakeResource_Spec{} err := src.ConvertSpecFrom(source) if err != nil { return errors.Wrap(err, "initial step of conversion in ConvertSpecFrom()") @@ -389,14 +389,14 @@ func (resource *FakeResource_Spec) ConvertSpecFrom(source genruntime.Convertible // ConvertSpecTo populates the provided destination from our FakeResource_Spec func (resource *FakeResource_Spec) ConvertSpecTo(destination genruntime.ConvertibleSpec) error { - dst, ok := destination.(*v20200101s.FakeResource_Spec) + dst, ok := destination.(*storage.FakeResource_Spec) if ok { // Populate destination from our instance return resource.AssignProperties_To_FakeResource_Spec(dst) } // Convert to an intermediate form - dst = &v20200101s.FakeResource_Spec{} + dst = &storage.FakeResource_Spec{} err := resource.AssignProperties_To_FakeResource_Spec(dst) if err != nil { return errors.Wrap(err, "initial step of conversion in ConvertSpecTo()") @@ -412,11 +412,12 @@ func (resource *FakeResource_Spec) ConvertSpecTo(destination genruntime.Converti } // AssignProperties_From_FakeResource_Spec populates our FakeResource_Spec from the provided source FakeResource_Spec -func (resource *FakeResource_Spec) AssignProperties_From_FakeResource_Spec(source *v20200101s.FakeResource_Spec) error { +func (resource *FakeResource_Spec) AssignProperties_From_FakeResource_Spec(source *storage.FakeResource_Spec) error { // APIVersion if source.APIVersion != nil { - resource.APIVersion = FakeResource_APIVersion_Spec(*source.APIVersion) + apiVersion := *source.APIVersion + resource.APIVersion = genruntime.ToEnum(apiVersion, fakeResource_APIVersion_Spec_Values) } else { resource.APIVersion = "" } @@ -446,7 +447,8 @@ func (resource *FakeResource_Spec) AssignProperties_From_FakeResource_Spec(sourc // Type if source.Type != nil { - resource.Type = FakeResource_Type_Spec(*source.Type) + typeVar := *source.Type + resource.Type = genruntime.ToEnum(typeVar, fakeResource_Type_Spec_Values) } else { resource.Type = "" } @@ -456,7 +458,7 @@ func (resource *FakeResource_Spec) AssignProperties_From_FakeResource_Spec(sourc } // AssignProperties_To_FakeResource_Spec populates the provided destination FakeResource_Spec from our FakeResource_Spec -func (resource *FakeResource_Spec) AssignProperties_To_FakeResource_Spec(destination *v20200101s.FakeResource_Spec) error { +func (resource *FakeResource_Spec) AssignProperties_To_FakeResource_Spec(destination *storage.FakeResource_Spec) error { // Create a new property bag propertyBag := genruntime.NewPropertyBag() @@ -480,7 +482,7 @@ func (resource *FakeResource_Spec) AssignProperties_To_FakeResource_Spec(destina // Properties if resource.Properties != nil { - var property v20200101s.FakeResourceProperties + var property storage.FakeResourceProperties err := resource.Properties.AssignProperties_To_FakeResourceProperties(&property) if err != nil { return errors.Wrap(err, "calling AssignProperties_To_FakeResourceProperties() to populate field Properties") @@ -518,11 +520,21 @@ type FakeResource_APIVersion_Spec string const FakeResource_APIVersion_Spec_20200601 = FakeResource_APIVersion_Spec("2020-06-01") +// Mapping from string to FakeResource_APIVersion_Spec +var fakeResource_APIVersion_Spec_Values = map[string]FakeResource_APIVersion_Spec{ + "2020-06-01": FakeResource_APIVersion_Spec_20200601, +} + // +kubebuilder:validation:Enum={"Microsoft.Azure/FakeResource"} type FakeResource_Type_Spec string const FakeResource_Type_Spec_MicrosoftAzureFakeResource = FakeResource_Type_Spec("Microsoft.Azure/FakeResource") +// Mapping from string to FakeResource_Type_Spec +var fakeResource_Type_Spec_Values = map[string]FakeResource_Type_Spec{ + "microsoft.azure/fakeresource": FakeResource_Type_Spec_MicrosoftAzureFakeResource, +} + // Generated from: https://test.test/schemas/2020-01-01/test.json#/definitions/FakeResourceProperties type FakeResourceProperties struct { // NsgMapReferences: A map of NSG IDs of the form @@ -549,7 +561,7 @@ func (properties *FakeResourceProperties) ConvertToARM(resolved genruntime.Conve if properties == nil { return nil, nil } - result := &FakeResourceProperties{} + result := &arm.FakeResourceProperties{} // Set property "Id": if properties.Reference != nil { @@ -596,14 +608,14 @@ func (properties *FakeResourceProperties) ConvertToARM(resolved genruntime.Conve // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (properties *FakeResourceProperties) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &v20200101a.FakeResourceProperties{} + return &arm.FakeResourceProperties{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (properties *FakeResourceProperties) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - _, ok := armInput.(FakeResourceProperties) + _, ok := armInput.(arm.FakeResourceProperties) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected FakeResourceProperties, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.FakeResourceProperties, got %T", armInput) } // no assignment for property "NsgMapReferences" @@ -619,7 +631,7 @@ func (properties *FakeResourceProperties) PopulateFromARM(owner genruntime.Arbit } // AssignProperties_From_FakeResourceProperties populates our FakeResourceProperties from the provided source FakeResourceProperties -func (properties *FakeResourceProperties) AssignProperties_From_FakeResourceProperties(source *v20200101s.FakeResourceProperties) error { +func (properties *FakeResourceProperties) AssignProperties_From_FakeResourceProperties(source *storage.FakeResourceProperties) error { // NsgMapReferences if source.NsgMapReferences != nil { @@ -668,7 +680,7 @@ func (properties *FakeResourceProperties) AssignProperties_From_FakeResourceProp } // AssignProperties_To_FakeResourceProperties populates the provided destination FakeResourceProperties from our FakeResourceProperties -func (properties *FakeResourceProperties) AssignProperties_To_FakeResourceProperties(destination *v20200101s.FakeResourceProperties) error { +func (properties *FakeResourceProperties) AssignProperties_To_FakeResourceProperties(destination *storage.FakeResourceProperties) error { // Create a new property bag propertyBag := genruntime.NewPropertyBag() diff --git a/v2/tools/generator/internal/codegen/testdata/ArmResource/Arm_test_required_and_optional_resource_references_azure_v1api20200101.golden b/v2/tools/generator/internal/codegen/testdata/ArmResource/Arm_test_required_and_optional_resource_references_azure_v1api20200101.golden index 4ddd74485f..784a5df5c5 100644 --- a/v2/tools/generator/internal/codegen/testdata/ArmResource/Arm_test_required_and_optional_resource_references_azure_v1api20200101.golden +++ b/v2/tools/generator/internal/codegen/testdata/ArmResource/Arm_test_required_and_optional_resource_references_azure_v1api20200101.golden @@ -5,8 +5,8 @@ package v1api20200101 import ( "fmt" - v20200101a "github.com/Azure/azure-service-operator/testing/test/v1api20200101/arm" - v20200101s "github.com/Azure/azure-service-operator/testing/test/v1api20200101/storage" + arm "github.com/Azure/azure-service-operator/testing/test/v1api20200101/arm" + storage "github.com/Azure/azure-service-operator/testing/test/v1api20200101/storage" "github.com/Azure/azure-service-operator/v2/internal/reflecthelpers" "github.com/Azure/azure-service-operator/v2/pkg/genruntime" "github.com/Azure/azure-service-operator/v2/pkg/genruntime/conditions" @@ -46,7 +46,7 @@ var _ conversion.Convertible = &FakeResource{} // ConvertFrom populates our FakeResource from the provided hub FakeResource func (resource *FakeResource) ConvertFrom(hub conversion.Hub) error { - source, ok := hub.(*v20200101s.FakeResource) + source, ok := hub.(*storage.FakeResource) if !ok { return fmt.Errorf("expected test/v1api20200101/storage/FakeResource but received %T instead", hub) } @@ -56,7 +56,7 @@ func (resource *FakeResource) ConvertFrom(hub conversion.Hub) error { // ConvertTo populates the provided hub FakeResource from our FakeResource func (resource *FakeResource) ConvertTo(hub conversion.Hub) error { - destination, ok := hub.(*v20200101s.FakeResource) + destination, ok := hub.(*storage.FakeResource) if !ok { return fmt.Errorf("expected test/v1api20200101/storage/FakeResource but received %T instead", hub) } @@ -211,7 +211,7 @@ func (resource *FakeResource) validateWriteOnceProperties(old runtime.Object) (a } // AssignProperties_From_FakeResource populates our FakeResource from the provided source FakeResource -func (resource *FakeResource) AssignProperties_From_FakeResource(source *v20200101s.FakeResource) error { +func (resource *FakeResource) AssignProperties_From_FakeResource(source *storage.FakeResource) error { // ObjectMeta resource.ObjectMeta = *source.ObjectMeta.DeepCopy() @@ -229,13 +229,13 @@ func (resource *FakeResource) AssignProperties_From_FakeResource(source *v202001 } // AssignProperties_To_FakeResource populates the provided destination FakeResource from our FakeResource -func (resource *FakeResource) AssignProperties_To_FakeResource(destination *v20200101s.FakeResource) error { +func (resource *FakeResource) AssignProperties_To_FakeResource(destination *storage.FakeResource) error { // ObjectMeta destination.ObjectMeta = *resource.ObjectMeta.DeepCopy() // Spec - var spec v20200101s.FakeResource_Spec + var spec storage.FakeResource_Spec err := resource.Spec.AssignProperties_To_FakeResource_Spec(&spec) if err != nil { return errors.Wrap(err, "calling AssignProperties_To_FakeResource_Spec() to populate field Spec") @@ -296,7 +296,7 @@ func (resource *FakeResource_Spec) ConvertToARM(resolved genruntime.ConvertToARM if resource == nil { return nil, nil } - result := &FakeResource_Spec{} + result := &arm.FakeResource_Spec{} // Set property "APIVersion": result.APIVersion = resource.APIVersion @@ -310,7 +310,7 @@ func (resource *FakeResource_Spec) ConvertToARM(resolved genruntime.ConvertToARM if err != nil { return nil, err } - properties := *properties_ARM.(*v20200101a.FakeResourceProperties) + properties := *properties_ARM.(*arm.FakeResourceProperties) result.Properties = &properties } @@ -321,14 +321,14 @@ func (resource *FakeResource_Spec) ConvertToARM(resolved genruntime.ConvertToARM // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (resource *FakeResource_Spec) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &v20200101a.FakeResource_Spec{} + return &arm.FakeResource_Spec{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (resource *FakeResource_Spec) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(FakeResource_Spec) + typedInput, ok := armInput.(arm.FakeResource_Spec) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected FakeResource_Spec, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.FakeResource_Spec, got %T", armInput) } // Set property "APIVersion": @@ -365,14 +365,14 @@ var _ genruntime.ConvertibleSpec = &FakeResource_Spec{} // ConvertSpecFrom populates our FakeResource_Spec from the provided source func (resource *FakeResource_Spec) ConvertSpecFrom(source genruntime.ConvertibleSpec) error { - src, ok := source.(*v20200101s.FakeResource_Spec) + src, ok := source.(*storage.FakeResource_Spec) if ok { // Populate our instance from source return resource.AssignProperties_From_FakeResource_Spec(src) } // Convert to an intermediate form - src = &v20200101s.FakeResource_Spec{} + src = &storage.FakeResource_Spec{} err := src.ConvertSpecFrom(source) if err != nil { return errors.Wrap(err, "initial step of conversion in ConvertSpecFrom()") @@ -389,14 +389,14 @@ func (resource *FakeResource_Spec) ConvertSpecFrom(source genruntime.Convertible // ConvertSpecTo populates the provided destination from our FakeResource_Spec func (resource *FakeResource_Spec) ConvertSpecTo(destination genruntime.ConvertibleSpec) error { - dst, ok := destination.(*v20200101s.FakeResource_Spec) + dst, ok := destination.(*storage.FakeResource_Spec) if ok { // Populate destination from our instance return resource.AssignProperties_To_FakeResource_Spec(dst) } // Convert to an intermediate form - dst = &v20200101s.FakeResource_Spec{} + dst = &storage.FakeResource_Spec{} err := resource.AssignProperties_To_FakeResource_Spec(dst) if err != nil { return errors.Wrap(err, "initial step of conversion in ConvertSpecTo()") @@ -412,11 +412,12 @@ func (resource *FakeResource_Spec) ConvertSpecTo(destination genruntime.Converti } // AssignProperties_From_FakeResource_Spec populates our FakeResource_Spec from the provided source FakeResource_Spec -func (resource *FakeResource_Spec) AssignProperties_From_FakeResource_Spec(source *v20200101s.FakeResource_Spec) error { +func (resource *FakeResource_Spec) AssignProperties_From_FakeResource_Spec(source *storage.FakeResource_Spec) error { // APIVersion if source.APIVersion != nil { - resource.APIVersion = FakeResource_APIVersion_Spec(*source.APIVersion) + apiVersion := *source.APIVersion + resource.APIVersion = genruntime.ToEnum(apiVersion, fakeResource_APIVersion_Spec_Values) } else { resource.APIVersion = "" } @@ -446,7 +447,8 @@ func (resource *FakeResource_Spec) AssignProperties_From_FakeResource_Spec(sourc // Type if source.Type != nil { - resource.Type = FakeResource_Type_Spec(*source.Type) + typeVar := *source.Type + resource.Type = genruntime.ToEnum(typeVar, fakeResource_Type_Spec_Values) } else { resource.Type = "" } @@ -456,7 +458,7 @@ func (resource *FakeResource_Spec) AssignProperties_From_FakeResource_Spec(sourc } // AssignProperties_To_FakeResource_Spec populates the provided destination FakeResource_Spec from our FakeResource_Spec -func (resource *FakeResource_Spec) AssignProperties_To_FakeResource_Spec(destination *v20200101s.FakeResource_Spec) error { +func (resource *FakeResource_Spec) AssignProperties_To_FakeResource_Spec(destination *storage.FakeResource_Spec) error { // Create a new property bag propertyBag := genruntime.NewPropertyBag() @@ -480,7 +482,7 @@ func (resource *FakeResource_Spec) AssignProperties_To_FakeResource_Spec(destina // Properties if resource.Properties != nil { - var property v20200101s.FakeResourceProperties + var property storage.FakeResourceProperties err := resource.Properties.AssignProperties_To_FakeResourceProperties(&property) if err != nil { return errors.Wrap(err, "calling AssignProperties_To_FakeResourceProperties() to populate field Properties") @@ -518,11 +520,21 @@ type FakeResource_APIVersion_Spec string const FakeResource_APIVersion_Spec_20200601 = FakeResource_APIVersion_Spec("2020-06-01") +// Mapping from string to FakeResource_APIVersion_Spec +var fakeResource_APIVersion_Spec_Values = map[string]FakeResource_APIVersion_Spec{ + "2020-06-01": FakeResource_APIVersion_Spec_20200601, +} + // +kubebuilder:validation:Enum={"Microsoft.Azure/FakeResource"} type FakeResource_Type_Spec string const FakeResource_Type_Spec_MicrosoftAzureFakeResource = FakeResource_Type_Spec("Microsoft.Azure/FakeResource") +// Mapping from string to FakeResource_Type_Spec +var fakeResource_Type_Spec_Values = map[string]FakeResource_Type_Spec{ + "microsoft.azure/fakeresource": FakeResource_Type_Spec_MicrosoftAzureFakeResource, +} + // Generated from: https://test.test/schemas/2020-01-01/test.json#/definitions/FakeResourceProperties type FakeResourceProperties struct { // OptionalVNetReference: A string of the form @@ -542,7 +554,7 @@ func (properties *FakeResourceProperties) ConvertToARM(resolved genruntime.Conve if properties == nil { return nil, nil } - result := &FakeResourceProperties{} + result := &arm.FakeResourceProperties{} // Set property "OptionalVNet": if properties.OptionalVNetReference != nil { @@ -568,14 +580,14 @@ func (properties *FakeResourceProperties) ConvertToARM(resolved genruntime.Conve // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (properties *FakeResourceProperties) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &v20200101a.FakeResourceProperties{} + return &arm.FakeResourceProperties{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (properties *FakeResourceProperties) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - _, ok := armInput.(FakeResourceProperties) + _, ok := armInput.(arm.FakeResourceProperties) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected FakeResourceProperties, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.FakeResourceProperties, got %T", armInput) } // no assignment for property "OptionalVNetReference" @@ -587,7 +599,7 @@ func (properties *FakeResourceProperties) PopulateFromARM(owner genruntime.Arbit } // AssignProperties_From_FakeResourceProperties populates our FakeResourceProperties from the provided source FakeResourceProperties -func (properties *FakeResourceProperties) AssignProperties_From_FakeResourceProperties(source *v20200101s.FakeResourceProperties) error { +func (properties *FakeResourceProperties) AssignProperties_From_FakeResourceProperties(source *storage.FakeResourceProperties) error { // OptionalVNetReference if source.OptionalVNetReference != nil { @@ -610,7 +622,7 @@ func (properties *FakeResourceProperties) AssignProperties_From_FakeResourceProp } // AssignProperties_To_FakeResourceProperties populates the provided destination FakeResourceProperties from our FakeResourceProperties -func (properties *FakeResourceProperties) AssignProperties_To_FakeResourceProperties(destination *v20200101s.FakeResourceProperties) error { +func (properties *FakeResourceProperties) AssignProperties_To_FakeResourceProperties(destination *storage.FakeResourceProperties) error { // Create a new property bag propertyBag := genruntime.NewPropertyBag() diff --git a/v2/tools/generator/internal/codegen/testdata/ArmResource/Arm_test_simple_resource_array_properties_azure_v1api20200101.golden b/v2/tools/generator/internal/codegen/testdata/ArmResource/Arm_test_simple_resource_array_properties_azure_v1api20200101.golden index 7ae9961706..156e580c95 100644 --- a/v2/tools/generator/internal/codegen/testdata/ArmResource/Arm_test_simple_resource_array_properties_azure_v1api20200101.golden +++ b/v2/tools/generator/internal/codegen/testdata/ArmResource/Arm_test_simple_resource_array_properties_azure_v1api20200101.golden @@ -5,8 +5,8 @@ package v1api20200101 import ( "fmt" - v20200101a "github.com/Azure/azure-service-operator/testing/test/v1api20200101/arm" - v20200101s "github.com/Azure/azure-service-operator/testing/test/v1api20200101/storage" + arm "github.com/Azure/azure-service-operator/testing/test/v1api20200101/arm" + storage "github.com/Azure/azure-service-operator/testing/test/v1api20200101/storage" "github.com/Azure/azure-service-operator/v2/internal/reflecthelpers" "github.com/Azure/azure-service-operator/v2/pkg/genruntime" "github.com/Azure/azure-service-operator/v2/pkg/genruntime/conditions" @@ -46,7 +46,7 @@ var _ conversion.Convertible = &FakeResource{} // ConvertFrom populates our FakeResource from the provided hub FakeResource func (resource *FakeResource) ConvertFrom(hub conversion.Hub) error { - source, ok := hub.(*v20200101s.FakeResource) + source, ok := hub.(*storage.FakeResource) if !ok { return fmt.Errorf("expected test/v1api20200101/storage/FakeResource but received %T instead", hub) } @@ -56,7 +56,7 @@ func (resource *FakeResource) ConvertFrom(hub conversion.Hub) error { // ConvertTo populates the provided hub FakeResource from our FakeResource func (resource *FakeResource) ConvertTo(hub conversion.Hub) error { - destination, ok := hub.(*v20200101s.FakeResource) + destination, ok := hub.(*storage.FakeResource) if !ok { return fmt.Errorf("expected test/v1api20200101/storage/FakeResource but received %T instead", hub) } @@ -211,7 +211,7 @@ func (resource *FakeResource) validateWriteOnceProperties(old runtime.Object) (a } // AssignProperties_From_FakeResource populates our FakeResource from the provided source FakeResource -func (resource *FakeResource) AssignProperties_From_FakeResource(source *v20200101s.FakeResource) error { +func (resource *FakeResource) AssignProperties_From_FakeResource(source *storage.FakeResource) error { // ObjectMeta resource.ObjectMeta = *source.ObjectMeta.DeepCopy() @@ -229,13 +229,13 @@ func (resource *FakeResource) AssignProperties_From_FakeResource(source *v202001 } // AssignProperties_To_FakeResource populates the provided destination FakeResource from our FakeResource -func (resource *FakeResource) AssignProperties_To_FakeResource(destination *v20200101s.FakeResource) error { +func (resource *FakeResource) AssignProperties_To_FakeResource(destination *storage.FakeResource) error { // ObjectMeta destination.ObjectMeta = *resource.ObjectMeta.DeepCopy() // Spec - var spec v20200101s.FakeResource_Spec + var spec storage.FakeResource_Spec err := resource.Spec.AssignProperties_To_FakeResource_Spec(&spec) if err != nil { return errors.Wrap(err, "calling AssignProperties_To_FakeResource_Spec() to populate field Spec") @@ -300,7 +300,7 @@ func (resource *FakeResource_Spec) ConvertToARM(resolved genruntime.ConvertToARM if resource == nil { return nil, nil } - result := &FakeResource_Spec{} + result := &arm.FakeResource_Spec{} // Set property "APIVersion": result.APIVersion = resource.APIVersion @@ -311,33 +311,33 @@ func (resource *FakeResource_Spec) ConvertToARM(resolved genruntime.ConvertToARM if err != nil { return nil, err } - result.ArrayFoo = append(result.ArrayFoo, *item_ARM.(*v20200101a.Foo)) + result.ArrayFoo = append(result.ArrayFoo, *item_ARM.(*arm.Foo)) } // Set property "ArrayOfArrays": for _, item := range resource.ArrayOfArrays { - var itemTemp []v20200101a.Foo + var itemTemp []arm.Foo for _, item1 := range item { item1_ARM, err := item1.ConvertToARM(resolved) if err != nil { return nil, err } - itemTemp = append(itemTemp, *item1_ARM.(*v20200101a.Foo)) + itemTemp = append(itemTemp, *item1_ARM.(*arm.Foo)) } result.ArrayOfArrays = append(result.ArrayOfArrays, itemTemp) } // Set property "ArrayOfArraysOfArrays": for _, item := range resource.ArrayOfArraysOfArrays { - var itemTemp [][]v20200101a.Foo + var itemTemp [][]arm.Foo for _, item1 := range item { - var item1Temp []v20200101a.Foo + var item1Temp []arm.Foo for _, item2 := range item1 { item2_ARM, err := item2.ConvertToARM(resolved) if err != nil { return nil, err } - item1Temp = append(item1Temp, *item2_ARM.(*v20200101a.Foo)) + item1Temp = append(item1Temp, *item2_ARM.(*arm.Foo)) } itemTemp = append(itemTemp, item1Temp) } @@ -352,13 +352,13 @@ func (resource *FakeResource_Spec) ConvertToARM(resolved genruntime.ConvertToARM // Set property "ArrayOfMaps": for _, item := range resource.ArrayOfMaps { if item != nil { - itemTemp := make(map[string]v20200101a.Foo, len(item)) + itemTemp := make(map[string]arm.Foo, len(item)) for key, value := range item { value_ARM, err := value.ConvertToARM(resolved) if err != nil { return nil, err } - itemTemp[key] = *value_ARM.(*v20200101a.Foo) + itemTemp[key] = *value_ARM.(*arm.Foo) } result.ArrayOfMaps = append(result.ArrayOfMaps, itemTemp) } @@ -374,14 +374,14 @@ func (resource *FakeResource_Spec) ConvertToARM(resolved genruntime.ConvertToARM // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (resource *FakeResource_Spec) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &v20200101a.FakeResource_Spec{} + return &arm.FakeResource_Spec{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (resource *FakeResource_Spec) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(FakeResource_Spec) + typedInput, ok := armInput.(arm.FakeResource_Spec) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected FakeResource_Spec, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.FakeResource_Spec, got %T", armInput) } // Set property "APIVersion": @@ -470,14 +470,14 @@ var _ genruntime.ConvertibleSpec = &FakeResource_Spec{} // ConvertSpecFrom populates our FakeResource_Spec from the provided source func (resource *FakeResource_Spec) ConvertSpecFrom(source genruntime.ConvertibleSpec) error { - src, ok := source.(*v20200101s.FakeResource_Spec) + src, ok := source.(*storage.FakeResource_Spec) if ok { // Populate our instance from source return resource.AssignProperties_From_FakeResource_Spec(src) } // Convert to an intermediate form - src = &v20200101s.FakeResource_Spec{} + src = &storage.FakeResource_Spec{} err := src.ConvertSpecFrom(source) if err != nil { return errors.Wrap(err, "initial step of conversion in ConvertSpecFrom()") @@ -494,14 +494,14 @@ func (resource *FakeResource_Spec) ConvertSpecFrom(source genruntime.Convertible // ConvertSpecTo populates the provided destination from our FakeResource_Spec func (resource *FakeResource_Spec) ConvertSpecTo(destination genruntime.ConvertibleSpec) error { - dst, ok := destination.(*v20200101s.FakeResource_Spec) + dst, ok := destination.(*storage.FakeResource_Spec) if ok { // Populate destination from our instance return resource.AssignProperties_To_FakeResource_Spec(dst) } // Convert to an intermediate form - dst = &v20200101s.FakeResource_Spec{} + dst = &storage.FakeResource_Spec{} err := resource.AssignProperties_To_FakeResource_Spec(dst) if err != nil { return errors.Wrap(err, "initial step of conversion in ConvertSpecTo()") @@ -517,11 +517,12 @@ func (resource *FakeResource_Spec) ConvertSpecTo(destination genruntime.Converti } // AssignProperties_From_FakeResource_Spec populates our FakeResource_Spec from the provided source FakeResource_Spec -func (resource *FakeResource_Spec) AssignProperties_From_FakeResource_Spec(source *v20200101s.FakeResource_Spec) error { +func (resource *FakeResource_Spec) AssignProperties_From_FakeResource_Spec(source *storage.FakeResource_Spec) error { // APIVersion if source.APIVersion != nil { - resource.APIVersion = FakeResource_APIVersion_Spec(*source.APIVersion) + apiVersion := *source.APIVersion + resource.APIVersion = genruntime.ToEnum(apiVersion, fakeResource_APIVersion_Spec_Values) } else { resource.APIVersion = "" } @@ -616,7 +617,7 @@ func (resource *FakeResource_Spec) AssignProperties_From_FakeResource_Spec(sourc for arrayOfEnumIndex, arrayOfEnumItem := range source.ArrayOfEnums { // Shadow the loop variable to avoid aliasing arrayOfEnumItem := arrayOfEnumItem - arrayOfEnumList[arrayOfEnumIndex] = Color(arrayOfEnumItem) + arrayOfEnumList[arrayOfEnumIndex] = genruntime.ToEnum(arrayOfEnumItem, color_Values) } resource.ArrayOfEnums = arrayOfEnumList } else { @@ -664,7 +665,8 @@ func (resource *FakeResource_Spec) AssignProperties_From_FakeResource_Spec(sourc // Type if source.Type != nil { - resource.Type = FakeResource_Type_Spec(*source.Type) + typeVar := *source.Type + resource.Type = genruntime.ToEnum(typeVar, fakeResource_Type_Spec_Values) } else { resource.Type = "" } @@ -674,7 +676,7 @@ func (resource *FakeResource_Spec) AssignProperties_From_FakeResource_Spec(sourc } // AssignProperties_To_FakeResource_Spec populates the provided destination FakeResource_Spec from our FakeResource_Spec -func (resource *FakeResource_Spec) AssignProperties_To_FakeResource_Spec(destination *v20200101s.FakeResource_Spec) error { +func (resource *FakeResource_Spec) AssignProperties_To_FakeResource_Spec(destination *storage.FakeResource_Spec) error { // Create a new property bag propertyBag := genruntime.NewPropertyBag() @@ -684,11 +686,11 @@ func (resource *FakeResource_Spec) AssignProperties_To_FakeResource_Spec(destina // ArrayFoo if resource.ArrayFoo != nil { - arrayFooList := make([]v20200101s.Foo, len(resource.ArrayFoo)) + arrayFooList := make([]storage.Foo, len(resource.ArrayFoo)) for arrayFooIndex, arrayFooItem := range resource.ArrayFoo { // Shadow the loop variable to avoid aliasing arrayFooItem := arrayFooItem - var arrayFoo v20200101s.Foo + var arrayFoo storage.Foo err := arrayFooItem.AssignProperties_To_Foo(&arrayFoo) if err != nil { return errors.Wrap(err, "calling AssignProperties_To_Foo() to populate field ArrayFoo") @@ -702,16 +704,16 @@ func (resource *FakeResource_Spec) AssignProperties_To_FakeResource_Spec(destina // ArrayOfArrays if resource.ArrayOfArrays != nil { - arrayOfArrayList := make([][]v20200101s.Foo, len(resource.ArrayOfArrays)) + arrayOfArrayList := make([][]storage.Foo, len(resource.ArrayOfArrays)) for arrayOfArrayIndex, arrayOfArrayItem := range resource.ArrayOfArrays { // Shadow the loop variable to avoid aliasing arrayOfArrayItem := arrayOfArrayItem if arrayOfArrayItem != nil { - arrayOfArrayList1 := make([]v20200101s.Foo, len(arrayOfArrayItem)) + arrayOfArrayList1 := make([]storage.Foo, len(arrayOfArrayItem)) for arrayOfArrayIndex1, arrayOfArrayItem1 := range arrayOfArrayItem { // Shadow the loop variable to avoid aliasing arrayOfArrayItem1 := arrayOfArrayItem1 - var arrayOfArray v20200101s.Foo + var arrayOfArray storage.Foo err := arrayOfArrayItem1.AssignProperties_To_Foo(&arrayOfArray) if err != nil { return errors.Wrap(err, "calling AssignProperties_To_Foo() to populate field ArrayOfArrays") @@ -730,21 +732,21 @@ func (resource *FakeResource_Spec) AssignProperties_To_FakeResource_Spec(destina // ArrayOfArraysOfArrays if resource.ArrayOfArraysOfArrays != nil { - arrayOfArraysOfArrayList := make([][][]v20200101s.Foo, len(resource.ArrayOfArraysOfArrays)) + arrayOfArraysOfArrayList := make([][][]storage.Foo, len(resource.ArrayOfArraysOfArrays)) for arrayOfArraysOfArrayIndex, arrayOfArraysOfArrayItem := range resource.ArrayOfArraysOfArrays { // Shadow the loop variable to avoid aliasing arrayOfArraysOfArrayItem := arrayOfArraysOfArrayItem if arrayOfArraysOfArrayItem != nil { - arrayOfArraysOfArrayList1 := make([][]v20200101s.Foo, len(arrayOfArraysOfArrayItem)) + arrayOfArraysOfArrayList1 := make([][]storage.Foo, len(arrayOfArraysOfArrayItem)) for arrayOfArraysOfArrayIndex1, arrayOfArraysOfArrayItem1 := range arrayOfArraysOfArrayItem { // Shadow the loop variable to avoid aliasing arrayOfArraysOfArrayItem1 := arrayOfArraysOfArrayItem1 if arrayOfArraysOfArrayItem1 != nil { - arrayOfArraysOfArrayList2 := make([]v20200101s.Foo, len(arrayOfArraysOfArrayItem1)) + arrayOfArraysOfArrayList2 := make([]storage.Foo, len(arrayOfArraysOfArrayItem1)) for arrayOfArraysOfArrayIndex2, arrayOfArraysOfArrayItem2 := range arrayOfArraysOfArrayItem1 { // Shadow the loop variable to avoid aliasing arrayOfArraysOfArrayItem2 := arrayOfArraysOfArrayItem2 - var arrayOfArraysOfArray v20200101s.Foo + var arrayOfArraysOfArray storage.Foo err := arrayOfArraysOfArrayItem2.AssignProperties_To_Foo(&arrayOfArraysOfArray) if err != nil { return errors.Wrap(err, "calling AssignProperties_To_Foo() to populate field ArrayOfArraysOfArrays") @@ -781,16 +783,16 @@ func (resource *FakeResource_Spec) AssignProperties_To_FakeResource_Spec(destina // ArrayOfMaps if resource.ArrayOfMaps != nil { - arrayOfMapList := make([]map[string]v20200101s.Foo, len(resource.ArrayOfMaps)) + arrayOfMapList := make([]map[string]storage.Foo, len(resource.ArrayOfMaps)) for arrayOfMapIndex, arrayOfMapItem := range resource.ArrayOfMaps { // Shadow the loop variable to avoid aliasing arrayOfMapItem := arrayOfMapItem if arrayOfMapItem != nil { - arrayOfMap := make(map[string]v20200101s.Foo, len(arrayOfMapItem)) + arrayOfMap := make(map[string]storage.Foo, len(arrayOfMapItem)) for arrayOfMapKey, arrayOfMapValue := range arrayOfMapItem { // Shadow the loop variable to avoid aliasing arrayOfMapValue := arrayOfMapValue - var arrayOfMapLocal v20200101s.Foo + var arrayOfMapLocal storage.Foo err := arrayOfMapValue.AssignProperties_To_Foo(&arrayOfMapLocal) if err != nil { return errors.Wrap(err, "calling AssignProperties_To_Foo() to populate field ArrayOfMaps") @@ -854,16 +856,33 @@ const ( Color_Red = Color("red") ) +// Mapping from string to Color +var color_Values = map[string]Color{ + "blue": Color_Blue, + "green": Color_Green, + "red": Color_Red, +} + // +kubebuilder:validation:Enum={"2020-06-01"} type FakeResource_APIVersion_Spec string const FakeResource_APIVersion_Spec_20200601 = FakeResource_APIVersion_Spec("2020-06-01") +// Mapping from string to FakeResource_APIVersion_Spec +var fakeResource_APIVersion_Spec_Values = map[string]FakeResource_APIVersion_Spec{ + "2020-06-01": FakeResource_APIVersion_Spec_20200601, +} + // +kubebuilder:validation:Enum={"Microsoft.Azure/FakeResource"} type FakeResource_Type_Spec string const FakeResource_Type_Spec_MicrosoftAzureFakeResource = FakeResource_Type_Spec("Microsoft.Azure/FakeResource") +// Mapping from string to FakeResource_Type_Spec +var fakeResource_Type_Spec_Values = map[string]FakeResource_Type_Spec{ + "microsoft.azure/fakeresource": FakeResource_Type_Spec_MicrosoftAzureFakeResource, +} + // Generated from: https://test.test/schemas/2020-01-01/test.json#/definitions/Foo type Foo struct { Name *string `json:"name,omitempty"` @@ -876,7 +895,7 @@ func (foo *Foo) ConvertToARM(resolved genruntime.ConvertToARMResolvedDetails) (i if foo == nil { return nil, nil } - result := &Foo{} + result := &arm.Foo{} // Set property "Name": if foo.Name != nil { @@ -888,14 +907,14 @@ func (foo *Foo) ConvertToARM(resolved genruntime.ConvertToARMResolvedDetails) (i // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (foo *Foo) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &v20200101a.Foo{} + return &arm.Foo{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (foo *Foo) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(Foo) + typedInput, ok := armInput.(arm.Foo) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected Foo, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.Foo, got %T", armInput) } // Set property "Name": @@ -909,7 +928,7 @@ func (foo *Foo) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInp } // AssignProperties_From_Foo populates our Foo from the provided source Foo -func (foo *Foo) AssignProperties_From_Foo(source *v20200101s.Foo) error { +func (foo *Foo) AssignProperties_From_Foo(source *storage.Foo) error { // Name foo.Name = genruntime.ClonePointerToString(source.Name) @@ -919,7 +938,7 @@ func (foo *Foo) AssignProperties_From_Foo(source *v20200101s.Foo) error { } // AssignProperties_To_Foo populates the provided destination Foo from our Foo -func (foo *Foo) AssignProperties_To_Foo(destination *v20200101s.Foo) error { +func (foo *Foo) AssignProperties_To_Foo(destination *storage.Foo) error { // Create a new property bag propertyBag := genruntime.NewPropertyBag() diff --git a/v2/tools/generator/internal/codegen/testdata/ArmResource/Arm_test_simple_resource_complex_properties_azure_v1api20200101.golden b/v2/tools/generator/internal/codegen/testdata/ArmResource/Arm_test_simple_resource_complex_properties_azure_v1api20200101.golden index c79bc1476c..a64ab2da70 100644 --- a/v2/tools/generator/internal/codegen/testdata/ArmResource/Arm_test_simple_resource_complex_properties_azure_v1api20200101.golden +++ b/v2/tools/generator/internal/codegen/testdata/ArmResource/Arm_test_simple_resource_complex_properties_azure_v1api20200101.golden @@ -5,8 +5,8 @@ package v1api20200101 import ( "fmt" - v20200101a "github.com/Azure/azure-service-operator/testing/test/v1api20200101/arm" - v20200101s "github.com/Azure/azure-service-operator/testing/test/v1api20200101/storage" + arm "github.com/Azure/azure-service-operator/testing/test/v1api20200101/arm" + storage "github.com/Azure/azure-service-operator/testing/test/v1api20200101/storage" "github.com/Azure/azure-service-operator/v2/internal/reflecthelpers" "github.com/Azure/azure-service-operator/v2/pkg/genruntime" "github.com/Azure/azure-service-operator/v2/pkg/genruntime/conditions" @@ -46,7 +46,7 @@ var _ conversion.Convertible = &FakeResource{} // ConvertFrom populates our FakeResource from the provided hub FakeResource func (resource *FakeResource) ConvertFrom(hub conversion.Hub) error { - source, ok := hub.(*v20200101s.FakeResource) + source, ok := hub.(*storage.FakeResource) if !ok { return fmt.Errorf("expected test/v1api20200101/storage/FakeResource but received %T instead", hub) } @@ -56,7 +56,7 @@ func (resource *FakeResource) ConvertFrom(hub conversion.Hub) error { // ConvertTo populates the provided hub FakeResource from our FakeResource func (resource *FakeResource) ConvertTo(hub conversion.Hub) error { - destination, ok := hub.(*v20200101s.FakeResource) + destination, ok := hub.(*storage.FakeResource) if !ok { return fmt.Errorf("expected test/v1api20200101/storage/FakeResource but received %T instead", hub) } @@ -211,7 +211,7 @@ func (resource *FakeResource) validateWriteOnceProperties(old runtime.Object) (a } // AssignProperties_From_FakeResource populates our FakeResource from the provided source FakeResource -func (resource *FakeResource) AssignProperties_From_FakeResource(source *v20200101s.FakeResource) error { +func (resource *FakeResource) AssignProperties_From_FakeResource(source *storage.FakeResource) error { // ObjectMeta resource.ObjectMeta = *source.ObjectMeta.DeepCopy() @@ -229,13 +229,13 @@ func (resource *FakeResource) AssignProperties_From_FakeResource(source *v202001 } // AssignProperties_To_FakeResource populates the provided destination FakeResource from our FakeResource -func (resource *FakeResource) AssignProperties_To_FakeResource(destination *v20200101s.FakeResource) error { +func (resource *FakeResource) AssignProperties_To_FakeResource(destination *storage.FakeResource) error { // ObjectMeta destination.ObjectMeta = *resource.ObjectMeta.DeepCopy() // Spec - var spec v20200101s.FakeResource_Spec + var spec storage.FakeResource_Spec err := resource.Spec.AssignProperties_To_FakeResource_Spec(&spec) if err != nil { return errors.Wrap(err, "calling AssignProperties_To_FakeResource_Spec() to populate field Spec") @@ -301,7 +301,7 @@ func (resource *FakeResource_Spec) ConvertToARM(resolved genruntime.ConvertToARM if resource == nil { return nil, nil } - result := &FakeResource_Spec{} + result := &arm.FakeResource_Spec{} // Set property "APIVersion": result.APIVersion = resource.APIVersion @@ -318,7 +318,7 @@ func (resource *FakeResource_Spec) ConvertToARM(resolved genruntime.ConvertToARM if err != nil { return nil, err } - foo := *foo_ARM.(*v20200101a.Foo) + foo := *foo_ARM.(*arm.Foo) result.Foo = &foo } @@ -331,7 +331,7 @@ func (resource *FakeResource_Spec) ConvertToARM(resolved genruntime.ConvertToARM if err != nil { return nil, err } - optionalFoo := *optionalFoo_ARM.(*v20200101a.Foo) + optionalFoo := *optionalFoo_ARM.(*arm.Foo) result.OptionalFoo = &optionalFoo } @@ -342,14 +342,14 @@ func (resource *FakeResource_Spec) ConvertToARM(resolved genruntime.ConvertToARM // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (resource *FakeResource_Spec) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &v20200101a.FakeResource_Spec{} + return &arm.FakeResource_Spec{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (resource *FakeResource_Spec) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(FakeResource_Spec) + typedInput, ok := armInput.(arm.FakeResource_Spec) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected FakeResource_Spec, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.FakeResource_Spec, got %T", armInput) } // Set property "APIVersion": @@ -403,14 +403,14 @@ var _ genruntime.ConvertibleSpec = &FakeResource_Spec{} // ConvertSpecFrom populates our FakeResource_Spec from the provided source func (resource *FakeResource_Spec) ConvertSpecFrom(source genruntime.ConvertibleSpec) error { - src, ok := source.(*v20200101s.FakeResource_Spec) + src, ok := source.(*storage.FakeResource_Spec) if ok { // Populate our instance from source return resource.AssignProperties_From_FakeResource_Spec(src) } // Convert to an intermediate form - src = &v20200101s.FakeResource_Spec{} + src = &storage.FakeResource_Spec{} err := src.ConvertSpecFrom(source) if err != nil { return errors.Wrap(err, "initial step of conversion in ConvertSpecFrom()") @@ -427,14 +427,14 @@ func (resource *FakeResource_Spec) ConvertSpecFrom(source genruntime.Convertible // ConvertSpecTo populates the provided destination from our FakeResource_Spec func (resource *FakeResource_Spec) ConvertSpecTo(destination genruntime.ConvertibleSpec) error { - dst, ok := destination.(*v20200101s.FakeResource_Spec) + dst, ok := destination.(*storage.FakeResource_Spec) if ok { // Populate destination from our instance return resource.AssignProperties_To_FakeResource_Spec(dst) } // Convert to an intermediate form - dst = &v20200101s.FakeResource_Spec{} + dst = &storage.FakeResource_Spec{} err := resource.AssignProperties_To_FakeResource_Spec(dst) if err != nil { return errors.Wrap(err, "initial step of conversion in ConvertSpecTo()") @@ -450,11 +450,12 @@ func (resource *FakeResource_Spec) ConvertSpecTo(destination genruntime.Converti } // AssignProperties_From_FakeResource_Spec populates our FakeResource_Spec from the provided source FakeResource_Spec -func (resource *FakeResource_Spec) AssignProperties_From_FakeResource_Spec(source *v20200101s.FakeResource_Spec) error { +func (resource *FakeResource_Spec) AssignProperties_From_FakeResource_Spec(source *storage.FakeResource_Spec) error { // APIVersion if source.APIVersion != nil { - resource.APIVersion = FakeResource_APIVersion_Spec(*source.APIVersion) + apiVersion := *source.APIVersion + resource.APIVersion = genruntime.ToEnum(apiVersion, fakeResource_APIVersion_Spec_Values) } else { resource.APIVersion = "" } @@ -464,8 +465,9 @@ func (resource *FakeResource_Spec) AssignProperties_From_FakeResource_Spec(sourc // Color if source.Color != nil { - color := FakeResource_Color_Spec(*source.Color) - resource.Color = &color + color := *source.Color + colorTemp := genruntime.ToEnum(color, fakeResource_Color_Spec_Values) + resource.Color = &colorTemp } else { resource.Color = nil } @@ -504,7 +506,8 @@ func (resource *FakeResource_Spec) AssignProperties_From_FakeResource_Spec(sourc // Type if source.Type != nil { - resource.Type = FakeResource_Type_Spec(*source.Type) + typeVar := *source.Type + resource.Type = genruntime.ToEnum(typeVar, fakeResource_Type_Spec_Values) } else { resource.Type = "" } @@ -514,7 +517,7 @@ func (resource *FakeResource_Spec) AssignProperties_From_FakeResource_Spec(sourc } // AssignProperties_To_FakeResource_Spec populates the provided destination FakeResource_Spec from our FakeResource_Spec -func (resource *FakeResource_Spec) AssignProperties_To_FakeResource_Spec(destination *v20200101s.FakeResource_Spec) error { +func (resource *FakeResource_Spec) AssignProperties_To_FakeResource_Spec(destination *storage.FakeResource_Spec) error { // Create a new property bag propertyBag := genruntime.NewPropertyBag() @@ -535,7 +538,7 @@ func (resource *FakeResource_Spec) AssignProperties_To_FakeResource_Spec(destina // Foo if resource.Foo != nil { - var foo v20200101s.Foo + var foo storage.Foo err := resource.Foo.AssignProperties_To_Foo(&foo) if err != nil { return errors.Wrap(err, "calling AssignProperties_To_Foo() to populate field Foo") @@ -547,7 +550,7 @@ func (resource *FakeResource_Spec) AssignProperties_To_FakeResource_Spec(destina // OptionalFoo if resource.OptionalFoo != nil { - var optionalFoo v20200101s.Foo + var optionalFoo storage.Foo err := resource.OptionalFoo.AssignProperties_To_Foo(&optionalFoo) if err != nil { return errors.Wrap(err, "calling AssignProperties_To_Foo() to populate field OptionalFoo") @@ -596,6 +599,11 @@ type FakeResource_APIVersion_Spec string const FakeResource_APIVersion_Spec_20200601 = FakeResource_APIVersion_Spec("2020-06-01") +// Mapping from string to FakeResource_APIVersion_Spec +var fakeResource_APIVersion_Spec_Values = map[string]FakeResource_APIVersion_Spec{ + "2020-06-01": FakeResource_APIVersion_Spec_20200601, +} + // +kubebuilder:validation:Enum={"blue","green","red"} type FakeResource_Color_Spec string @@ -605,11 +613,23 @@ const ( FakeResource_Color_Spec_Red = FakeResource_Color_Spec("red") ) +// Mapping from string to FakeResource_Color_Spec +var fakeResource_Color_Spec_Values = map[string]FakeResource_Color_Spec{ + "blue": FakeResource_Color_Spec_Blue, + "green": FakeResource_Color_Spec_Green, + "red": FakeResource_Color_Spec_Red, +} + // +kubebuilder:validation:Enum={"Microsoft.Azure/FakeResource"} type FakeResource_Type_Spec string const FakeResource_Type_Spec_MicrosoftAzureFakeResource = FakeResource_Type_Spec("Microsoft.Azure/FakeResource") +// Mapping from string to FakeResource_Type_Spec +var fakeResource_Type_Spec_Values = map[string]FakeResource_Type_Spec{ + "microsoft.azure/fakeresource": FakeResource_Type_Spec_MicrosoftAzureFakeResource, +} + // Generated from: https://test.test/schemas/2020-01-01/test.json#/definitions/Foo type Foo struct { Name *string `json:"name,omitempty"` @@ -622,7 +642,7 @@ func (foo *Foo) ConvertToARM(resolved genruntime.ConvertToARMResolvedDetails) (i if foo == nil { return nil, nil } - result := &Foo{} + result := &arm.Foo{} // Set property "Name": if foo.Name != nil { @@ -634,14 +654,14 @@ func (foo *Foo) ConvertToARM(resolved genruntime.ConvertToARMResolvedDetails) (i // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (foo *Foo) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &v20200101a.Foo{} + return &arm.Foo{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (foo *Foo) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(Foo) + typedInput, ok := armInput.(arm.Foo) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected Foo, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.Foo, got %T", armInput) } // Set property "Name": @@ -655,7 +675,7 @@ func (foo *Foo) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInp } // AssignProperties_From_Foo populates our Foo from the provided source Foo -func (foo *Foo) AssignProperties_From_Foo(source *v20200101s.Foo) error { +func (foo *Foo) AssignProperties_From_Foo(source *storage.Foo) error { // Name foo.Name = genruntime.ClonePointerToString(source.Name) @@ -665,7 +685,7 @@ func (foo *Foo) AssignProperties_From_Foo(source *v20200101s.Foo) error { } // AssignProperties_To_Foo populates the provided destination Foo from our Foo -func (foo *Foo) AssignProperties_To_Foo(destination *v20200101s.Foo) error { +func (foo *Foo) AssignProperties_To_Foo(destination *storage.Foo) error { // Create a new property bag propertyBag := genruntime.NewPropertyBag() diff --git a/v2/tools/generator/internal/codegen/testdata/ArmResource/Arm_test_simple_resource_json_fields_azure_v1api20200101.golden b/v2/tools/generator/internal/codegen/testdata/ArmResource/Arm_test_simple_resource_json_fields_azure_v1api20200101.golden index 03b5ee4412..a2dd7c2cd7 100644 --- a/v2/tools/generator/internal/codegen/testdata/ArmResource/Arm_test_simple_resource_json_fields_azure_v1api20200101.golden +++ b/v2/tools/generator/internal/codegen/testdata/ArmResource/Arm_test_simple_resource_json_fields_azure_v1api20200101.golden @@ -5,8 +5,8 @@ package v1api20200101 import ( "fmt" - v20200101a "github.com/Azure/azure-service-operator/testing/test/v1api20200101/arm" - v20200101s "github.com/Azure/azure-service-operator/testing/test/v1api20200101/storage" + arm "github.com/Azure/azure-service-operator/testing/test/v1api20200101/arm" + storage "github.com/Azure/azure-service-operator/testing/test/v1api20200101/storage" "github.com/Azure/azure-service-operator/v2/internal/reflecthelpers" "github.com/Azure/azure-service-operator/v2/pkg/genruntime" "github.com/Azure/azure-service-operator/v2/pkg/genruntime/conditions" @@ -47,7 +47,7 @@ var _ conversion.Convertible = &FakeResource{} // ConvertFrom populates our FakeResource from the provided hub FakeResource func (resource *FakeResource) ConvertFrom(hub conversion.Hub) error { - source, ok := hub.(*v20200101s.FakeResource) + source, ok := hub.(*storage.FakeResource) if !ok { return fmt.Errorf("expected test/v1api20200101/storage/FakeResource but received %T instead", hub) } @@ -57,7 +57,7 @@ func (resource *FakeResource) ConvertFrom(hub conversion.Hub) error { // ConvertTo populates the provided hub FakeResource from our FakeResource func (resource *FakeResource) ConvertTo(hub conversion.Hub) error { - destination, ok := hub.(*v20200101s.FakeResource) + destination, ok := hub.(*storage.FakeResource) if !ok { return fmt.Errorf("expected test/v1api20200101/storage/FakeResource but received %T instead", hub) } @@ -212,7 +212,7 @@ func (resource *FakeResource) validateWriteOnceProperties(old runtime.Object) (a } // AssignProperties_From_FakeResource populates our FakeResource from the provided source FakeResource -func (resource *FakeResource) AssignProperties_From_FakeResource(source *v20200101s.FakeResource) error { +func (resource *FakeResource) AssignProperties_From_FakeResource(source *storage.FakeResource) error { // ObjectMeta resource.ObjectMeta = *source.ObjectMeta.DeepCopy() @@ -230,13 +230,13 @@ func (resource *FakeResource) AssignProperties_From_FakeResource(source *v202001 } // AssignProperties_To_FakeResource populates the provided destination FakeResource from our FakeResource -func (resource *FakeResource) AssignProperties_To_FakeResource(destination *v20200101s.FakeResource) error { +func (resource *FakeResource) AssignProperties_To_FakeResource(destination *storage.FakeResource) error { // ObjectMeta destination.ObjectMeta = *resource.ObjectMeta.DeepCopy() // Spec - var spec v20200101s.FakeResource_Spec + var spec storage.FakeResource_Spec err := resource.Spec.AssignProperties_To_FakeResource_Spec(&spec) if err != nil { return errors.Wrap(err, "calling AssignProperties_To_FakeResource_Spec() to populate field Spec") @@ -301,7 +301,7 @@ func (resource *FakeResource_Spec) ConvertToARM(resolved genruntime.ConvertToARM if resource == nil { return nil, nil } - result := &FakeResource_Spec{} + result := &arm.FakeResource_Spec{} // Set property "APIVersion": result.APIVersion = resource.APIVersion @@ -336,14 +336,14 @@ func (resource *FakeResource_Spec) ConvertToARM(resolved genruntime.ConvertToARM // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (resource *FakeResource_Spec) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &v20200101a.FakeResource_Spec{} + return &arm.FakeResource_Spec{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (resource *FakeResource_Spec) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(FakeResource_Spec) + typedInput, ok := armInput.(arm.FakeResource_Spec) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected FakeResource_Spec, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.FakeResource_Spec, got %T", armInput) } // Set property "APIVersion": @@ -389,14 +389,14 @@ var _ genruntime.ConvertibleSpec = &FakeResource_Spec{} // ConvertSpecFrom populates our FakeResource_Spec from the provided source func (resource *FakeResource_Spec) ConvertSpecFrom(source genruntime.ConvertibleSpec) error { - src, ok := source.(*v20200101s.FakeResource_Spec) + src, ok := source.(*storage.FakeResource_Spec) if ok { // Populate our instance from source return resource.AssignProperties_From_FakeResource_Spec(src) } // Convert to an intermediate form - src = &v20200101s.FakeResource_Spec{} + src = &storage.FakeResource_Spec{} err := src.ConvertSpecFrom(source) if err != nil { return errors.Wrap(err, "initial step of conversion in ConvertSpecFrom()") @@ -413,14 +413,14 @@ func (resource *FakeResource_Spec) ConvertSpecFrom(source genruntime.Convertible // ConvertSpecTo populates the provided destination from our FakeResource_Spec func (resource *FakeResource_Spec) ConvertSpecTo(destination genruntime.ConvertibleSpec) error { - dst, ok := destination.(*v20200101s.FakeResource_Spec) + dst, ok := destination.(*storage.FakeResource_Spec) if ok { // Populate destination from our instance return resource.AssignProperties_To_FakeResource_Spec(dst) } // Convert to an intermediate form - dst = &v20200101s.FakeResource_Spec{} + dst = &storage.FakeResource_Spec{} err := resource.AssignProperties_To_FakeResource_Spec(dst) if err != nil { return errors.Wrap(err, "initial step of conversion in ConvertSpecTo()") @@ -436,11 +436,12 @@ func (resource *FakeResource_Spec) ConvertSpecTo(destination genruntime.Converti } // AssignProperties_From_FakeResource_Spec populates our FakeResource_Spec from the provided source FakeResource_Spec -func (resource *FakeResource_Spec) AssignProperties_From_FakeResource_Spec(source *v20200101s.FakeResource_Spec) error { +func (resource *FakeResource_Spec) AssignProperties_From_FakeResource_Spec(source *storage.FakeResource_Spec) error { // APIVersion if source.APIVersion != nil { - resource.APIVersion = FakeResource_APIVersion_Spec(*source.APIVersion) + apiVersion := *source.APIVersion + resource.APIVersion = genruntime.ToEnum(apiVersion, fakeResource_APIVersion_Spec_Values) } else { resource.APIVersion = "" } @@ -487,7 +488,8 @@ func (resource *FakeResource_Spec) AssignProperties_From_FakeResource_Spec(sourc // Type if source.Type != nil { - resource.Type = FakeResource_Type_Spec(*source.Type) + typeVar := *source.Type + resource.Type = genruntime.ToEnum(typeVar, fakeResource_Type_Spec_Values) } else { resource.Type = "" } @@ -497,7 +499,7 @@ func (resource *FakeResource_Spec) AssignProperties_From_FakeResource_Spec(sourc } // AssignProperties_To_FakeResource_Spec populates the provided destination FakeResource_Spec from our FakeResource_Spec -func (resource *FakeResource_Spec) AssignProperties_To_FakeResource_Spec(destination *v20200101s.FakeResource_Spec) error { +func (resource *FakeResource_Spec) AssignProperties_To_FakeResource_Spec(destination *storage.FakeResource_Spec) error { // Create a new property bag propertyBag := genruntime.NewPropertyBag() @@ -576,11 +578,21 @@ type FakeResource_APIVersion_Spec string const FakeResource_APIVersion_Spec_20200601 = FakeResource_APIVersion_Spec("2020-06-01") +// Mapping from string to FakeResource_APIVersion_Spec +var fakeResource_APIVersion_Spec_Values = map[string]FakeResource_APIVersion_Spec{ + "2020-06-01": FakeResource_APIVersion_Spec_20200601, +} + // +kubebuilder:validation:Enum={"Microsoft.Azure/FakeResource"} type FakeResource_Type_Spec string const FakeResource_Type_Spec_MicrosoftAzureFakeResource = FakeResource_Type_Spec("Microsoft.Azure/FakeResource") +// Mapping from string to FakeResource_Type_Spec +var fakeResource_Type_Spec_Values = map[string]FakeResource_Type_Spec{ + "microsoft.azure/fakeresource": FakeResource_Type_Spec_MicrosoftAzureFakeResource, +} + func init() { SchemeBuilder.Register(&FakeResource{}, &FakeResourceList{}) } diff --git a/v2/tools/generator/internal/codegen/testdata/ArmResource/Arm_test_simple_resource_map_properties_azure_v1api20200101.golden b/v2/tools/generator/internal/codegen/testdata/ArmResource/Arm_test_simple_resource_map_properties_azure_v1api20200101.golden index 671ba6380e..9274e3c5e2 100644 --- a/v2/tools/generator/internal/codegen/testdata/ArmResource/Arm_test_simple_resource_map_properties_azure_v1api20200101.golden +++ b/v2/tools/generator/internal/codegen/testdata/ArmResource/Arm_test_simple_resource_map_properties_azure_v1api20200101.golden @@ -5,8 +5,8 @@ package v1api20200101 import ( "fmt" - v20200101a "github.com/Azure/azure-service-operator/testing/test/v1api20200101/arm" - v20200101s "github.com/Azure/azure-service-operator/testing/test/v1api20200101/storage" + arm "github.com/Azure/azure-service-operator/testing/test/v1api20200101/arm" + storage "github.com/Azure/azure-service-operator/testing/test/v1api20200101/storage" "github.com/Azure/azure-service-operator/v2/internal/reflecthelpers" "github.com/Azure/azure-service-operator/v2/pkg/genruntime" "github.com/Azure/azure-service-operator/v2/pkg/genruntime/conditions" @@ -46,7 +46,7 @@ var _ conversion.Convertible = &FakeResource{} // ConvertFrom populates our FakeResource from the provided hub FakeResource func (resource *FakeResource) ConvertFrom(hub conversion.Hub) error { - source, ok := hub.(*v20200101s.FakeResource) + source, ok := hub.(*storage.FakeResource) if !ok { return fmt.Errorf("expected test/v1api20200101/storage/FakeResource but received %T instead", hub) } @@ -56,7 +56,7 @@ func (resource *FakeResource) ConvertFrom(hub conversion.Hub) error { // ConvertTo populates the provided hub FakeResource from our FakeResource func (resource *FakeResource) ConvertTo(hub conversion.Hub) error { - destination, ok := hub.(*v20200101s.FakeResource) + destination, ok := hub.(*storage.FakeResource) if !ok { return fmt.Errorf("expected test/v1api20200101/storage/FakeResource but received %T instead", hub) } @@ -211,7 +211,7 @@ func (resource *FakeResource) validateWriteOnceProperties(old runtime.Object) (a } // AssignProperties_From_FakeResource populates our FakeResource from the provided source FakeResource -func (resource *FakeResource) AssignProperties_From_FakeResource(source *v20200101s.FakeResource) error { +func (resource *FakeResource) AssignProperties_From_FakeResource(source *storage.FakeResource) error { // ObjectMeta resource.ObjectMeta = *source.ObjectMeta.DeepCopy() @@ -229,13 +229,13 @@ func (resource *FakeResource) AssignProperties_From_FakeResource(source *v202001 } // AssignProperties_To_FakeResource populates the provided destination FakeResource from our FakeResource -func (resource *FakeResource) AssignProperties_To_FakeResource(destination *v20200101s.FakeResource) error { +func (resource *FakeResource) AssignProperties_To_FakeResource(destination *storage.FakeResource) error { // ObjectMeta destination.ObjectMeta = *resource.ObjectMeta.DeepCopy() // Spec - var spec v20200101s.FakeResource_Spec + var spec storage.FakeResource_Spec err := resource.Spec.AssignProperties_To_FakeResource_Spec(&spec) if err != nil { return errors.Wrap(err, "calling AssignProperties_To_FakeResource_Spec() to populate field Spec") @@ -302,34 +302,34 @@ func (resource *FakeResource_Spec) ConvertToARM(resolved genruntime.ConvertToARM if resource == nil { return nil, nil } - result := &FakeResource_Spec{} + result := &arm.FakeResource_Spec{} // Set property "APIVersion": result.APIVersion = resource.APIVersion // Set property "MapFoo": if resource.MapFoo != nil { - result.MapFoo = make(map[string]v20200101a.Foo, len(resource.MapFoo)) + result.MapFoo = make(map[string]arm.Foo, len(resource.MapFoo)) for key, value := range resource.MapFoo { value_ARM, err := value.ConvertToARM(resolved) if err != nil { return nil, err } - result.MapFoo[key] = *value_ARM.(*v20200101a.Foo) + result.MapFoo[key] = *value_ARM.(*arm.Foo) } } // Set property "MapOfArrays": if resource.MapOfArrays != nil { - result.MapOfArrays = make(map[string][]v20200101a.Foo, len(resource.MapOfArrays)) + result.MapOfArrays = make(map[string][]arm.Foo, len(resource.MapOfArrays)) for key, value := range resource.MapOfArrays { - var valueTemp []v20200101a.Foo + var valueTemp []arm.Foo for _, item := range value { item_ARM, err := item.ConvertToARM(resolved) if err != nil { return nil, err } - valueTemp = append(valueTemp, *item_ARM.(*v20200101a.Foo)) + valueTemp = append(valueTemp, *item_ARM.(*arm.Foo)) } result.MapOfArrays[key] = valueTemp } @@ -345,16 +345,16 @@ func (resource *FakeResource_Spec) ConvertToARM(resolved genruntime.ConvertToARM // Set property "MapOfMaps": if resource.MapOfMaps != nil { - result.MapOfMaps = make(map[string]map[string]v20200101a.Foo, len(resource.MapOfMaps)) + result.MapOfMaps = make(map[string]map[string]arm.Foo, len(resource.MapOfMaps)) for key, value := range resource.MapOfMaps { if value != nil { - valueTemp := make(map[string]v20200101a.Foo, len(value)) + valueTemp := make(map[string]arm.Foo, len(value)) for valueKey, value1 := range value { value1_ARM, err := value1.ConvertToARM(resolved) if err != nil { return nil, err } - valueTemp[valueKey] = *value1_ARM.(*v20200101a.Foo) + valueTemp[valueKey] = *value1_ARM.(*arm.Foo) } result.MapOfMaps[key] = valueTemp } @@ -363,19 +363,19 @@ func (resource *FakeResource_Spec) ConvertToARM(resolved genruntime.ConvertToARM // Set property "MapOfMapsOfMaps": if resource.MapOfMapsOfMaps != nil { - result.MapOfMapsOfMaps = make(map[string]map[string]map[string]v20200101a.Foo, len(resource.MapOfMapsOfMaps)) + result.MapOfMapsOfMaps = make(map[string]map[string]map[string]arm.Foo, len(resource.MapOfMapsOfMaps)) for key, value := range resource.MapOfMapsOfMaps { if value != nil { - valueTemp := make(map[string]map[string]v20200101a.Foo, len(value)) + valueTemp := make(map[string]map[string]arm.Foo, len(value)) for valueKey, value1 := range value { if value1 != nil { - value1Temp := make(map[string]v20200101a.Foo, len(value1)) + value1Temp := make(map[string]arm.Foo, len(value1)) for valueKey1, value2 := range value1 { value2_ARM, err := value2.ConvertToARM(resolved) if err != nil { return nil, err } - value1Temp[valueKey1] = *value2_ARM.(*v20200101a.Foo) + value1Temp[valueKey1] = *value2_ARM.(*arm.Foo) } valueTemp[valueKey] = value1Temp } @@ -423,14 +423,14 @@ func (resource *FakeResource_Spec) ConvertToARM(resolved genruntime.ConvertToARM // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (resource *FakeResource_Spec) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &v20200101a.FakeResource_Spec{} + return &arm.FakeResource_Spec{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (resource *FakeResource_Spec) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(FakeResource_Spec) + typedInput, ok := armInput.(arm.FakeResource_Spec) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected FakeResource_Spec, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.FakeResource_Spec, got %T", armInput) } // Set property "APIVersion": @@ -566,14 +566,14 @@ var _ genruntime.ConvertibleSpec = &FakeResource_Spec{} // ConvertSpecFrom populates our FakeResource_Spec from the provided source func (resource *FakeResource_Spec) ConvertSpecFrom(source genruntime.ConvertibleSpec) error { - src, ok := source.(*v20200101s.FakeResource_Spec) + src, ok := source.(*storage.FakeResource_Spec) if ok { // Populate our instance from source return resource.AssignProperties_From_FakeResource_Spec(src) } // Convert to an intermediate form - src = &v20200101s.FakeResource_Spec{} + src = &storage.FakeResource_Spec{} err := src.ConvertSpecFrom(source) if err != nil { return errors.Wrap(err, "initial step of conversion in ConvertSpecFrom()") @@ -590,14 +590,14 @@ func (resource *FakeResource_Spec) ConvertSpecFrom(source genruntime.Convertible // ConvertSpecTo populates the provided destination from our FakeResource_Spec func (resource *FakeResource_Spec) ConvertSpecTo(destination genruntime.ConvertibleSpec) error { - dst, ok := destination.(*v20200101s.FakeResource_Spec) + dst, ok := destination.(*storage.FakeResource_Spec) if ok { // Populate destination from our instance return resource.AssignProperties_To_FakeResource_Spec(dst) } // Convert to an intermediate form - dst = &v20200101s.FakeResource_Spec{} + dst = &storage.FakeResource_Spec{} err := resource.AssignProperties_To_FakeResource_Spec(dst) if err != nil { return errors.Wrap(err, "initial step of conversion in ConvertSpecTo()") @@ -613,11 +613,12 @@ func (resource *FakeResource_Spec) ConvertSpecTo(destination genruntime.Converti } // AssignProperties_From_FakeResource_Spec populates our FakeResource_Spec from the provided source FakeResource_Spec -func (resource *FakeResource_Spec) AssignProperties_From_FakeResource_Spec(source *v20200101s.FakeResource_Spec) error { +func (resource *FakeResource_Spec) AssignProperties_From_FakeResource_Spec(source *storage.FakeResource_Spec) error { // APIVersion if source.APIVersion != nil { - resource.APIVersion = FakeResource_APIVersion_Spec(*source.APIVersion) + apiVersion := *source.APIVersion + resource.APIVersion = genruntime.ToEnum(apiVersion, fakeResource_APIVersion_Spec_Values) } else { resource.APIVersion = "" } @@ -677,7 +678,7 @@ func (resource *FakeResource_Spec) AssignProperties_From_FakeResource_Spec(sourc for mapOfEnumKey, mapOfEnumValue := range source.MapOfEnums { // Shadow the loop variable to avoid aliasing mapOfEnumValue := mapOfEnumValue - mapOfEnumMap[mapOfEnumKey] = Color(mapOfEnumValue) + mapOfEnumMap[mapOfEnumKey] = genruntime.ToEnum(mapOfEnumValue, color_Values) } resource.MapOfEnums = mapOfEnumMap } else { @@ -786,7 +787,8 @@ func (resource *FakeResource_Spec) AssignProperties_From_FakeResource_Spec(sourc // Type if source.Type != nil { - resource.Type = FakeResource_Type_Spec(*source.Type) + typeVar := *source.Type + resource.Type = genruntime.ToEnum(typeVar, fakeResource_Type_Spec_Values) } else { resource.Type = "" } @@ -796,7 +798,7 @@ func (resource *FakeResource_Spec) AssignProperties_From_FakeResource_Spec(sourc } // AssignProperties_To_FakeResource_Spec populates the provided destination FakeResource_Spec from our FakeResource_Spec -func (resource *FakeResource_Spec) AssignProperties_To_FakeResource_Spec(destination *v20200101s.FakeResource_Spec) error { +func (resource *FakeResource_Spec) AssignProperties_To_FakeResource_Spec(destination *storage.FakeResource_Spec) error { // Create a new property bag propertyBag := genruntime.NewPropertyBag() @@ -809,11 +811,11 @@ func (resource *FakeResource_Spec) AssignProperties_To_FakeResource_Spec(destina // MapFoo if resource.MapFoo != nil { - mapFooMap := make(map[string]v20200101s.Foo, len(resource.MapFoo)) + mapFooMap := make(map[string]storage.Foo, len(resource.MapFoo)) for mapFooKey, mapFooValue := range resource.MapFoo { // Shadow the loop variable to avoid aliasing mapFooValue := mapFooValue - var mapFoo v20200101s.Foo + var mapFoo storage.Foo err := mapFooValue.AssignProperties_To_Foo(&mapFoo) if err != nil { return errors.Wrap(err, "calling AssignProperties_To_Foo() to populate field MapFoo") @@ -827,16 +829,16 @@ func (resource *FakeResource_Spec) AssignProperties_To_FakeResource_Spec(destina // MapOfArrays if resource.MapOfArrays != nil { - mapOfArrayMap := make(map[string][]v20200101s.Foo, len(resource.MapOfArrays)) + mapOfArrayMap := make(map[string][]storage.Foo, len(resource.MapOfArrays)) for mapOfArrayKey, mapOfArrayValue := range resource.MapOfArrays { // Shadow the loop variable to avoid aliasing mapOfArrayValue := mapOfArrayValue if mapOfArrayValue != nil { - mapOfArrayList := make([]v20200101s.Foo, len(mapOfArrayValue)) + mapOfArrayList := make([]storage.Foo, len(mapOfArrayValue)) for mapOfArrayIndex, mapOfArrayItem := range mapOfArrayValue { // Shadow the loop variable to avoid aliasing mapOfArrayItem := mapOfArrayItem - var mapOfArray v20200101s.Foo + var mapOfArray storage.Foo err := mapOfArrayItem.AssignProperties_To_Foo(&mapOfArray) if err != nil { return errors.Wrap(err, "calling AssignProperties_To_Foo() to populate field MapOfArrays") @@ -868,16 +870,16 @@ func (resource *FakeResource_Spec) AssignProperties_To_FakeResource_Spec(destina // MapOfMaps if resource.MapOfMaps != nil { - mapOfMap := make(map[string]map[string]v20200101s.Foo, len(resource.MapOfMaps)) + mapOfMap := make(map[string]map[string]storage.Foo, len(resource.MapOfMaps)) for mapOfMapKey, mapOfMapValue := range resource.MapOfMaps { // Shadow the loop variable to avoid aliasing mapOfMapValue := mapOfMapValue if mapOfMapValue != nil { - mapOfMap1 := make(map[string]v20200101s.Foo, len(mapOfMapValue)) + mapOfMap1 := make(map[string]storage.Foo, len(mapOfMapValue)) for mapOfMapKey1, mapOfMapValue1 := range mapOfMapValue { // Shadow the loop variable to avoid aliasing mapOfMapValue1 := mapOfMapValue1 - var mapOfMapLocal v20200101s.Foo + var mapOfMapLocal storage.Foo err := mapOfMapValue1.AssignProperties_To_Foo(&mapOfMapLocal) if err != nil { return errors.Wrap(err, "calling AssignProperties_To_Foo() to populate field MapOfMaps") @@ -896,21 +898,21 @@ func (resource *FakeResource_Spec) AssignProperties_To_FakeResource_Spec(destina // MapOfMapsOfMaps if resource.MapOfMapsOfMaps != nil { - mapOfMapsOfMap := make(map[string]map[string]map[string]v20200101s.Foo, len(resource.MapOfMapsOfMaps)) + mapOfMapsOfMap := make(map[string]map[string]map[string]storage.Foo, len(resource.MapOfMapsOfMaps)) for mapOfMapsOfMapKey, mapOfMapsOfMapValue := range resource.MapOfMapsOfMaps { // Shadow the loop variable to avoid aliasing mapOfMapsOfMapValue := mapOfMapsOfMapValue if mapOfMapsOfMapValue != nil { - mapOfMapsOfMap1 := make(map[string]map[string]v20200101s.Foo, len(mapOfMapsOfMapValue)) + mapOfMapsOfMap1 := make(map[string]map[string]storage.Foo, len(mapOfMapsOfMapValue)) for mapOfMapsOfMapKey1, mapOfMapsOfMapValue1 := range mapOfMapsOfMapValue { // Shadow the loop variable to avoid aliasing mapOfMapsOfMapValue1 := mapOfMapsOfMapValue1 if mapOfMapsOfMapValue1 != nil { - mapOfMapsOfMap2 := make(map[string]v20200101s.Foo, len(mapOfMapsOfMapValue1)) + mapOfMapsOfMap2 := make(map[string]storage.Foo, len(mapOfMapsOfMapValue1)) for mapOfMapsOfMapKey2, mapOfMapsOfMapValue2 := range mapOfMapsOfMapValue1 { // Shadow the loop variable to avoid aliasing mapOfMapsOfMapValue2 := mapOfMapsOfMapValue2 - var mapOfMapsOfMapLocal v20200101s.Foo + var mapOfMapsOfMapLocal storage.Foo err := mapOfMapsOfMapValue2.AssignProperties_To_Foo(&mapOfMapsOfMapLocal) if err != nil { return errors.Wrap(err, "calling AssignProperties_To_Foo() to populate field MapOfMapsOfMaps") @@ -1002,16 +1004,33 @@ const ( Color_Red = Color("red") ) +// Mapping from string to Color +var color_Values = map[string]Color{ + "blue": Color_Blue, + "green": Color_Green, + "red": Color_Red, +} + // +kubebuilder:validation:Enum={"2020-06-01"} type FakeResource_APIVersion_Spec string const FakeResource_APIVersion_Spec_20200601 = FakeResource_APIVersion_Spec("2020-06-01") +// Mapping from string to FakeResource_APIVersion_Spec +var fakeResource_APIVersion_Spec_Values = map[string]FakeResource_APIVersion_Spec{ + "2020-06-01": FakeResource_APIVersion_Spec_20200601, +} + // +kubebuilder:validation:Enum={"Microsoft.Azure/FakeResource"} type FakeResource_Type_Spec string const FakeResource_Type_Spec_MicrosoftAzureFakeResource = FakeResource_Type_Spec("Microsoft.Azure/FakeResource") +// Mapping from string to FakeResource_Type_Spec +var fakeResource_Type_Spec_Values = map[string]FakeResource_Type_Spec{ + "microsoft.azure/fakeresource": FakeResource_Type_Spec_MicrosoftAzureFakeResource, +} + // Generated from: https://test.test/schemas/2020-01-01/test.json#/definitions/Foo type Foo struct { FooName *string `json:"fooName,omitempty"` @@ -1024,7 +1043,7 @@ func (foo *Foo) ConvertToARM(resolved genruntime.ConvertToARMResolvedDetails) (i if foo == nil { return nil, nil } - result := &Foo{} + result := &arm.Foo{} // Set property "FooName": if foo.FooName != nil { @@ -1036,14 +1055,14 @@ func (foo *Foo) ConvertToARM(resolved genruntime.ConvertToARMResolvedDetails) (i // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (foo *Foo) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &v20200101a.Foo{} + return &arm.Foo{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (foo *Foo) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(Foo) + typedInput, ok := armInput.(arm.Foo) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected Foo, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.Foo, got %T", armInput) } // Set property "FooName": @@ -1057,7 +1076,7 @@ func (foo *Foo) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInp } // AssignProperties_From_Foo populates our Foo from the provided source Foo -func (foo *Foo) AssignProperties_From_Foo(source *v20200101s.Foo) error { +func (foo *Foo) AssignProperties_From_Foo(source *storage.Foo) error { // FooName foo.FooName = genruntime.ClonePointerToString(source.FooName) @@ -1067,7 +1086,7 @@ func (foo *Foo) AssignProperties_From_Foo(source *v20200101s.Foo) error { } // AssignProperties_To_Foo populates the provided destination Foo from our Foo -func (foo *Foo) AssignProperties_To_Foo(destination *v20200101s.Foo) error { +func (foo *Foo) AssignProperties_To_Foo(destination *storage.Foo) error { // Create a new property bag propertyBag := genruntime.NewPropertyBag() diff --git a/v2/tools/generator/internal/codegen/testdata/ArmResource/Arm_test_simple_resource_renders_spec_azure_v1api20200101.golden b/v2/tools/generator/internal/codegen/testdata/ArmResource/Arm_test_simple_resource_renders_spec_azure_v1api20200101.golden index 6acf7c3be2..b7babdc250 100644 --- a/v2/tools/generator/internal/codegen/testdata/ArmResource/Arm_test_simple_resource_renders_spec_azure_v1api20200101.golden +++ b/v2/tools/generator/internal/codegen/testdata/ArmResource/Arm_test_simple_resource_renders_spec_azure_v1api20200101.golden @@ -5,8 +5,8 @@ package v1api20200101 import ( "fmt" - v20200101a "github.com/Azure/azure-service-operator/testing/test/v1api20200101/arm" - v20200101s "github.com/Azure/azure-service-operator/testing/test/v1api20200101/storage" + arm "github.com/Azure/azure-service-operator/testing/test/v1api20200101/arm" + storage "github.com/Azure/azure-service-operator/testing/test/v1api20200101/storage" "github.com/Azure/azure-service-operator/v2/internal/reflecthelpers" "github.com/Azure/azure-service-operator/v2/pkg/genruntime" "github.com/Azure/azure-service-operator/v2/pkg/genruntime/conditions" @@ -46,7 +46,7 @@ var _ conversion.Convertible = &FakeResource{} // ConvertFrom populates our FakeResource from the provided hub FakeResource func (resource *FakeResource) ConvertFrom(hub conversion.Hub) error { - source, ok := hub.(*v20200101s.FakeResource) + source, ok := hub.(*storage.FakeResource) if !ok { return fmt.Errorf("expected test/v1api20200101/storage/FakeResource but received %T instead", hub) } @@ -56,7 +56,7 @@ func (resource *FakeResource) ConvertFrom(hub conversion.Hub) error { // ConvertTo populates the provided hub FakeResource from our FakeResource func (resource *FakeResource) ConvertTo(hub conversion.Hub) error { - destination, ok := hub.(*v20200101s.FakeResource) + destination, ok := hub.(*storage.FakeResource) if !ok { return fmt.Errorf("expected test/v1api20200101/storage/FakeResource but received %T instead", hub) } @@ -211,7 +211,7 @@ func (resource *FakeResource) validateWriteOnceProperties(old runtime.Object) (a } // AssignProperties_From_FakeResource populates our FakeResource from the provided source FakeResource -func (resource *FakeResource) AssignProperties_From_FakeResource(source *v20200101s.FakeResource) error { +func (resource *FakeResource) AssignProperties_From_FakeResource(source *storage.FakeResource) error { // ObjectMeta resource.ObjectMeta = *source.ObjectMeta.DeepCopy() @@ -229,13 +229,13 @@ func (resource *FakeResource) AssignProperties_From_FakeResource(source *v202001 } // AssignProperties_To_FakeResource populates the provided destination FakeResource from our FakeResource -func (resource *FakeResource) AssignProperties_To_FakeResource(destination *v20200101s.FakeResource) error { +func (resource *FakeResource) AssignProperties_To_FakeResource(destination *storage.FakeResource) error { // ObjectMeta destination.ObjectMeta = *resource.ObjectMeta.DeepCopy() // Spec - var spec v20200101s.FakeResource_Spec + var spec storage.FakeResource_Spec err := resource.Spec.AssignProperties_To_FakeResource_Spec(&spec) if err != nil { return errors.Wrap(err, "calling AssignProperties_To_FakeResource_Spec() to populate field Spec") @@ -293,7 +293,7 @@ func (resource *FakeResource_Spec) ConvertToARM(resolved genruntime.ConvertToARM if resource == nil { return nil, nil } - result := &FakeResource_Spec{} + result := &arm.FakeResource_Spec{} // Set property "APIVersion": result.APIVersion = resource.APIVersion @@ -308,14 +308,14 @@ func (resource *FakeResource_Spec) ConvertToARM(resolved genruntime.ConvertToARM // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (resource *FakeResource_Spec) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &v20200101a.FakeResource_Spec{} + return &arm.FakeResource_Spec{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (resource *FakeResource_Spec) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(FakeResource_Spec) + typedInput, ok := armInput.(arm.FakeResource_Spec) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected FakeResource_Spec, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.FakeResource_Spec, got %T", armInput) } // Set property "APIVersion": @@ -341,14 +341,14 @@ var _ genruntime.ConvertibleSpec = &FakeResource_Spec{} // ConvertSpecFrom populates our FakeResource_Spec from the provided source func (resource *FakeResource_Spec) ConvertSpecFrom(source genruntime.ConvertibleSpec) error { - src, ok := source.(*v20200101s.FakeResource_Spec) + src, ok := source.(*storage.FakeResource_Spec) if ok { // Populate our instance from source return resource.AssignProperties_From_FakeResource_Spec(src) } // Convert to an intermediate form - src = &v20200101s.FakeResource_Spec{} + src = &storage.FakeResource_Spec{} err := src.ConvertSpecFrom(source) if err != nil { return errors.Wrap(err, "initial step of conversion in ConvertSpecFrom()") @@ -365,14 +365,14 @@ func (resource *FakeResource_Spec) ConvertSpecFrom(source genruntime.Convertible // ConvertSpecTo populates the provided destination from our FakeResource_Spec func (resource *FakeResource_Spec) ConvertSpecTo(destination genruntime.ConvertibleSpec) error { - dst, ok := destination.(*v20200101s.FakeResource_Spec) + dst, ok := destination.(*storage.FakeResource_Spec) if ok { // Populate destination from our instance return resource.AssignProperties_To_FakeResource_Spec(dst) } // Convert to an intermediate form - dst = &v20200101s.FakeResource_Spec{} + dst = &storage.FakeResource_Spec{} err := resource.AssignProperties_To_FakeResource_Spec(dst) if err != nil { return errors.Wrap(err, "initial step of conversion in ConvertSpecTo()") @@ -388,11 +388,12 @@ func (resource *FakeResource_Spec) ConvertSpecTo(destination genruntime.Converti } // AssignProperties_From_FakeResource_Spec populates our FakeResource_Spec from the provided source FakeResource_Spec -func (resource *FakeResource_Spec) AssignProperties_From_FakeResource_Spec(source *v20200101s.FakeResource_Spec) error { +func (resource *FakeResource_Spec) AssignProperties_From_FakeResource_Spec(source *storage.FakeResource_Spec) error { // APIVersion if source.APIVersion != nil { - resource.APIVersion = FakeResource_APIVersion_Spec(*source.APIVersion) + apiVersion := *source.APIVersion + resource.APIVersion = genruntime.ToEnum(apiVersion, fakeResource_APIVersion_Spec_Values) } else { resource.APIVersion = "" } @@ -410,7 +411,8 @@ func (resource *FakeResource_Spec) AssignProperties_From_FakeResource_Spec(sourc // Type if source.Type != nil { - resource.Type = FakeResource_Type_Spec(*source.Type) + typeVar := *source.Type + resource.Type = genruntime.ToEnum(typeVar, fakeResource_Type_Spec_Values) } else { resource.Type = "" } @@ -420,7 +422,7 @@ func (resource *FakeResource_Spec) AssignProperties_From_FakeResource_Spec(sourc } // AssignProperties_To_FakeResource_Spec populates the provided destination FakeResource_Spec from our FakeResource_Spec -func (resource *FakeResource_Spec) AssignProperties_To_FakeResource_Spec(destination *v20200101s.FakeResource_Spec) error { +func (resource *FakeResource_Spec) AssignProperties_To_FakeResource_Spec(destination *storage.FakeResource_Spec) error { // Create a new property bag propertyBag := genruntime.NewPropertyBag() @@ -470,11 +472,21 @@ type FakeResource_APIVersion_Spec string const FakeResource_APIVersion_Spec_20200601 = FakeResource_APIVersion_Spec("2020-06-01") +// Mapping from string to FakeResource_APIVersion_Spec +var fakeResource_APIVersion_Spec_Values = map[string]FakeResource_APIVersion_Spec{ + "2020-06-01": FakeResource_APIVersion_Spec_20200601, +} + // +kubebuilder:validation:Enum={"Microsoft.Azure/FakeResource"} type FakeResource_Type_Spec string const FakeResource_Type_Spec_MicrosoftAzureFakeResource = FakeResource_Type_Spec("Microsoft.Azure/FakeResource") +// Mapping from string to FakeResource_Type_Spec +var fakeResource_Type_Spec_Values = map[string]FakeResource_Type_Spec{ + "microsoft.azure/fakeresource": FakeResource_Type_Spec_MicrosoftAzureFakeResource, +} + func init() { SchemeBuilder.Register(&FakeResource{}, &FakeResourceList{}) } diff --git a/v2/tools/generator/internal/codegen/testdata/EmbeddedTypes/Embedded_type_simple_resource_v1api20200101.golden b/v2/tools/generator/internal/codegen/testdata/EmbeddedTypes/Embedded_type_simple_resource_v1api20200101.golden index daee86c2c8..04c0aa682d 100644 --- a/v2/tools/generator/internal/codegen/testdata/EmbeddedTypes/Embedded_type_simple_resource_v1api20200101.golden +++ b/v2/tools/generator/internal/codegen/testdata/EmbeddedTypes/Embedded_type_simple_resource_v1api20200101.golden @@ -5,8 +5,8 @@ package v1api20200101 import ( "fmt" - v20200101a "github.com/Azure/azure-service-operator/testing/test/v1api20200101/arm" - v20200101s "github.com/Azure/azure-service-operator/testing/test/v1api20200101/storage" + arm "github.com/Azure/azure-service-operator/testing/test/v1api20200101/arm" + storage "github.com/Azure/azure-service-operator/testing/test/v1api20200101/storage" "github.com/Azure/azure-service-operator/v2/internal/reflecthelpers" "github.com/Azure/azure-service-operator/v2/pkg/genruntime" "github.com/Azure/azure-service-operator/v2/pkg/genruntime/conditions" @@ -46,7 +46,7 @@ var _ conversion.Convertible = &FakeResource{} // ConvertFrom populates our FakeResource from the provided hub FakeResource func (resource *FakeResource) ConvertFrom(hub conversion.Hub) error { - source, ok := hub.(*v20200101s.FakeResource) + source, ok := hub.(*storage.FakeResource) if !ok { return fmt.Errorf("expected test/v1api20200101/storage/FakeResource but received %T instead", hub) } @@ -56,7 +56,7 @@ func (resource *FakeResource) ConvertFrom(hub conversion.Hub) error { // ConvertTo populates the provided hub FakeResource from our FakeResource func (resource *FakeResource) ConvertTo(hub conversion.Hub) error { - destination, ok := hub.(*v20200101s.FakeResource) + destination, ok := hub.(*storage.FakeResource) if !ok { return fmt.Errorf("expected test/v1api20200101/storage/FakeResource but received %T instead", hub) } @@ -211,7 +211,7 @@ func (resource *FakeResource) validateWriteOnceProperties(old runtime.Object) (a } // AssignProperties_From_FakeResource populates our FakeResource from the provided source FakeResource -func (resource *FakeResource) AssignProperties_From_FakeResource(source *v20200101s.FakeResource) error { +func (resource *FakeResource) AssignProperties_From_FakeResource(source *storage.FakeResource) error { // ObjectMeta resource.ObjectMeta = *source.ObjectMeta.DeepCopy() @@ -229,13 +229,13 @@ func (resource *FakeResource) AssignProperties_From_FakeResource(source *v202001 } // AssignProperties_To_FakeResource populates the provided destination FakeResource from our FakeResource -func (resource *FakeResource) AssignProperties_To_FakeResource(destination *v20200101s.FakeResource) error { +func (resource *FakeResource) AssignProperties_To_FakeResource(destination *storage.FakeResource) error { // ObjectMeta destination.ObjectMeta = *resource.ObjectMeta.DeepCopy() // Spec - var spec v20200101s.FakeResource_Spec + var spec storage.FakeResource_Spec err := resource.Spec.AssignProperties_To_FakeResource_Spec(&spec) if err != nil { return errors.Wrap(err, "calling AssignProperties_To_FakeResource_Spec() to populate field Spec") @@ -303,7 +303,7 @@ func (resource *FakeResource_Spec) ConvertToARM(resolved genruntime.ConvertToARM if resource == nil { return nil, nil } - result := &FakeResource_Spec{} + result := &arm.FakeResource_Spec{} // Set property "APIVersion": result.APIVersion = resource.APIVersion @@ -320,7 +320,7 @@ func (resource *FakeResource_Spec) ConvertToARM(resolved genruntime.ConvertToARM if err != nil { return nil, err } - foo := *foo_ARM.(*v20200101a.Foo) + foo := *foo_ARM.(*arm.Foo) result.Foo = &foo } @@ -333,7 +333,7 @@ func (resource *FakeResource_Spec) ConvertToARM(resolved genruntime.ConvertToARM if err != nil { return nil, err } - optionalFoo := *optionalFoo_ARM.(*v20200101a.Foo) + optionalFoo := *optionalFoo_ARM.(*arm.Foo) result.OptionalFoo = &optionalFoo } @@ -344,14 +344,14 @@ func (resource *FakeResource_Spec) ConvertToARM(resolved genruntime.ConvertToARM // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (resource *FakeResource_Spec) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &v20200101a.FakeResource_Spec{} + return &arm.FakeResource_Spec{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (resource *FakeResource_Spec) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(FakeResource_Spec) + typedInput, ok := armInput.(arm.FakeResource_Spec) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected FakeResource_Spec, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.FakeResource_Spec, got %T", armInput) } // Set property "APIVersion": @@ -405,14 +405,14 @@ var _ genruntime.ConvertibleSpec = &FakeResource_Spec{} // ConvertSpecFrom populates our FakeResource_Spec from the provided source func (resource *FakeResource_Spec) ConvertSpecFrom(source genruntime.ConvertibleSpec) error { - src, ok := source.(*v20200101s.FakeResource_Spec) + src, ok := source.(*storage.FakeResource_Spec) if ok { // Populate our instance from source return resource.AssignProperties_From_FakeResource_Spec(src) } // Convert to an intermediate form - src = &v20200101s.FakeResource_Spec{} + src = &storage.FakeResource_Spec{} err := src.ConvertSpecFrom(source) if err != nil { return errors.Wrap(err, "initial step of conversion in ConvertSpecFrom()") @@ -429,14 +429,14 @@ func (resource *FakeResource_Spec) ConvertSpecFrom(source genruntime.Convertible // ConvertSpecTo populates the provided destination from our FakeResource_Spec func (resource *FakeResource_Spec) ConvertSpecTo(destination genruntime.ConvertibleSpec) error { - dst, ok := destination.(*v20200101s.FakeResource_Spec) + dst, ok := destination.(*storage.FakeResource_Spec) if ok { // Populate destination from our instance return resource.AssignProperties_To_FakeResource_Spec(dst) } // Convert to an intermediate form - dst = &v20200101s.FakeResource_Spec{} + dst = &storage.FakeResource_Spec{} err := resource.AssignProperties_To_FakeResource_Spec(dst) if err != nil { return errors.Wrap(err, "initial step of conversion in ConvertSpecTo()") @@ -452,11 +452,12 @@ func (resource *FakeResource_Spec) ConvertSpecTo(destination genruntime.Converti } // AssignProperties_From_FakeResource_Spec populates our FakeResource_Spec from the provided source FakeResource_Spec -func (resource *FakeResource_Spec) AssignProperties_From_FakeResource_Spec(source *v20200101s.FakeResource_Spec) error { +func (resource *FakeResource_Spec) AssignProperties_From_FakeResource_Spec(source *storage.FakeResource_Spec) error { // APIVersion if source.APIVersion != nil { - resource.APIVersion = FakeResource_APIVersion_Spec(*source.APIVersion) + apiVersion := *source.APIVersion + resource.APIVersion = genruntime.ToEnum(apiVersion, fakeResource_APIVersion_Spec_Values) } else { resource.APIVersion = "" } @@ -466,8 +467,9 @@ func (resource *FakeResource_Spec) AssignProperties_From_FakeResource_Spec(sourc // Color if source.Color != nil { - color := FakeResource_Color_Spec(*source.Color) - resource.Color = &color + color := *source.Color + colorTemp := genruntime.ToEnum(color, fakeResource_Color_Spec_Values) + resource.Color = &colorTemp } else { resource.Color = nil } @@ -506,7 +508,8 @@ func (resource *FakeResource_Spec) AssignProperties_From_FakeResource_Spec(sourc // Type if source.Type != nil { - resource.Type = FakeResource_Type_Spec(*source.Type) + typeVar := *source.Type + resource.Type = genruntime.ToEnum(typeVar, fakeResource_Type_Spec_Values) } else { resource.Type = "" } @@ -516,7 +519,7 @@ func (resource *FakeResource_Spec) AssignProperties_From_FakeResource_Spec(sourc } // AssignProperties_To_FakeResource_Spec populates the provided destination FakeResource_Spec from our FakeResource_Spec -func (resource *FakeResource_Spec) AssignProperties_To_FakeResource_Spec(destination *v20200101s.FakeResource_Spec) error { +func (resource *FakeResource_Spec) AssignProperties_To_FakeResource_Spec(destination *storage.FakeResource_Spec) error { // Create a new property bag propertyBag := genruntime.NewPropertyBag() @@ -537,7 +540,7 @@ func (resource *FakeResource_Spec) AssignProperties_To_FakeResource_Spec(destina // Foo if resource.Foo != nil { - var foo v20200101s.Foo + var foo storage.Foo err := resource.Foo.AssignProperties_To_Foo(&foo) if err != nil { return errors.Wrap(err, "calling AssignProperties_To_Foo() to populate field Foo") @@ -549,7 +552,7 @@ func (resource *FakeResource_Spec) AssignProperties_To_FakeResource_Spec(destina // OptionalFoo if resource.OptionalFoo != nil { - var optionalFoo v20200101s.Foo + var optionalFoo storage.Foo err := resource.OptionalFoo.AssignProperties_To_Foo(&optionalFoo) if err != nil { return errors.Wrap(err, "calling AssignProperties_To_Foo() to populate field OptionalFoo") @@ -604,7 +607,7 @@ func (testType *EmbeddedTestType) ConvertToARM(resolved genruntime.ConvertToARMR if testType == nil { return nil, nil } - result := &EmbeddedTestType{} + result := &arm.EmbeddedTestType{} // Set property "FancyProp": result.FancyProp = testType.FancyProp @@ -613,14 +616,14 @@ func (testType *EmbeddedTestType) ConvertToARM(resolved genruntime.ConvertToARMR // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (testType *EmbeddedTestType) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &v20200101a.EmbeddedTestType{} + return &arm.EmbeddedTestType{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (testType *EmbeddedTestType) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(EmbeddedTestType) + typedInput, ok := armInput.(arm.EmbeddedTestType) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected EmbeddedTestType, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.EmbeddedTestType, got %T", armInput) } // Set property "FancyProp": @@ -631,7 +634,7 @@ func (testType *EmbeddedTestType) PopulateFromARM(owner genruntime.ArbitraryOwne } // AssignProperties_From_EmbeddedTestType populates our EmbeddedTestType from the provided source EmbeddedTestType -func (testType *EmbeddedTestType) AssignProperties_From_EmbeddedTestType(source *v20200101s.EmbeddedTestType) error { +func (testType *EmbeddedTestType) AssignProperties_From_EmbeddedTestType(source *storage.EmbeddedTestType) error { // FancyProp testType.FancyProp = genruntime.GetOptionalIntValue(source.FancyProp) @@ -641,7 +644,7 @@ func (testType *EmbeddedTestType) AssignProperties_From_EmbeddedTestType(source } // AssignProperties_To_EmbeddedTestType populates the provided destination EmbeddedTestType from our EmbeddedTestType -func (testType *EmbeddedTestType) AssignProperties_To_EmbeddedTestType(destination *v20200101s.EmbeddedTestType) error { +func (testType *EmbeddedTestType) AssignProperties_To_EmbeddedTestType(destination *storage.EmbeddedTestType) error { // Create a new property bag propertyBag := genruntime.NewPropertyBag() @@ -665,6 +668,11 @@ type FakeResource_APIVersion_Spec string const FakeResource_APIVersion_Spec_20200601 = FakeResource_APIVersion_Spec("2020-06-01") +// Mapping from string to FakeResource_APIVersion_Spec +var fakeResource_APIVersion_Spec_Values = map[string]FakeResource_APIVersion_Spec{ + "2020-06-01": FakeResource_APIVersion_Spec_20200601, +} + // +kubebuilder:validation:Enum={"blue","green","red"} type FakeResource_Color_Spec string @@ -674,11 +682,23 @@ const ( FakeResource_Color_Spec_Red = FakeResource_Color_Spec("red") ) +// Mapping from string to FakeResource_Color_Spec +var fakeResource_Color_Spec_Values = map[string]FakeResource_Color_Spec{ + "blue": FakeResource_Color_Spec_Blue, + "green": FakeResource_Color_Spec_Green, + "red": FakeResource_Color_Spec_Red, +} + // +kubebuilder:validation:Enum={"Microsoft.Azure/FakeResource"} type FakeResource_Type_Spec string const FakeResource_Type_Spec_MicrosoftAzureFakeResource = FakeResource_Type_Spec("Microsoft.Azure/FakeResource") +// Mapping from string to FakeResource_Type_Spec +var fakeResource_Type_Spec_Values = map[string]FakeResource_Type_Spec{ + "microsoft.azure/fakeresource": FakeResource_Type_Spec_MicrosoftAzureFakeResource, +} + // Generated from: https://test.test/schemas/2020-01-01/test.json#/definitions/Foo type Foo struct { EmbeddedTestType `json:",inline,omitempty"` @@ -692,7 +712,7 @@ func (foo *Foo) ConvertToARM(resolved genruntime.ConvertToARMResolvedDetails) (i if foo == nil { return nil, nil } - result := &Foo{} + result := &arm.Foo{} // Set property "Name": if foo.Name != nil { @@ -704,14 +724,14 @@ func (foo *Foo) ConvertToARM(resolved genruntime.ConvertToARMResolvedDetails) (i // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (foo *Foo) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &v20200101a.Foo{} + return &arm.Foo{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (foo *Foo) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(Foo) + typedInput, ok := armInput.(arm.Foo) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected Foo, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.Foo, got %T", armInput) } // Set property "Name": @@ -725,7 +745,7 @@ func (foo *Foo) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInp } // AssignProperties_From_Foo populates our Foo from the provided source Foo -func (foo *Foo) AssignProperties_From_Foo(source *v20200101s.Foo) error { +func (foo *Foo) AssignProperties_From_Foo(source *storage.Foo) error { // Name foo.Name = genruntime.ClonePointerToString(source.Name) @@ -735,7 +755,7 @@ func (foo *Foo) AssignProperties_From_Foo(source *v20200101s.Foo) error { } // AssignProperties_To_Foo populates the provided destination Foo from our Foo -func (foo *Foo) AssignProperties_To_Foo(destination *v20200101s.Foo) error { +func (foo *Foo) AssignProperties_To_Foo(destination *storage.Foo) error { // Create a new property bag propertyBag := genruntime.NewPropertyBag() diff --git a/v2/tools/generator/internal/codegen/testdata/EnumNames/Multi_valued_enum_name_v1api20200101.golden b/v2/tools/generator/internal/codegen/testdata/EnumNames/Multi_valued_enum_name_v1api20200101.golden index df6f29ff1b..f65260ab8c 100644 --- a/v2/tools/generator/internal/codegen/testdata/EnumNames/Multi_valued_enum_name_v1api20200101.golden +++ b/v2/tools/generator/internal/codegen/testdata/EnumNames/Multi_valued_enum_name_v1api20200101.golden @@ -5,8 +5,8 @@ package v1api20200101 import ( "fmt" - v20200101a "github.com/Azure/azure-service-operator/testing/test/v1api20200101/arm" - v20200101s "github.com/Azure/azure-service-operator/testing/test/v1api20200101/storage" + arm "github.com/Azure/azure-service-operator/testing/test/v1api20200101/arm" + storage "github.com/Azure/azure-service-operator/testing/test/v1api20200101/storage" "github.com/Azure/azure-service-operator/v2/internal/reflecthelpers" "github.com/Azure/azure-service-operator/v2/pkg/genruntime" "github.com/Azure/azure-service-operator/v2/pkg/genruntime/conditions" @@ -46,7 +46,7 @@ var _ conversion.Convertible = &AResource{} // ConvertFrom populates our AResource from the provided hub AResource func (resource *AResource) ConvertFrom(hub conversion.Hub) error { - source, ok := hub.(*v20200101s.AResource) + source, ok := hub.(*storage.AResource) if !ok { return fmt.Errorf("expected test/v1api20200101/storage/AResource but received %T instead", hub) } @@ -56,7 +56,7 @@ func (resource *AResource) ConvertFrom(hub conversion.Hub) error { // ConvertTo populates the provided hub AResource from our AResource func (resource *AResource) ConvertTo(hub conversion.Hub) error { - destination, ok := hub.(*v20200101s.AResource) + destination, ok := hub.(*storage.AResource) if !ok { return fmt.Errorf("expected test/v1api20200101/storage/AResource but received %T instead", hub) } @@ -211,7 +211,7 @@ func (resource *AResource) validateWriteOnceProperties(old runtime.Object) (admi } // AssignProperties_From_AResource populates our AResource from the provided source AResource -func (resource *AResource) AssignProperties_From_AResource(source *v20200101s.AResource) error { +func (resource *AResource) AssignProperties_From_AResource(source *storage.AResource) error { // ObjectMeta resource.ObjectMeta = *source.ObjectMeta.DeepCopy() @@ -229,13 +229,13 @@ func (resource *AResource) AssignProperties_From_AResource(source *v20200101s.AR } // AssignProperties_To_AResource populates the provided destination AResource from our AResource -func (resource *AResource) AssignProperties_To_AResource(destination *v20200101s.AResource) error { +func (resource *AResource) AssignProperties_To_AResource(destination *storage.AResource) error { // ObjectMeta destination.ObjectMeta = *resource.ObjectMeta.DeepCopy() // Spec - var spec v20200101s.AResource_Spec + var spec storage.AResource_Spec err := resource.Spec.AssignProperties_To_AResource_Spec(&spec) if err != nil { return errors.Wrap(err, "calling AssignProperties_To_AResource_Spec() to populate field Spec") @@ -293,7 +293,7 @@ func (resource *AResource_Spec) ConvertToARM(resolved genruntime.ConvertToARMRes if resource == nil { return nil, nil } - result := &AResource_Spec{} + result := &arm.AResource_Spec{} // Set property "APIVersion": result.APIVersion = resource.APIVersion @@ -308,14 +308,14 @@ func (resource *AResource_Spec) ConvertToARM(resolved genruntime.ConvertToARMRes // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (resource *AResource_Spec) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &v20200101a.AResource_Spec{} + return &arm.AResource_Spec{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (resource *AResource_Spec) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(AResource_Spec) + typedInput, ok := armInput.(arm.AResource_Spec) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected AResource_Spec, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.AResource_Spec, got %T", armInput) } // Set property "APIVersion": @@ -341,14 +341,14 @@ var _ genruntime.ConvertibleSpec = &AResource_Spec{} // ConvertSpecFrom populates our AResource_Spec from the provided source func (resource *AResource_Spec) ConvertSpecFrom(source genruntime.ConvertibleSpec) error { - src, ok := source.(*v20200101s.AResource_Spec) + src, ok := source.(*storage.AResource_Spec) if ok { // Populate our instance from source return resource.AssignProperties_From_AResource_Spec(src) } // Convert to an intermediate form - src = &v20200101s.AResource_Spec{} + src = &storage.AResource_Spec{} err := src.ConvertSpecFrom(source) if err != nil { return errors.Wrap(err, "initial step of conversion in ConvertSpecFrom()") @@ -365,14 +365,14 @@ func (resource *AResource_Spec) ConvertSpecFrom(source genruntime.ConvertibleSpe // ConvertSpecTo populates the provided destination from our AResource_Spec func (resource *AResource_Spec) ConvertSpecTo(destination genruntime.ConvertibleSpec) error { - dst, ok := destination.(*v20200101s.AResource_Spec) + dst, ok := destination.(*storage.AResource_Spec) if ok { // Populate destination from our instance return resource.AssignProperties_To_AResource_Spec(dst) } // Convert to an intermediate form - dst = &v20200101s.AResource_Spec{} + dst = &storage.AResource_Spec{} err := resource.AssignProperties_To_AResource_Spec(dst) if err != nil { return errors.Wrap(err, "initial step of conversion in ConvertSpecTo()") @@ -388,11 +388,12 @@ func (resource *AResource_Spec) ConvertSpecTo(destination genruntime.Convertible } // AssignProperties_From_AResource_Spec populates our AResource_Spec from the provided source AResource_Spec -func (resource *AResource_Spec) AssignProperties_From_AResource_Spec(source *v20200101s.AResource_Spec) error { +func (resource *AResource_Spec) AssignProperties_From_AResource_Spec(source *storage.AResource_Spec) error { // APIVersion if source.APIVersion != nil { - resource.APIVersion = AResource_APIVersion_Spec(*source.APIVersion) + apiVersion := *source.APIVersion + resource.APIVersion = genruntime.ToEnum(apiVersion, aResource_APIVersion_Spec_Values) } else { resource.APIVersion = "" } @@ -411,7 +412,8 @@ func (resource *AResource_Spec) AssignProperties_From_AResource_Spec(source *v20 // Type if source.Type != nil { - resource.Type = AResource_Type_Spec(*source.Type) + typeVar := *source.Type + resource.Type = genruntime.ToEnum(typeVar, aResource_Type_Spec_Values) } else { resource.Type = "" } @@ -421,7 +423,7 @@ func (resource *AResource_Spec) AssignProperties_From_AResource_Spec(source *v20 } // AssignProperties_To_AResource_Spec populates the provided destination AResource_Spec from our AResource_Spec -func (resource *AResource_Spec) AssignProperties_To_AResource_Spec(destination *v20200101s.AResource_Spec) error { +func (resource *AResource_Spec) AssignProperties_To_AResource_Spec(destination *storage.AResource_Spec) error { // Create a new property bag propertyBag := genruntime.NewPropertyBag() @@ -474,6 +476,11 @@ type AResource_APIVersion_Spec string const AResource_APIVersion_Spec_20200601 = AResource_APIVersion_Spec("2020-06-01") +// Mapping from string to AResource_APIVersion_Spec +var aResource_APIVersion_Spec_Values = map[string]AResource_APIVersion_Spec{ + "2020-06-01": AResource_APIVersion_Spec_20200601, +} + // +kubebuilder:validation:Enum={"one","three","two"} type AResource_Name_Spec string @@ -483,11 +490,23 @@ const ( AResource_Name_Spec_Two = AResource_Name_Spec("two") ) +// Mapping from string to AResource_Name_Spec +var aResource_Name_Spec_Values = map[string]AResource_Name_Spec{ + "one": AResource_Name_Spec_One, + "three": AResource_Name_Spec_Three, + "two": AResource_Name_Spec_Two, +} + // +kubebuilder:validation:Enum={"Microsoft.Azure/AResource"} type AResource_Type_Spec string const AResource_Type_Spec_MicrosoftAzureAResource = AResource_Type_Spec("Microsoft.Azure/AResource") +// Mapping from string to AResource_Type_Spec +var aResource_Type_Spec_Values = map[string]AResource_Type_Spec{ + "microsoft.azure/aresource": AResource_Type_Spec_MicrosoftAzureAResource, +} + func init() { SchemeBuilder.Register(&AResource{}, &AResourceList{}) } diff --git a/v2/tools/generator/internal/codegen/testdata/EnumNames/Single_valued_enum_name_v1api20200101.golden b/v2/tools/generator/internal/codegen/testdata/EnumNames/Single_valued_enum_name_v1api20200101.golden index 74e1321d28..de1f71b992 100644 --- a/v2/tools/generator/internal/codegen/testdata/EnumNames/Single_valued_enum_name_v1api20200101.golden +++ b/v2/tools/generator/internal/codegen/testdata/EnumNames/Single_valued_enum_name_v1api20200101.golden @@ -5,8 +5,8 @@ package v1api20200101 import ( "fmt" - v20200101a "github.com/Azure/azure-service-operator/testing/test/v1api20200101/arm" - v20200101s "github.com/Azure/azure-service-operator/testing/test/v1api20200101/storage" + arm "github.com/Azure/azure-service-operator/testing/test/v1api20200101/arm" + storage "github.com/Azure/azure-service-operator/testing/test/v1api20200101/storage" "github.com/Azure/azure-service-operator/v2/internal/reflecthelpers" "github.com/Azure/azure-service-operator/v2/pkg/genruntime" "github.com/Azure/azure-service-operator/v2/pkg/genruntime/conditions" @@ -46,7 +46,7 @@ var _ conversion.Convertible = &AResource{} // ConvertFrom populates our AResource from the provided hub AResource func (resource *AResource) ConvertFrom(hub conversion.Hub) error { - source, ok := hub.(*v20200101s.AResource) + source, ok := hub.(*storage.AResource) if !ok { return fmt.Errorf("expected test/v1api20200101/storage/AResource but received %T instead", hub) } @@ -56,7 +56,7 @@ func (resource *AResource) ConvertFrom(hub conversion.Hub) error { // ConvertTo populates the provided hub AResource from our AResource func (resource *AResource) ConvertTo(hub conversion.Hub) error { - destination, ok := hub.(*v20200101s.AResource) + destination, ok := hub.(*storage.AResource) if !ok { return fmt.Errorf("expected test/v1api20200101/storage/AResource but received %T instead", hub) } @@ -204,7 +204,7 @@ func (resource *AResource) validateWriteOnceProperties(old runtime.Object) (admi } // AssignProperties_From_AResource populates our AResource from the provided source AResource -func (resource *AResource) AssignProperties_From_AResource(source *v20200101s.AResource) error { +func (resource *AResource) AssignProperties_From_AResource(source *storage.AResource) error { // ObjectMeta resource.ObjectMeta = *source.ObjectMeta.DeepCopy() @@ -222,13 +222,13 @@ func (resource *AResource) AssignProperties_From_AResource(source *v20200101s.AR } // AssignProperties_To_AResource populates the provided destination AResource from our AResource -func (resource *AResource) AssignProperties_To_AResource(destination *v20200101s.AResource) error { +func (resource *AResource) AssignProperties_To_AResource(destination *storage.AResource) error { // ObjectMeta destination.ObjectMeta = *resource.ObjectMeta.DeepCopy() // Spec - var spec v20200101s.AResource_Spec + var spec storage.AResource_Spec err := resource.Spec.AssignProperties_To_AResource_Spec(&spec) if err != nil { return errors.Wrap(err, "calling AssignProperties_To_AResource_Spec() to populate field Spec") @@ -282,7 +282,7 @@ func (resource *AResource_Spec) ConvertToARM(resolved genruntime.ConvertToARMRes if resource == nil { return nil, nil } - result := &AResource_Spec{} + result := &arm.AResource_Spec{} // Set property "APIVersion": result.APIVersion = resource.APIVersion @@ -297,14 +297,14 @@ func (resource *AResource_Spec) ConvertToARM(resolved genruntime.ConvertToARMRes // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (resource *AResource_Spec) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &v20200101a.AResource_Spec{} + return &arm.AResource_Spec{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (resource *AResource_Spec) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(AResource_Spec) + typedInput, ok := armInput.(arm.AResource_Spec) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected AResource_Spec, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.AResource_Spec, got %T", armInput) } // Set property "APIVersion": @@ -327,14 +327,14 @@ var _ genruntime.ConvertibleSpec = &AResource_Spec{} // ConvertSpecFrom populates our AResource_Spec from the provided source func (resource *AResource_Spec) ConvertSpecFrom(source genruntime.ConvertibleSpec) error { - src, ok := source.(*v20200101s.AResource_Spec) + src, ok := source.(*storage.AResource_Spec) if ok { // Populate our instance from source return resource.AssignProperties_From_AResource_Spec(src) } // Convert to an intermediate form - src = &v20200101s.AResource_Spec{} + src = &storage.AResource_Spec{} err := src.ConvertSpecFrom(source) if err != nil { return errors.Wrap(err, "initial step of conversion in ConvertSpecFrom()") @@ -351,14 +351,14 @@ func (resource *AResource_Spec) ConvertSpecFrom(source genruntime.ConvertibleSpe // ConvertSpecTo populates the provided destination from our AResource_Spec func (resource *AResource_Spec) ConvertSpecTo(destination genruntime.ConvertibleSpec) error { - dst, ok := destination.(*v20200101s.AResource_Spec) + dst, ok := destination.(*storage.AResource_Spec) if ok { // Populate destination from our instance return resource.AssignProperties_To_AResource_Spec(dst) } // Convert to an intermediate form - dst = &v20200101s.AResource_Spec{} + dst = &storage.AResource_Spec{} err := resource.AssignProperties_To_AResource_Spec(dst) if err != nil { return errors.Wrap(err, "initial step of conversion in ConvertSpecTo()") @@ -374,11 +374,12 @@ func (resource *AResource_Spec) ConvertSpecTo(destination genruntime.Convertible } // AssignProperties_From_AResource_Spec populates our AResource_Spec from the provided source AResource_Spec -func (resource *AResource_Spec) AssignProperties_From_AResource_Spec(source *v20200101s.AResource_Spec) error { +func (resource *AResource_Spec) AssignProperties_From_AResource_Spec(source *storage.AResource_Spec) error { // APIVersion if source.APIVersion != nil { - resource.APIVersion = AResource_APIVersion_Spec(*source.APIVersion) + apiVersion := *source.APIVersion + resource.APIVersion = genruntime.ToEnum(apiVersion, aResource_APIVersion_Spec_Values) } else { resource.APIVersion = "" } @@ -393,7 +394,8 @@ func (resource *AResource_Spec) AssignProperties_From_AResource_Spec(source *v20 // Type if source.Type != nil { - resource.Type = AResource_Type_Spec(*source.Type) + typeVar := *source.Type + resource.Type = genruntime.ToEnum(typeVar, aResource_Type_Spec_Values) } else { resource.Type = "" } @@ -403,7 +405,7 @@ func (resource *AResource_Spec) AssignProperties_From_AResource_Spec(source *v20 } // AssignProperties_To_AResource_Spec populates the provided destination AResource_Spec from our AResource_Spec -func (resource *AResource_Spec) AssignProperties_To_AResource_Spec(destination *v20200101s.AResource_Spec) error { +func (resource *AResource_Spec) AssignProperties_To_AResource_Spec(destination *storage.AResource_Spec) error { // Create a new property bag propertyBag := genruntime.NewPropertyBag() @@ -447,11 +449,21 @@ type AResource_APIVersion_Spec string const AResource_APIVersion_Spec_20200601 = AResource_APIVersion_Spec("2020-06-01") +// Mapping from string to AResource_APIVersion_Spec +var aResource_APIVersion_Spec_Values = map[string]AResource_APIVersion_Spec{ + "2020-06-01": AResource_APIVersion_Spec_20200601, +} + // +kubebuilder:validation:Enum={"Microsoft.Azure/AResource"} type AResource_Type_Spec string const AResource_Type_Spec_MicrosoftAzureAResource = AResource_Type_Spec("Microsoft.Azure/AResource") +// Mapping from string to AResource_Type_Spec +var aResource_Type_Spec_Values = map[string]AResource_Type_Spec{ + "microsoft.azure/aresource": AResource_Type_Spec_MicrosoftAzureAResource, +} + func init() { SchemeBuilder.Register(&AResource{}, &AResourceList{}) } From 0c4ac0a97eca5d270ecd4ba692152fbd320390a5 Mon Sep 17 00:00:00 2001 From: Bevan Arps Date: Mon, 10 Jun 2024 10:43:34 +1200 Subject: [PATCH 14/15] Update api files --- .../prometheus_rule_group_spec_types_gen.go} | 30 +- ...ometheus_rule_group_spec_types_gen_test.go | 388 +++++++++++++++ ...prometheus_rule_group_status_types_gen.go} | 64 +-- ...etheus_rule_group_status_types_gen_test.go | 471 ++++++++++++++++++ .../v1api20230301/arm/structure.txt | 61 +++ ...heus_rule_group_spec_arm_types_gen_test.go | 388 --------------- ...us_rule_group_status_arm_types_gen_test.go | 466 ----------------- .../prometheus_rule_group_types_gen.go | 105 ++-- .../v1api20230301/structure.txt | 171 ++----- .../account_status_arm_types_gen_test.go | 442 ---------------- .../v1api20230403/account_types_gen.go | 73 ++- .../account_spec_types_gen.go} | 12 +- .../account_spec_types_gen_test.go} | 36 +- .../account_status_types_gen.go} | 68 +-- .../arm/account_status_types_gen_test.go | 442 ++++++++++++++++ .../monitor/v1api20230403/arm/structure.txt | 32 ++ v2/api/monitor/v1api20230403/structure.txt | 141 ++---- 17 files changed, 1691 insertions(+), 1699 deletions(-) rename v2/api/alertsmanagement/v1api20230301/{prometheus_rule_group_spec_arm_types_gen.go => arm/prometheus_rule_group_spec_types_gen.go} (79%) create mode 100644 v2/api/alertsmanagement/v1api20230301/arm/prometheus_rule_group_spec_types_gen_test.go rename v2/api/alertsmanagement/v1api20230301/{prometheus_rule_group_status_arm_types_gen.go => arm/prometheus_rule_group_status_types_gen.go} (63%) create mode 100644 v2/api/alertsmanagement/v1api20230301/arm/prometheus_rule_group_status_types_gen_test.go create mode 100644 v2/api/alertsmanagement/v1api20230301/arm/structure.txt delete mode 100644 v2/api/alertsmanagement/v1api20230301/prometheus_rule_group_spec_arm_types_gen_test.go delete mode 100644 v2/api/alertsmanagement/v1api20230301/prometheus_rule_group_status_arm_types_gen_test.go delete mode 100644 v2/api/monitor/v1api20230403/account_status_arm_types_gen_test.go rename v2/api/monitor/v1api20230403/{account_spec_arm_types_gen.go => arm/account_spec_types_gen.go} (73%) rename v2/api/monitor/v1api20230403/{account_spec_arm_types_gen_test.go => arm/account_spec_types_gen_test.go} (51%) rename v2/api/monitor/v1api20230403/{account_status_arm_types_gen.go => arm/account_status_types_gen.go} (55%) create mode 100644 v2/api/monitor/v1api20230403/arm/account_status_types_gen_test.go create mode 100644 v2/api/monitor/v1api20230403/arm/structure.txt diff --git a/v2/api/alertsmanagement/v1api20230301/prometheus_rule_group_spec_arm_types_gen.go b/v2/api/alertsmanagement/v1api20230301/arm/prometheus_rule_group_spec_types_gen.go similarity index 79% rename from v2/api/alertsmanagement/v1api20230301/prometheus_rule_group_spec_arm_types_gen.go rename to v2/api/alertsmanagement/v1api20230301/arm/prometheus_rule_group_spec_types_gen.go index fc68e32337..88ed4192a3 100644 --- a/v2/api/alertsmanagement/v1api20230301/prometheus_rule_group_spec_arm_types_gen.go +++ b/v2/api/alertsmanagement/v1api20230301/arm/prometheus_rule_group_spec_types_gen.go @@ -1,41 +1,41 @@ // Code generated by azure-service-operator-codegen. DO NOT EDIT. // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -package v1api20230301 +package arm import "github.com/Azure/azure-service-operator/v2/pkg/genruntime" -type PrometheusRuleGroup_Spec_ARM struct { +type PrometheusRuleGroup_Spec struct { // Location: The geo-location where the resource lives Location *string `json:"location,omitempty"` Name string `json:"name,omitempty"` // Properties: The Prometheus rule group properties of the resource. - Properties *PrometheusRuleGroupProperties_ARM `json:"properties,omitempty"` + Properties *PrometheusRuleGroupProperties `json:"properties,omitempty"` // Tags: Resource tags. Tags map[string]string `json:"tags,omitempty"` } -var _ genruntime.ARMResourceSpec = &PrometheusRuleGroup_Spec_ARM{} +var _ genruntime.ARMResourceSpec = &PrometheusRuleGroup_Spec{} // GetAPIVersion returns the ARM API version of the resource. This is always "2023-03-01" -func (group PrometheusRuleGroup_Spec_ARM) GetAPIVersion() string { +func (group PrometheusRuleGroup_Spec) GetAPIVersion() string { return string(APIVersion_Value) } // GetName returns the Name of the resource -func (group *PrometheusRuleGroup_Spec_ARM) GetName() string { +func (group *PrometheusRuleGroup_Spec) GetName() string { return group.Name } // GetType returns the ARM Type of the resource. This is always "Microsoft.AlertsManagement/prometheusRuleGroups" -func (group *PrometheusRuleGroup_Spec_ARM) GetType() string { +func (group *PrometheusRuleGroup_Spec) GetType() string { return "Microsoft.AlertsManagement/prometheusRuleGroups" } // An Azure Prometheus rule group. -type PrometheusRuleGroupProperties_ARM struct { +type PrometheusRuleGroupProperties struct { // ClusterName: Apply rule to data from a specific cluster. ClusterName *string `json:"clusterName,omitempty"` @@ -50,14 +50,14 @@ type PrometheusRuleGroupProperties_ARM struct { Interval *string `json:"interval,omitempty"` // Rules: Defines the rules in the Prometheus rule group. - Rules []PrometheusRule_ARM `json:"rules,omitempty"` - Scopes []string `json:"scopes,omitempty"` + Rules []PrometheusRule `json:"rules,omitempty"` + Scopes []string `json:"scopes,omitempty"` } // An Azure Prometheus alerting or recording rule. -type PrometheusRule_ARM struct { +type PrometheusRule struct { // Actions: Actions that are performed when the alert rule becomes active, and when an alert condition is resolved. - Actions []PrometheusRuleGroupAction_ARM `json:"actions,omitempty"` + Actions []PrometheusRuleGroupAction `json:"actions,omitempty"` // Alert: Alert rule name. Alert *string `json:"alert,omitempty"` @@ -84,14 +84,14 @@ type PrometheusRule_ARM struct { Record *string `json:"record,omitempty"` // ResolveConfiguration: Defines the configuration for resolving fired alerts. Only relevant for alerts. - ResolveConfiguration *PrometheusRuleResolveConfiguration_ARM `json:"resolveConfiguration,omitempty"` + ResolveConfiguration *PrometheusRuleResolveConfiguration `json:"resolveConfiguration,omitempty"` // Severity: The severity of the alerts fired by the rule. Must be between 0 and 4. Severity *int `json:"severity,omitempty"` } // An alert action. Only relevant for alerts. -type PrometheusRuleGroupAction_ARM struct { +type PrometheusRuleGroupAction struct { ActionGroupId *string `json:"actionGroupId,omitempty"` // ActionProperties: The properties of an action group object. @@ -99,7 +99,7 @@ type PrometheusRuleGroupAction_ARM struct { } // Specifies the Prometheus alert rule configuration. -type PrometheusRuleResolveConfiguration_ARM struct { +type PrometheusRuleResolveConfiguration struct { // AutoResolved: Enable alert auto-resolution. AutoResolved *bool `json:"autoResolved,omitempty"` diff --git a/v2/api/alertsmanagement/v1api20230301/arm/prometheus_rule_group_spec_types_gen_test.go b/v2/api/alertsmanagement/v1api20230301/arm/prometheus_rule_group_spec_types_gen_test.go new file mode 100644 index 0000000000..07a2cf43b9 --- /dev/null +++ b/v2/api/alertsmanagement/v1api20230301/arm/prometheus_rule_group_spec_types_gen_test.go @@ -0,0 +1,388 @@ +// Code generated by azure-service-operator-codegen. DO NOT EDIT. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. +package arm + +import ( + "encoding/json" + "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" + "github.com/kr/pretty" + "github.com/kylelemons/godebug/diff" + "github.com/leanovate/gopter" + "github.com/leanovate/gopter/gen" + "github.com/leanovate/gopter/prop" + "os" + "reflect" + "testing" +) + +func Test_PrometheusRule_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { + t.Parallel() + parameters := gopter.DefaultTestParameters() + parameters.MinSuccessfulTests = 100 + parameters.MaxSize = 3 + properties := gopter.NewProperties(parameters) + properties.Property( + "Round trip of PrometheusRule via JSON returns original", + prop.ForAll(RunJSONSerializationTestForPrometheusRule, PrometheusRuleGenerator())) + properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout)) +} + +// RunJSONSerializationTestForPrometheusRule runs a test to see if a specific instance of PrometheusRule round trips to JSON and back losslessly +func RunJSONSerializationTestForPrometheusRule(subject PrometheusRule) string { + // Serialize to JSON + bin, err := json.Marshal(subject) + if err != nil { + return err.Error() + } + + // Deserialize back into memory + var actual PrometheusRule + err = json.Unmarshal(bin, &actual) + if err != nil { + return err.Error() + } + + // Check for outcome + match := cmp.Equal(subject, actual, cmpopts.EquateEmpty()) + if !match { + actualFmt := pretty.Sprint(actual) + subjectFmt := pretty.Sprint(subject) + result := diff.Diff(subjectFmt, actualFmt) + return result + } + + return "" +} + +// Generator of PrometheusRule instances for property testing - lazily instantiated by PrometheusRuleGenerator() +var prometheusRuleGenerator gopter.Gen + +// PrometheusRuleGenerator returns a generator of PrometheusRule instances for property testing. +// We first initialize prometheusRuleGenerator with a simplified generator based on the +// fields with primitive types then replacing it with a more complex one that also handles complex fields +// to ensure any cycles in the object graph properly terminate. +func PrometheusRuleGenerator() gopter.Gen { + if prometheusRuleGenerator != nil { + return prometheusRuleGenerator + } + + generators := make(map[string]gopter.Gen) + AddIndependentPropertyGeneratorsForPrometheusRule(generators) + prometheusRuleGenerator = gen.Struct(reflect.TypeOf(PrometheusRule{}), generators) + + // The above call to gen.Struct() captures the map, so create a new one + generators = make(map[string]gopter.Gen) + AddIndependentPropertyGeneratorsForPrometheusRule(generators) + AddRelatedPropertyGeneratorsForPrometheusRule(generators) + prometheusRuleGenerator = gen.Struct(reflect.TypeOf(PrometheusRule{}), generators) + + return prometheusRuleGenerator +} + +// AddIndependentPropertyGeneratorsForPrometheusRule is a factory method for creating gopter generators +func AddIndependentPropertyGeneratorsForPrometheusRule(gens map[string]gopter.Gen) { + gens["Alert"] = gen.PtrOf(gen.AlphaString()) + gens["Annotations"] = gen.MapOf( + gen.AlphaString(), + gen.AlphaString()) + gens["Enabled"] = gen.PtrOf(gen.Bool()) + gens["Expression"] = gen.PtrOf(gen.AlphaString()) + gens["For"] = gen.PtrOf(gen.AlphaString()) + gens["Labels"] = gen.MapOf( + gen.AlphaString(), + gen.AlphaString()) + gens["Record"] = gen.PtrOf(gen.AlphaString()) + gens["Severity"] = gen.PtrOf(gen.Int()) +} + +// AddRelatedPropertyGeneratorsForPrometheusRule is a factory method for creating gopter generators +func AddRelatedPropertyGeneratorsForPrometheusRule(gens map[string]gopter.Gen) { + gens["Actions"] = gen.SliceOf(PrometheusRuleGroupActionGenerator()) + gens["ResolveConfiguration"] = gen.PtrOf(PrometheusRuleResolveConfigurationGenerator()) +} + +func Test_PrometheusRuleGroupAction_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { + t.Parallel() + parameters := gopter.DefaultTestParameters() + parameters.MinSuccessfulTests = 100 + parameters.MaxSize = 3 + properties := gopter.NewProperties(parameters) + properties.Property( + "Round trip of PrometheusRuleGroupAction via JSON returns original", + prop.ForAll(RunJSONSerializationTestForPrometheusRuleGroupAction, PrometheusRuleGroupActionGenerator())) + properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout)) +} + +// RunJSONSerializationTestForPrometheusRuleGroupAction runs a test to see if a specific instance of PrometheusRuleGroupAction round trips to JSON and back losslessly +func RunJSONSerializationTestForPrometheusRuleGroupAction(subject PrometheusRuleGroupAction) string { + // Serialize to JSON + bin, err := json.Marshal(subject) + if err != nil { + return err.Error() + } + + // Deserialize back into memory + var actual PrometheusRuleGroupAction + err = json.Unmarshal(bin, &actual) + if err != nil { + return err.Error() + } + + // Check for outcome + match := cmp.Equal(subject, actual, cmpopts.EquateEmpty()) + if !match { + actualFmt := pretty.Sprint(actual) + subjectFmt := pretty.Sprint(subject) + result := diff.Diff(subjectFmt, actualFmt) + return result + } + + return "" +} + +// Generator of PrometheusRuleGroupAction instances for property testing - lazily instantiated by +// PrometheusRuleGroupActionGenerator() +var prometheusRuleGroupActionGenerator gopter.Gen + +// PrometheusRuleGroupActionGenerator returns a generator of PrometheusRuleGroupAction instances for property testing. +func PrometheusRuleGroupActionGenerator() gopter.Gen { + if prometheusRuleGroupActionGenerator != nil { + return prometheusRuleGroupActionGenerator + } + + generators := make(map[string]gopter.Gen) + AddIndependentPropertyGeneratorsForPrometheusRuleGroupAction(generators) + prometheusRuleGroupActionGenerator = gen.Struct(reflect.TypeOf(PrometheusRuleGroupAction{}), generators) + + return prometheusRuleGroupActionGenerator +} + +// AddIndependentPropertyGeneratorsForPrometheusRuleGroupAction is a factory method for creating gopter generators +func AddIndependentPropertyGeneratorsForPrometheusRuleGroupAction(gens map[string]gopter.Gen) { + gens["ActionGroupId"] = gen.PtrOf(gen.AlphaString()) + gens["ActionProperties"] = gen.MapOf( + gen.AlphaString(), + gen.AlphaString()) +} + +func Test_PrometheusRuleGroupProperties_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { + t.Parallel() + parameters := gopter.DefaultTestParameters() + parameters.MinSuccessfulTests = 100 + parameters.MaxSize = 3 + properties := gopter.NewProperties(parameters) + properties.Property( + "Round trip of PrometheusRuleGroupProperties via JSON returns original", + prop.ForAll(RunJSONSerializationTestForPrometheusRuleGroupProperties, PrometheusRuleGroupPropertiesGenerator())) + properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout)) +} + +// RunJSONSerializationTestForPrometheusRuleGroupProperties runs a test to see if a specific instance of PrometheusRuleGroupProperties round trips to JSON and back losslessly +func RunJSONSerializationTestForPrometheusRuleGroupProperties(subject PrometheusRuleGroupProperties) string { + // Serialize to JSON + bin, err := json.Marshal(subject) + if err != nil { + return err.Error() + } + + // Deserialize back into memory + var actual PrometheusRuleGroupProperties + err = json.Unmarshal(bin, &actual) + if err != nil { + return err.Error() + } + + // Check for outcome + match := cmp.Equal(subject, actual, cmpopts.EquateEmpty()) + if !match { + actualFmt := pretty.Sprint(actual) + subjectFmt := pretty.Sprint(subject) + result := diff.Diff(subjectFmt, actualFmt) + return result + } + + return "" +} + +// Generator of PrometheusRuleGroupProperties instances for property testing - lazily instantiated by +// PrometheusRuleGroupPropertiesGenerator() +var prometheusRuleGroupPropertiesGenerator gopter.Gen + +// PrometheusRuleGroupPropertiesGenerator returns a generator of PrometheusRuleGroupProperties instances for property testing. +// We first initialize prometheusRuleGroupPropertiesGenerator with a simplified generator based on the +// fields with primitive types then replacing it with a more complex one that also handles complex fields +// to ensure any cycles in the object graph properly terminate. +func PrometheusRuleGroupPropertiesGenerator() gopter.Gen { + if prometheusRuleGroupPropertiesGenerator != nil { + return prometheusRuleGroupPropertiesGenerator + } + + generators := make(map[string]gopter.Gen) + AddIndependentPropertyGeneratorsForPrometheusRuleGroupProperties(generators) + prometheusRuleGroupPropertiesGenerator = gen.Struct(reflect.TypeOf(PrometheusRuleGroupProperties{}), generators) + + // The above call to gen.Struct() captures the map, so create a new one + generators = make(map[string]gopter.Gen) + AddIndependentPropertyGeneratorsForPrometheusRuleGroupProperties(generators) + AddRelatedPropertyGeneratorsForPrometheusRuleGroupProperties(generators) + prometheusRuleGroupPropertiesGenerator = gen.Struct(reflect.TypeOf(PrometheusRuleGroupProperties{}), generators) + + return prometheusRuleGroupPropertiesGenerator +} + +// AddIndependentPropertyGeneratorsForPrometheusRuleGroupProperties is a factory method for creating gopter generators +func AddIndependentPropertyGeneratorsForPrometheusRuleGroupProperties(gens map[string]gopter.Gen) { + gens["ClusterName"] = gen.PtrOf(gen.AlphaString()) + gens["Description"] = gen.PtrOf(gen.AlphaString()) + gens["Enabled"] = gen.PtrOf(gen.Bool()) + gens["Interval"] = gen.PtrOf(gen.AlphaString()) + gens["Scopes"] = gen.SliceOf(gen.AlphaString()) +} + +// AddRelatedPropertyGeneratorsForPrometheusRuleGroupProperties is a factory method for creating gopter generators +func AddRelatedPropertyGeneratorsForPrometheusRuleGroupProperties(gens map[string]gopter.Gen) { + gens["Rules"] = gen.SliceOf(PrometheusRuleGenerator()) +} + +func Test_PrometheusRuleGroup_Spec_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { + t.Parallel() + parameters := gopter.DefaultTestParameters() + parameters.MinSuccessfulTests = 80 + parameters.MaxSize = 3 + properties := gopter.NewProperties(parameters) + properties.Property( + "Round trip of PrometheusRuleGroup_Spec via JSON returns original", + prop.ForAll(RunJSONSerializationTestForPrometheusRuleGroup_Spec, PrometheusRuleGroup_SpecGenerator())) + properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout)) +} + +// RunJSONSerializationTestForPrometheusRuleGroup_Spec runs a test to see if a specific instance of PrometheusRuleGroup_Spec round trips to JSON and back losslessly +func RunJSONSerializationTestForPrometheusRuleGroup_Spec(subject PrometheusRuleGroup_Spec) string { + // Serialize to JSON + bin, err := json.Marshal(subject) + if err != nil { + return err.Error() + } + + // Deserialize back into memory + var actual PrometheusRuleGroup_Spec + err = json.Unmarshal(bin, &actual) + if err != nil { + return err.Error() + } + + // Check for outcome + match := cmp.Equal(subject, actual, cmpopts.EquateEmpty()) + if !match { + actualFmt := pretty.Sprint(actual) + subjectFmt := pretty.Sprint(subject) + result := diff.Diff(subjectFmt, actualFmt) + return result + } + + return "" +} + +// Generator of PrometheusRuleGroup_Spec instances for property testing - lazily instantiated by +// PrometheusRuleGroup_SpecGenerator() +var prometheusRuleGroup_SpecGenerator gopter.Gen + +// PrometheusRuleGroup_SpecGenerator returns a generator of PrometheusRuleGroup_Spec instances for property testing. +// We first initialize prometheusRuleGroup_SpecGenerator with a simplified generator based on the +// fields with primitive types then replacing it with a more complex one that also handles complex fields +// to ensure any cycles in the object graph properly terminate. +func PrometheusRuleGroup_SpecGenerator() gopter.Gen { + if prometheusRuleGroup_SpecGenerator != nil { + return prometheusRuleGroup_SpecGenerator + } + + generators := make(map[string]gopter.Gen) + AddIndependentPropertyGeneratorsForPrometheusRuleGroup_Spec(generators) + prometheusRuleGroup_SpecGenerator = gen.Struct(reflect.TypeOf(PrometheusRuleGroup_Spec{}), generators) + + // The above call to gen.Struct() captures the map, so create a new one + generators = make(map[string]gopter.Gen) + AddIndependentPropertyGeneratorsForPrometheusRuleGroup_Spec(generators) + AddRelatedPropertyGeneratorsForPrometheusRuleGroup_Spec(generators) + prometheusRuleGroup_SpecGenerator = gen.Struct(reflect.TypeOf(PrometheusRuleGroup_Spec{}), generators) + + return prometheusRuleGroup_SpecGenerator +} + +// AddIndependentPropertyGeneratorsForPrometheusRuleGroup_Spec is a factory method for creating gopter generators +func AddIndependentPropertyGeneratorsForPrometheusRuleGroup_Spec(gens map[string]gopter.Gen) { + gens["Location"] = gen.PtrOf(gen.AlphaString()) + gens["Name"] = gen.AlphaString() + gens["Tags"] = gen.MapOf( + gen.AlphaString(), + gen.AlphaString()) +} + +// AddRelatedPropertyGeneratorsForPrometheusRuleGroup_Spec is a factory method for creating gopter generators +func AddRelatedPropertyGeneratorsForPrometheusRuleGroup_Spec(gens map[string]gopter.Gen) { + gens["Properties"] = gen.PtrOf(PrometheusRuleGroupPropertiesGenerator()) +} + +func Test_PrometheusRuleResolveConfiguration_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { + t.Parallel() + parameters := gopter.DefaultTestParameters() + parameters.MinSuccessfulTests = 100 + parameters.MaxSize = 3 + properties := gopter.NewProperties(parameters) + properties.Property( + "Round trip of PrometheusRuleResolveConfiguration via JSON returns original", + prop.ForAll(RunJSONSerializationTestForPrometheusRuleResolveConfiguration, PrometheusRuleResolveConfigurationGenerator())) + properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout)) +} + +// RunJSONSerializationTestForPrometheusRuleResolveConfiguration runs a test to see if a specific instance of PrometheusRuleResolveConfiguration round trips to JSON and back losslessly +func RunJSONSerializationTestForPrometheusRuleResolveConfiguration(subject PrometheusRuleResolveConfiguration) string { + // Serialize to JSON + bin, err := json.Marshal(subject) + if err != nil { + return err.Error() + } + + // Deserialize back into memory + var actual PrometheusRuleResolveConfiguration + err = json.Unmarshal(bin, &actual) + if err != nil { + return err.Error() + } + + // Check for outcome + match := cmp.Equal(subject, actual, cmpopts.EquateEmpty()) + if !match { + actualFmt := pretty.Sprint(actual) + subjectFmt := pretty.Sprint(subject) + result := diff.Diff(subjectFmt, actualFmt) + return result + } + + return "" +} + +// Generator of PrometheusRuleResolveConfiguration instances for property testing - lazily instantiated by +// PrometheusRuleResolveConfigurationGenerator() +var prometheusRuleResolveConfigurationGenerator gopter.Gen + +// PrometheusRuleResolveConfigurationGenerator returns a generator of PrometheusRuleResolveConfiguration instances for property testing. +func PrometheusRuleResolveConfigurationGenerator() gopter.Gen { + if prometheusRuleResolveConfigurationGenerator != nil { + return prometheusRuleResolveConfigurationGenerator + } + + generators := make(map[string]gopter.Gen) + AddIndependentPropertyGeneratorsForPrometheusRuleResolveConfiguration(generators) + prometheusRuleResolveConfigurationGenerator = gen.Struct(reflect.TypeOf(PrometheusRuleResolveConfiguration{}), generators) + + return prometheusRuleResolveConfigurationGenerator +} + +// AddIndependentPropertyGeneratorsForPrometheusRuleResolveConfiguration is a factory method for creating gopter generators +func AddIndependentPropertyGeneratorsForPrometheusRuleResolveConfiguration(gens map[string]gopter.Gen) { + gens["AutoResolved"] = gen.PtrOf(gen.Bool()) + gens["TimeToResolve"] = gen.PtrOf(gen.AlphaString()) +} diff --git a/v2/api/alertsmanagement/v1api20230301/prometheus_rule_group_status_arm_types_gen.go b/v2/api/alertsmanagement/v1api20230301/arm/prometheus_rule_group_status_types_gen.go similarity index 63% rename from v2/api/alertsmanagement/v1api20230301/prometheus_rule_group_status_arm_types_gen.go rename to v2/api/alertsmanagement/v1api20230301/arm/prometheus_rule_group_status_types_gen.go index 7a2d0cd65e..caeea68a2c 100644 --- a/v2/api/alertsmanagement/v1api20230301/prometheus_rule_group_status_arm_types_gen.go +++ b/v2/api/alertsmanagement/v1api20230301/arm/prometheus_rule_group_status_types_gen.go @@ -1,9 +1,11 @@ // Code generated by azure-service-operator-codegen. DO NOT EDIT. // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -package v1api20230301 +package arm -type PrometheusRuleGroup_STATUS_ARM struct { +import v20230301 "github.com/Azure/azure-service-operator/v2/api/alertsmanagement/v1api20230301" + +type PrometheusRuleGroup_STATUS struct { // Id: Fully qualified resource ID for the resource. Ex - // /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName} Id *string `json:"id,omitempty"` @@ -15,10 +17,10 @@ type PrometheusRuleGroup_STATUS_ARM struct { Name *string `json:"name,omitempty"` // Properties: The Prometheus rule group properties of the resource. - Properties *PrometheusRuleGroupProperties_STATUS_ARM `json:"properties,omitempty"` + Properties *PrometheusRuleGroupProperties_STATUS `json:"properties,omitempty"` // SystemData: Azure Resource Manager metadata containing createdBy and modifiedBy information. - SystemData *SystemData_STATUS_ARM `json:"systemData,omitempty"` + SystemData *SystemData_STATUS `json:"systemData,omitempty"` // Tags: Resource tags. Tags map[string]string `json:"tags,omitempty"` @@ -28,7 +30,7 @@ type PrometheusRuleGroup_STATUS_ARM struct { } // An Azure Prometheus rule group. -type PrometheusRuleGroupProperties_STATUS_ARM struct { +type PrometheusRuleGroupProperties_STATUS struct { // ClusterName: Apply rule to data from a specific cluster. ClusterName *string `json:"clusterName,omitempty"` @@ -43,7 +45,7 @@ type PrometheusRuleGroupProperties_STATUS_ARM struct { Interval *string `json:"interval,omitempty"` // Rules: Defines the rules in the Prometheus rule group. - Rules []PrometheusRule_STATUS_ARM `json:"rules,omitempty"` + Rules []PrometheusRule_STATUS `json:"rules,omitempty"` // Scopes: Target Azure Monitor workspaces resource ids. This api-version is currently limited to creating with one scope. // This may change in future. @@ -51,7 +53,7 @@ type PrometheusRuleGroupProperties_STATUS_ARM struct { } // Metadata pertaining to creation and last modification of the resource. -type SystemData_STATUS_ARM struct { +type SystemData_STATUS struct { // CreatedAt: The timestamp of resource creation (UTC). CreatedAt *string `json:"createdAt,omitempty"` @@ -59,7 +61,7 @@ type SystemData_STATUS_ARM struct { CreatedBy *string `json:"createdBy,omitempty"` // CreatedByType: The type of identity that created the resource. - CreatedByType *SystemData_CreatedByType_STATUS `json:"createdByType,omitempty"` + CreatedByType *v20230301.SystemData_CreatedByType_STATUS `json:"createdByType,omitempty"` // LastModifiedAt: The timestamp of resource last modification (UTC) LastModifiedAt *string `json:"lastModifiedAt,omitempty"` @@ -68,13 +70,13 @@ type SystemData_STATUS_ARM struct { LastModifiedBy *string `json:"lastModifiedBy,omitempty"` // LastModifiedByType: The type of identity that last modified the resource. - LastModifiedByType *SystemData_LastModifiedByType_STATUS `json:"lastModifiedByType,omitempty"` + LastModifiedByType *v20230301.SystemData_LastModifiedByType_STATUS `json:"lastModifiedByType,omitempty"` } // An Azure Prometheus alerting or recording rule. -type PrometheusRule_STATUS_ARM struct { +type PrometheusRule_STATUS struct { // Actions: Actions that are performed when the alert rule becomes active, and when an alert condition is resolved. - Actions []PrometheusRuleGroupAction_STATUS_ARM `json:"actions,omitempty"` + Actions []PrometheusRuleGroupAction_STATUS `json:"actions,omitempty"` // Alert: Alert rule name. Alert *string `json:"alert,omitempty"` @@ -101,48 +103,14 @@ type PrometheusRule_STATUS_ARM struct { Record *string `json:"record,omitempty"` // ResolveConfiguration: Defines the configuration for resolving fired alerts. Only relevant for alerts. - ResolveConfiguration *PrometheusRuleResolveConfiguration_STATUS_ARM `json:"resolveConfiguration,omitempty"` + ResolveConfiguration *PrometheusRuleResolveConfiguration_STATUS `json:"resolveConfiguration,omitempty"` // Severity: The severity of the alerts fired by the rule. Must be between 0 and 4. Severity *int `json:"severity,omitempty"` } -type SystemData_CreatedByType_STATUS string - -const ( - SystemData_CreatedByType_STATUS_Application = SystemData_CreatedByType_STATUS("Application") - SystemData_CreatedByType_STATUS_Key = SystemData_CreatedByType_STATUS("Key") - SystemData_CreatedByType_STATUS_ManagedIdentity = SystemData_CreatedByType_STATUS("ManagedIdentity") - SystemData_CreatedByType_STATUS_User = SystemData_CreatedByType_STATUS("User") -) - -// Mapping from string to SystemData_CreatedByType_STATUS -var systemData_CreatedByType_STATUS_Values = map[string]SystemData_CreatedByType_STATUS{ - "application": SystemData_CreatedByType_STATUS_Application, - "key": SystemData_CreatedByType_STATUS_Key, - "managedidentity": SystemData_CreatedByType_STATUS_ManagedIdentity, - "user": SystemData_CreatedByType_STATUS_User, -} - -type SystemData_LastModifiedByType_STATUS string - -const ( - SystemData_LastModifiedByType_STATUS_Application = SystemData_LastModifiedByType_STATUS("Application") - SystemData_LastModifiedByType_STATUS_Key = SystemData_LastModifiedByType_STATUS("Key") - SystemData_LastModifiedByType_STATUS_ManagedIdentity = SystemData_LastModifiedByType_STATUS("ManagedIdentity") - SystemData_LastModifiedByType_STATUS_User = SystemData_LastModifiedByType_STATUS("User") -) - -// Mapping from string to SystemData_LastModifiedByType_STATUS -var systemData_LastModifiedByType_STATUS_Values = map[string]SystemData_LastModifiedByType_STATUS{ - "application": SystemData_LastModifiedByType_STATUS_Application, - "key": SystemData_LastModifiedByType_STATUS_Key, - "managedidentity": SystemData_LastModifiedByType_STATUS_ManagedIdentity, - "user": SystemData_LastModifiedByType_STATUS_User, -} - // An alert action. Only relevant for alerts. -type PrometheusRuleGroupAction_STATUS_ARM struct { +type PrometheusRuleGroupAction_STATUS struct { // ActionGroupId: The resource id of the action group to use. ActionGroupId *string `json:"actionGroupId,omitempty"` @@ -151,7 +119,7 @@ type PrometheusRuleGroupAction_STATUS_ARM struct { } // Specifies the Prometheus alert rule configuration. -type PrometheusRuleResolveConfiguration_STATUS_ARM struct { +type PrometheusRuleResolveConfiguration_STATUS struct { // AutoResolved: Enable alert auto-resolution. AutoResolved *bool `json:"autoResolved,omitempty"` diff --git a/v2/api/alertsmanagement/v1api20230301/arm/prometheus_rule_group_status_types_gen_test.go b/v2/api/alertsmanagement/v1api20230301/arm/prometheus_rule_group_status_types_gen_test.go new file mode 100644 index 0000000000..f3ba86841e --- /dev/null +++ b/v2/api/alertsmanagement/v1api20230301/arm/prometheus_rule_group_status_types_gen_test.go @@ -0,0 +1,471 @@ +// Code generated by azure-service-operator-codegen. DO NOT EDIT. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. +package arm + +import ( + "encoding/json" + v20230301 "github.com/Azure/azure-service-operator/v2/api/alertsmanagement/v1api20230301" + "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" + "github.com/kr/pretty" + "github.com/kylelemons/godebug/diff" + "github.com/leanovate/gopter" + "github.com/leanovate/gopter/gen" + "github.com/leanovate/gopter/prop" + "os" + "reflect" + "testing" +) + +func Test_PrometheusRuleGroupAction_STATUS_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { + t.Parallel() + parameters := gopter.DefaultTestParameters() + parameters.MinSuccessfulTests = 80 + parameters.MaxSize = 3 + properties := gopter.NewProperties(parameters) + properties.Property( + "Round trip of PrometheusRuleGroupAction_STATUS via JSON returns original", + prop.ForAll(RunJSONSerializationTestForPrometheusRuleGroupAction_STATUS, PrometheusRuleGroupAction_STATUSGenerator())) + properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout)) +} + +// RunJSONSerializationTestForPrometheusRuleGroupAction_STATUS runs a test to see if a specific instance of PrometheusRuleGroupAction_STATUS round trips to JSON and back losslessly +func RunJSONSerializationTestForPrometheusRuleGroupAction_STATUS(subject PrometheusRuleGroupAction_STATUS) string { + // Serialize to JSON + bin, err := json.Marshal(subject) + if err != nil { + return err.Error() + } + + // Deserialize back into memory + var actual PrometheusRuleGroupAction_STATUS + err = json.Unmarshal(bin, &actual) + if err != nil { + return err.Error() + } + + // Check for outcome + match := cmp.Equal(subject, actual, cmpopts.EquateEmpty()) + if !match { + actualFmt := pretty.Sprint(actual) + subjectFmt := pretty.Sprint(subject) + result := diff.Diff(subjectFmt, actualFmt) + return result + } + + return "" +} + +// Generator of PrometheusRuleGroupAction_STATUS instances for property testing - lazily instantiated by +// PrometheusRuleGroupAction_STATUSGenerator() +var prometheusRuleGroupAction_STATUSGenerator gopter.Gen + +// PrometheusRuleGroupAction_STATUSGenerator returns a generator of PrometheusRuleGroupAction_STATUS instances for property testing. +func PrometheusRuleGroupAction_STATUSGenerator() gopter.Gen { + if prometheusRuleGroupAction_STATUSGenerator != nil { + return prometheusRuleGroupAction_STATUSGenerator + } + + generators := make(map[string]gopter.Gen) + AddIndependentPropertyGeneratorsForPrometheusRuleGroupAction_STATUS(generators) + prometheusRuleGroupAction_STATUSGenerator = gen.Struct(reflect.TypeOf(PrometheusRuleGroupAction_STATUS{}), generators) + + return prometheusRuleGroupAction_STATUSGenerator +} + +// AddIndependentPropertyGeneratorsForPrometheusRuleGroupAction_STATUS is a factory method for creating gopter generators +func AddIndependentPropertyGeneratorsForPrometheusRuleGroupAction_STATUS(gens map[string]gopter.Gen) { + gens["ActionGroupId"] = gen.PtrOf(gen.AlphaString()) + gens["ActionProperties"] = gen.MapOf( + gen.AlphaString(), + gen.AlphaString()) +} + +func Test_PrometheusRuleGroupProperties_STATUS_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { + t.Parallel() + parameters := gopter.DefaultTestParameters() + parameters.MinSuccessfulTests = 80 + parameters.MaxSize = 3 + properties := gopter.NewProperties(parameters) + properties.Property( + "Round trip of PrometheusRuleGroupProperties_STATUS via JSON returns original", + prop.ForAll(RunJSONSerializationTestForPrometheusRuleGroupProperties_STATUS, PrometheusRuleGroupProperties_STATUSGenerator())) + properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout)) +} + +// RunJSONSerializationTestForPrometheusRuleGroupProperties_STATUS runs a test to see if a specific instance of PrometheusRuleGroupProperties_STATUS round trips to JSON and back losslessly +func RunJSONSerializationTestForPrometheusRuleGroupProperties_STATUS(subject PrometheusRuleGroupProperties_STATUS) string { + // Serialize to JSON + bin, err := json.Marshal(subject) + if err != nil { + return err.Error() + } + + // Deserialize back into memory + var actual PrometheusRuleGroupProperties_STATUS + err = json.Unmarshal(bin, &actual) + if err != nil { + return err.Error() + } + + // Check for outcome + match := cmp.Equal(subject, actual, cmpopts.EquateEmpty()) + if !match { + actualFmt := pretty.Sprint(actual) + subjectFmt := pretty.Sprint(subject) + result := diff.Diff(subjectFmt, actualFmt) + return result + } + + return "" +} + +// Generator of PrometheusRuleGroupProperties_STATUS instances for property testing - lazily instantiated by +// PrometheusRuleGroupProperties_STATUSGenerator() +var prometheusRuleGroupProperties_STATUSGenerator gopter.Gen + +// PrometheusRuleGroupProperties_STATUSGenerator returns a generator of PrometheusRuleGroupProperties_STATUS instances for property testing. +// We first initialize prometheusRuleGroupProperties_STATUSGenerator with a simplified generator based on the +// fields with primitive types then replacing it with a more complex one that also handles complex fields +// to ensure any cycles in the object graph properly terminate. +func PrometheusRuleGroupProperties_STATUSGenerator() gopter.Gen { + if prometheusRuleGroupProperties_STATUSGenerator != nil { + return prometheusRuleGroupProperties_STATUSGenerator + } + + generators := make(map[string]gopter.Gen) + AddIndependentPropertyGeneratorsForPrometheusRuleGroupProperties_STATUS(generators) + prometheusRuleGroupProperties_STATUSGenerator = gen.Struct(reflect.TypeOf(PrometheusRuleGroupProperties_STATUS{}), generators) + + // The above call to gen.Struct() captures the map, so create a new one + generators = make(map[string]gopter.Gen) + AddIndependentPropertyGeneratorsForPrometheusRuleGroupProperties_STATUS(generators) + AddRelatedPropertyGeneratorsForPrometheusRuleGroupProperties_STATUS(generators) + prometheusRuleGroupProperties_STATUSGenerator = gen.Struct(reflect.TypeOf(PrometheusRuleGroupProperties_STATUS{}), generators) + + return prometheusRuleGroupProperties_STATUSGenerator +} + +// AddIndependentPropertyGeneratorsForPrometheusRuleGroupProperties_STATUS is a factory method for creating gopter generators +func AddIndependentPropertyGeneratorsForPrometheusRuleGroupProperties_STATUS(gens map[string]gopter.Gen) { + gens["ClusterName"] = gen.PtrOf(gen.AlphaString()) + gens["Description"] = gen.PtrOf(gen.AlphaString()) + gens["Enabled"] = gen.PtrOf(gen.Bool()) + gens["Interval"] = gen.PtrOf(gen.AlphaString()) + gens["Scopes"] = gen.SliceOf(gen.AlphaString()) +} + +// AddRelatedPropertyGeneratorsForPrometheusRuleGroupProperties_STATUS is a factory method for creating gopter generators +func AddRelatedPropertyGeneratorsForPrometheusRuleGroupProperties_STATUS(gens map[string]gopter.Gen) { + gens["Rules"] = gen.SliceOf(PrometheusRule_STATUSGenerator()) +} + +func Test_PrometheusRuleGroup_STATUS_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { + t.Parallel() + parameters := gopter.DefaultTestParameters() + parameters.MinSuccessfulTests = 80 + parameters.MaxSize = 3 + properties := gopter.NewProperties(parameters) + properties.Property( + "Round trip of PrometheusRuleGroup_STATUS via JSON returns original", + prop.ForAll(RunJSONSerializationTestForPrometheusRuleGroup_STATUS, PrometheusRuleGroup_STATUSGenerator())) + properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout)) +} + +// RunJSONSerializationTestForPrometheusRuleGroup_STATUS runs a test to see if a specific instance of PrometheusRuleGroup_STATUS round trips to JSON and back losslessly +func RunJSONSerializationTestForPrometheusRuleGroup_STATUS(subject PrometheusRuleGroup_STATUS) string { + // Serialize to JSON + bin, err := json.Marshal(subject) + if err != nil { + return err.Error() + } + + // Deserialize back into memory + var actual PrometheusRuleGroup_STATUS + err = json.Unmarshal(bin, &actual) + if err != nil { + return err.Error() + } + + // Check for outcome + match := cmp.Equal(subject, actual, cmpopts.EquateEmpty()) + if !match { + actualFmt := pretty.Sprint(actual) + subjectFmt := pretty.Sprint(subject) + result := diff.Diff(subjectFmt, actualFmt) + return result + } + + return "" +} + +// Generator of PrometheusRuleGroup_STATUS instances for property testing - lazily instantiated by +// PrometheusRuleGroup_STATUSGenerator() +var prometheusRuleGroup_STATUSGenerator gopter.Gen + +// PrometheusRuleGroup_STATUSGenerator returns a generator of PrometheusRuleGroup_STATUS instances for property testing. +// We first initialize prometheusRuleGroup_STATUSGenerator with a simplified generator based on the +// fields with primitive types then replacing it with a more complex one that also handles complex fields +// to ensure any cycles in the object graph properly terminate. +func PrometheusRuleGroup_STATUSGenerator() gopter.Gen { + if prometheusRuleGroup_STATUSGenerator != nil { + return prometheusRuleGroup_STATUSGenerator + } + + generators := make(map[string]gopter.Gen) + AddIndependentPropertyGeneratorsForPrometheusRuleGroup_STATUS(generators) + prometheusRuleGroup_STATUSGenerator = gen.Struct(reflect.TypeOf(PrometheusRuleGroup_STATUS{}), generators) + + // The above call to gen.Struct() captures the map, so create a new one + generators = make(map[string]gopter.Gen) + AddIndependentPropertyGeneratorsForPrometheusRuleGroup_STATUS(generators) + AddRelatedPropertyGeneratorsForPrometheusRuleGroup_STATUS(generators) + prometheusRuleGroup_STATUSGenerator = gen.Struct(reflect.TypeOf(PrometheusRuleGroup_STATUS{}), generators) + + return prometheusRuleGroup_STATUSGenerator +} + +// AddIndependentPropertyGeneratorsForPrometheusRuleGroup_STATUS is a factory method for creating gopter generators +func AddIndependentPropertyGeneratorsForPrometheusRuleGroup_STATUS(gens map[string]gopter.Gen) { + gens["Id"] = gen.PtrOf(gen.AlphaString()) + gens["Location"] = gen.PtrOf(gen.AlphaString()) + gens["Name"] = gen.PtrOf(gen.AlphaString()) + gens["Tags"] = gen.MapOf( + gen.AlphaString(), + gen.AlphaString()) + gens["Type"] = gen.PtrOf(gen.AlphaString()) +} + +// AddRelatedPropertyGeneratorsForPrometheusRuleGroup_STATUS is a factory method for creating gopter generators +func AddRelatedPropertyGeneratorsForPrometheusRuleGroup_STATUS(gens map[string]gopter.Gen) { + gens["Properties"] = gen.PtrOf(PrometheusRuleGroupProperties_STATUSGenerator()) + gens["SystemData"] = gen.PtrOf(SystemData_STATUSGenerator()) +} + +func Test_PrometheusRuleResolveConfiguration_STATUS_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { + t.Parallel() + parameters := gopter.DefaultTestParameters() + parameters.MinSuccessfulTests = 80 + parameters.MaxSize = 3 + properties := gopter.NewProperties(parameters) + properties.Property( + "Round trip of PrometheusRuleResolveConfiguration_STATUS via JSON returns original", + prop.ForAll(RunJSONSerializationTestForPrometheusRuleResolveConfiguration_STATUS, PrometheusRuleResolveConfiguration_STATUSGenerator())) + properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout)) +} + +// RunJSONSerializationTestForPrometheusRuleResolveConfiguration_STATUS runs a test to see if a specific instance of PrometheusRuleResolveConfiguration_STATUS round trips to JSON and back losslessly +func RunJSONSerializationTestForPrometheusRuleResolveConfiguration_STATUS(subject PrometheusRuleResolveConfiguration_STATUS) string { + // Serialize to JSON + bin, err := json.Marshal(subject) + if err != nil { + return err.Error() + } + + // Deserialize back into memory + var actual PrometheusRuleResolveConfiguration_STATUS + err = json.Unmarshal(bin, &actual) + if err != nil { + return err.Error() + } + + // Check for outcome + match := cmp.Equal(subject, actual, cmpopts.EquateEmpty()) + if !match { + actualFmt := pretty.Sprint(actual) + subjectFmt := pretty.Sprint(subject) + result := diff.Diff(subjectFmt, actualFmt) + return result + } + + return "" +} + +// Generator of PrometheusRuleResolveConfiguration_STATUS instances for property testing - lazily instantiated by +// PrometheusRuleResolveConfiguration_STATUSGenerator() +var prometheusRuleResolveConfiguration_STATUSGenerator gopter.Gen + +// PrometheusRuleResolveConfiguration_STATUSGenerator returns a generator of PrometheusRuleResolveConfiguration_STATUS instances for property testing. +func PrometheusRuleResolveConfiguration_STATUSGenerator() gopter.Gen { + if prometheusRuleResolveConfiguration_STATUSGenerator != nil { + return prometheusRuleResolveConfiguration_STATUSGenerator + } + + generators := make(map[string]gopter.Gen) + AddIndependentPropertyGeneratorsForPrometheusRuleResolveConfiguration_STATUS(generators) + prometheusRuleResolveConfiguration_STATUSGenerator = gen.Struct(reflect.TypeOf(PrometheusRuleResolveConfiguration_STATUS{}), generators) + + return prometheusRuleResolveConfiguration_STATUSGenerator +} + +// AddIndependentPropertyGeneratorsForPrometheusRuleResolveConfiguration_STATUS is a factory method for creating gopter generators +func AddIndependentPropertyGeneratorsForPrometheusRuleResolveConfiguration_STATUS(gens map[string]gopter.Gen) { + gens["AutoResolved"] = gen.PtrOf(gen.Bool()) + gens["TimeToResolve"] = gen.PtrOf(gen.AlphaString()) +} + +func Test_PrometheusRule_STATUS_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { + t.Parallel() + parameters := gopter.DefaultTestParameters() + parameters.MinSuccessfulTests = 80 + parameters.MaxSize = 3 + properties := gopter.NewProperties(parameters) + properties.Property( + "Round trip of PrometheusRule_STATUS via JSON returns original", + prop.ForAll(RunJSONSerializationTestForPrometheusRule_STATUS, PrometheusRule_STATUSGenerator())) + properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout)) +} + +// RunJSONSerializationTestForPrometheusRule_STATUS runs a test to see if a specific instance of PrometheusRule_STATUS round trips to JSON and back losslessly +func RunJSONSerializationTestForPrometheusRule_STATUS(subject PrometheusRule_STATUS) string { + // Serialize to JSON + bin, err := json.Marshal(subject) + if err != nil { + return err.Error() + } + + // Deserialize back into memory + var actual PrometheusRule_STATUS + err = json.Unmarshal(bin, &actual) + if err != nil { + return err.Error() + } + + // Check for outcome + match := cmp.Equal(subject, actual, cmpopts.EquateEmpty()) + if !match { + actualFmt := pretty.Sprint(actual) + subjectFmt := pretty.Sprint(subject) + result := diff.Diff(subjectFmt, actualFmt) + return result + } + + return "" +} + +// Generator of PrometheusRule_STATUS instances for property testing - lazily instantiated by +// PrometheusRule_STATUSGenerator() +var prometheusRule_STATUSGenerator gopter.Gen + +// PrometheusRule_STATUSGenerator returns a generator of PrometheusRule_STATUS instances for property testing. +// We first initialize prometheusRule_STATUSGenerator with a simplified generator based on the +// fields with primitive types then replacing it with a more complex one that also handles complex fields +// to ensure any cycles in the object graph properly terminate. +func PrometheusRule_STATUSGenerator() gopter.Gen { + if prometheusRule_STATUSGenerator != nil { + return prometheusRule_STATUSGenerator + } + + generators := make(map[string]gopter.Gen) + AddIndependentPropertyGeneratorsForPrometheusRule_STATUS(generators) + prometheusRule_STATUSGenerator = gen.Struct(reflect.TypeOf(PrometheusRule_STATUS{}), generators) + + // The above call to gen.Struct() captures the map, so create a new one + generators = make(map[string]gopter.Gen) + AddIndependentPropertyGeneratorsForPrometheusRule_STATUS(generators) + AddRelatedPropertyGeneratorsForPrometheusRule_STATUS(generators) + prometheusRule_STATUSGenerator = gen.Struct(reflect.TypeOf(PrometheusRule_STATUS{}), generators) + + return prometheusRule_STATUSGenerator +} + +// AddIndependentPropertyGeneratorsForPrometheusRule_STATUS is a factory method for creating gopter generators +func AddIndependentPropertyGeneratorsForPrometheusRule_STATUS(gens map[string]gopter.Gen) { + gens["Alert"] = gen.PtrOf(gen.AlphaString()) + gens["Annotations"] = gen.MapOf( + gen.AlphaString(), + gen.AlphaString()) + gens["Enabled"] = gen.PtrOf(gen.Bool()) + gens["Expression"] = gen.PtrOf(gen.AlphaString()) + gens["For"] = gen.PtrOf(gen.AlphaString()) + gens["Labels"] = gen.MapOf( + gen.AlphaString(), + gen.AlphaString()) + gens["Record"] = gen.PtrOf(gen.AlphaString()) + gens["Severity"] = gen.PtrOf(gen.Int()) +} + +// AddRelatedPropertyGeneratorsForPrometheusRule_STATUS is a factory method for creating gopter generators +func AddRelatedPropertyGeneratorsForPrometheusRule_STATUS(gens map[string]gopter.Gen) { + gens["Actions"] = gen.SliceOf(PrometheusRuleGroupAction_STATUSGenerator()) + gens["ResolveConfiguration"] = gen.PtrOf(PrometheusRuleResolveConfiguration_STATUSGenerator()) +} + +func Test_SystemData_STATUS_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { + t.Parallel() + parameters := gopter.DefaultTestParameters() + parameters.MinSuccessfulTests = 80 + parameters.MaxSize = 3 + properties := gopter.NewProperties(parameters) + properties.Property( + "Round trip of SystemData_STATUS via JSON returns original", + prop.ForAll(RunJSONSerializationTestForSystemData_STATUS, SystemData_STATUSGenerator())) + properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout)) +} + +// RunJSONSerializationTestForSystemData_STATUS runs a test to see if a specific instance of SystemData_STATUS round trips to JSON and back losslessly +func RunJSONSerializationTestForSystemData_STATUS(subject SystemData_STATUS) string { + // Serialize to JSON + bin, err := json.Marshal(subject) + if err != nil { + return err.Error() + } + + // Deserialize back into memory + var actual SystemData_STATUS + err = json.Unmarshal(bin, &actual) + if err != nil { + return err.Error() + } + + // Check for outcome + match := cmp.Equal(subject, actual, cmpopts.EquateEmpty()) + if !match { + actualFmt := pretty.Sprint(actual) + subjectFmt := pretty.Sprint(subject) + result := diff.Diff(subjectFmt, actualFmt) + return result + } + + return "" +} + +// Generator of SystemData_STATUS instances for property testing - lazily instantiated by SystemData_STATUSGenerator() +var systemData_STATUSGenerator gopter.Gen + +// SystemData_STATUSGenerator returns a generator of SystemData_STATUS instances for property testing. +// We first initialize systemData_STATUSGenerator with a simplified generator based on the +// fields with primitive types then replacing it with a more complex one that also handles complex fields +// to ensure any cycles in the object graph properly terminate. +func SystemData_STATUSGenerator() gopter.Gen { + if systemData_STATUSGenerator != nil { + return systemData_STATUSGenerator + } + + generators := make(map[string]gopter.Gen) + AddIndependentPropertyGeneratorsForSystemData_STATUS(generators) + systemData_STATUSGenerator = gen.Struct(reflect.TypeOf(SystemData_STATUS{}), generators) + + // The above call to gen.Struct() captures the map, so create a new one + generators = make(map[string]gopter.Gen) + AddIndependentPropertyGeneratorsForSystemData_STATUS(generators) + AddRelatedPropertyGeneratorsForSystemData_STATUS(generators) + systemData_STATUSGenerator = gen.Struct(reflect.TypeOf(SystemData_STATUS{}), generators) + + return systemData_STATUSGenerator +} + +// AddIndependentPropertyGeneratorsForSystemData_STATUS is a factory method for creating gopter generators +func AddIndependentPropertyGeneratorsForSystemData_STATUS(gens map[string]gopter.Gen) { + gens["CreatedAt"] = gen.PtrOf(gen.AlphaString()) + gens["CreatedBy"] = gen.PtrOf(gen.AlphaString()) + gens["LastModifiedAt"] = gen.PtrOf(gen.AlphaString()) + gens["LastModifiedBy"] = gen.PtrOf(gen.AlphaString()) +} + +// AddRelatedPropertyGeneratorsForSystemData_STATUS is a factory method for creating gopter generators +func AddRelatedPropertyGeneratorsForSystemData_STATUS(gens map[string]gopter.Gen) { + gens["CreatedByType"] = gen.PtrOf(v20230301.SystemData_CreatedByType_STATUSGenerator()) + gens["LastModifiedByType"] = gen.PtrOf(v20230301.SystemData_LastModifiedByType_STATUSGenerator()) +} diff --git a/v2/api/alertsmanagement/v1api20230301/arm/structure.txt b/v2/api/alertsmanagement/v1api20230301/arm/structure.txt new file mode 100644 index 0000000000..973e36e1dd --- /dev/null +++ b/v2/api/alertsmanagement/v1api20230301/arm/structure.txt @@ -0,0 +1,61 @@ +// Code generated by azure-service-operator-codegen. DO NOT EDIT. +github.com/Azure/azure-service-operator/v2/api/alertsmanagement/v1api20230301/arm +├── PrometheusRuleGroup_STATUS: Object (7 properties) +│ ├── Id: *string +│ ├── Location: *string +│ ├── Name: *string +│ ├── Properties: *Object (6 properties) +│ │ ├── ClusterName: *string +│ │ ├── Description: *string +│ │ ├── Enabled: *bool +│ │ ├── Interval: *string +│ │ ├── Rules: Object (10 properties)[] +│ │ │ ├── Actions: Object (2 properties)[] +│ │ │ │ ├── ActionGroupId: *string +│ │ │ │ └── ActionProperties: map[string]string +│ │ │ ├── Alert: *string +│ │ │ ├── Annotations: map[string]string +│ │ │ ├── Enabled: *bool +│ │ │ ├── Expression: *string +│ │ │ ├── For: *string +│ │ │ ├── Labels: map[string]string +│ │ │ ├── Record: *string +│ │ │ ├── ResolveConfiguration: *Object (2 properties) +│ │ │ │ ├── AutoResolved: *bool +│ │ │ │ └── TimeToResolve: *string +│ │ │ └── Severity: *int +│ │ └── Scopes: string[] +│ ├── SystemData: *Object (6 properties) +│ │ ├── CreatedAt: *string +│ │ ├── CreatedBy: *string +│ │ ├── CreatedByType: *alertsmanagement/v1api20230301.SystemData_CreatedByType_STATUS +│ │ ├── LastModifiedAt: *string +│ │ ├── LastModifiedBy: *string +│ │ └── LastModifiedByType: *alertsmanagement/v1api20230301.SystemData_LastModifiedByType_STATUS +│ ├── Tags: map[string]string +│ └── Type: *string +└── PrometheusRuleGroup_Spec: Object (4 properties) + ├── Location: *string + ├── Name: string + ├── Properties: *Object (6 properties) + │ ├── ClusterName: *string + │ ├── Description: *string + │ ├── Enabled: *bool + │ ├── Interval: *string + │ ├── Rules: Object (10 properties)[] + │ │ ├── Actions: Object (2 properties)[] + │ │ │ ├── ActionGroupId: *string + │ │ │ └── ActionProperties: map[string]string + │ │ ├── Alert: *string + │ │ ├── Annotations: map[string]string + │ │ ├── Enabled: *bool + │ │ ├── Expression: *string + │ │ ├── For: *string + │ │ ├── Labels: map[string]string + │ │ ├── Record: *string + │ │ ├── ResolveConfiguration: *Object (2 properties) + │ │ │ ├── AutoResolved: *bool + │ │ │ └── TimeToResolve: *string + │ │ └── Severity: *int + │ └── Scopes: string[] + └── Tags: map[string]string diff --git a/v2/api/alertsmanagement/v1api20230301/prometheus_rule_group_spec_arm_types_gen_test.go b/v2/api/alertsmanagement/v1api20230301/prometheus_rule_group_spec_arm_types_gen_test.go deleted file mode 100644 index ef97fc9184..0000000000 --- a/v2/api/alertsmanagement/v1api20230301/prometheus_rule_group_spec_arm_types_gen_test.go +++ /dev/null @@ -1,388 +0,0 @@ -// Code generated by azure-service-operator-codegen. DO NOT EDIT. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. -package v1api20230301 - -import ( - "encoding/json" - "github.com/google/go-cmp/cmp" - "github.com/google/go-cmp/cmp/cmpopts" - "github.com/kr/pretty" - "github.com/kylelemons/godebug/diff" - "github.com/leanovate/gopter" - "github.com/leanovate/gopter/gen" - "github.com/leanovate/gopter/prop" - "os" - "reflect" - "testing" -) - -func Test_PrometheusRuleGroupAction_ARM_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { - t.Parallel() - parameters := gopter.DefaultTestParameters() - parameters.MinSuccessfulTests = 100 - parameters.MaxSize = 3 - properties := gopter.NewProperties(parameters) - properties.Property( - "Round trip of PrometheusRuleGroupAction_ARM via JSON returns original", - prop.ForAll(RunJSONSerializationTestForPrometheusRuleGroupAction_ARM, PrometheusRuleGroupAction_ARMGenerator())) - properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout)) -} - -// RunJSONSerializationTestForPrometheusRuleGroupAction_ARM runs a test to see if a specific instance of PrometheusRuleGroupAction_ARM round trips to JSON and back losslessly -func RunJSONSerializationTestForPrometheusRuleGroupAction_ARM(subject PrometheusRuleGroupAction_ARM) string { - // Serialize to JSON - bin, err := json.Marshal(subject) - if err != nil { - return err.Error() - } - - // Deserialize back into memory - var actual PrometheusRuleGroupAction_ARM - err = json.Unmarshal(bin, &actual) - if err != nil { - return err.Error() - } - - // Check for outcome - match := cmp.Equal(subject, actual, cmpopts.EquateEmpty()) - if !match { - actualFmt := pretty.Sprint(actual) - subjectFmt := pretty.Sprint(subject) - result := diff.Diff(subjectFmt, actualFmt) - return result - } - - return "" -} - -// Generator of PrometheusRuleGroupAction_ARM instances for property testing - lazily instantiated by -// PrometheusRuleGroupAction_ARMGenerator() -var prometheusRuleGroupAction_ARMGenerator gopter.Gen - -// PrometheusRuleGroupAction_ARMGenerator returns a generator of PrometheusRuleGroupAction_ARM instances for property testing. -func PrometheusRuleGroupAction_ARMGenerator() gopter.Gen { - if prometheusRuleGroupAction_ARMGenerator != nil { - return prometheusRuleGroupAction_ARMGenerator - } - - generators := make(map[string]gopter.Gen) - AddIndependentPropertyGeneratorsForPrometheusRuleGroupAction_ARM(generators) - prometheusRuleGroupAction_ARMGenerator = gen.Struct(reflect.TypeOf(PrometheusRuleGroupAction_ARM{}), generators) - - return prometheusRuleGroupAction_ARMGenerator -} - -// AddIndependentPropertyGeneratorsForPrometheusRuleGroupAction_ARM is a factory method for creating gopter generators -func AddIndependentPropertyGeneratorsForPrometheusRuleGroupAction_ARM(gens map[string]gopter.Gen) { - gens["ActionGroupId"] = gen.PtrOf(gen.AlphaString()) - gens["ActionProperties"] = gen.MapOf( - gen.AlphaString(), - gen.AlphaString()) -} - -func Test_PrometheusRuleGroupProperties_ARM_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { - t.Parallel() - parameters := gopter.DefaultTestParameters() - parameters.MinSuccessfulTests = 100 - parameters.MaxSize = 3 - properties := gopter.NewProperties(parameters) - properties.Property( - "Round trip of PrometheusRuleGroupProperties_ARM via JSON returns original", - prop.ForAll(RunJSONSerializationTestForPrometheusRuleGroupProperties_ARM, PrometheusRuleGroupProperties_ARMGenerator())) - properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout)) -} - -// RunJSONSerializationTestForPrometheusRuleGroupProperties_ARM runs a test to see if a specific instance of PrometheusRuleGroupProperties_ARM round trips to JSON and back losslessly -func RunJSONSerializationTestForPrometheusRuleGroupProperties_ARM(subject PrometheusRuleGroupProperties_ARM) string { - // Serialize to JSON - bin, err := json.Marshal(subject) - if err != nil { - return err.Error() - } - - // Deserialize back into memory - var actual PrometheusRuleGroupProperties_ARM - err = json.Unmarshal(bin, &actual) - if err != nil { - return err.Error() - } - - // Check for outcome - match := cmp.Equal(subject, actual, cmpopts.EquateEmpty()) - if !match { - actualFmt := pretty.Sprint(actual) - subjectFmt := pretty.Sprint(subject) - result := diff.Diff(subjectFmt, actualFmt) - return result - } - - return "" -} - -// Generator of PrometheusRuleGroupProperties_ARM instances for property testing - lazily instantiated by -// PrometheusRuleGroupProperties_ARMGenerator() -var prometheusRuleGroupProperties_ARMGenerator gopter.Gen - -// PrometheusRuleGroupProperties_ARMGenerator returns a generator of PrometheusRuleGroupProperties_ARM instances for property testing. -// We first initialize prometheusRuleGroupProperties_ARMGenerator with a simplified generator based on the -// fields with primitive types then replacing it with a more complex one that also handles complex fields -// to ensure any cycles in the object graph properly terminate. -func PrometheusRuleGroupProperties_ARMGenerator() gopter.Gen { - if prometheusRuleGroupProperties_ARMGenerator != nil { - return prometheusRuleGroupProperties_ARMGenerator - } - - generators := make(map[string]gopter.Gen) - AddIndependentPropertyGeneratorsForPrometheusRuleGroupProperties_ARM(generators) - prometheusRuleGroupProperties_ARMGenerator = gen.Struct(reflect.TypeOf(PrometheusRuleGroupProperties_ARM{}), generators) - - // The above call to gen.Struct() captures the map, so create a new one - generators = make(map[string]gopter.Gen) - AddIndependentPropertyGeneratorsForPrometheusRuleGroupProperties_ARM(generators) - AddRelatedPropertyGeneratorsForPrometheusRuleGroupProperties_ARM(generators) - prometheusRuleGroupProperties_ARMGenerator = gen.Struct(reflect.TypeOf(PrometheusRuleGroupProperties_ARM{}), generators) - - return prometheusRuleGroupProperties_ARMGenerator -} - -// AddIndependentPropertyGeneratorsForPrometheusRuleGroupProperties_ARM is a factory method for creating gopter generators -func AddIndependentPropertyGeneratorsForPrometheusRuleGroupProperties_ARM(gens map[string]gopter.Gen) { - gens["ClusterName"] = gen.PtrOf(gen.AlphaString()) - gens["Description"] = gen.PtrOf(gen.AlphaString()) - gens["Enabled"] = gen.PtrOf(gen.Bool()) - gens["Interval"] = gen.PtrOf(gen.AlphaString()) - gens["Scopes"] = gen.SliceOf(gen.AlphaString()) -} - -// AddRelatedPropertyGeneratorsForPrometheusRuleGroupProperties_ARM is a factory method for creating gopter generators -func AddRelatedPropertyGeneratorsForPrometheusRuleGroupProperties_ARM(gens map[string]gopter.Gen) { - gens["Rules"] = gen.SliceOf(PrometheusRule_ARMGenerator()) -} - -func Test_PrometheusRuleGroup_Spec_ARM_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { - t.Parallel() - parameters := gopter.DefaultTestParameters() - parameters.MinSuccessfulTests = 80 - parameters.MaxSize = 3 - properties := gopter.NewProperties(parameters) - properties.Property( - "Round trip of PrometheusRuleGroup_Spec_ARM via JSON returns original", - prop.ForAll(RunJSONSerializationTestForPrometheusRuleGroup_Spec_ARM, PrometheusRuleGroup_Spec_ARMGenerator())) - properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout)) -} - -// RunJSONSerializationTestForPrometheusRuleGroup_Spec_ARM runs a test to see if a specific instance of PrometheusRuleGroup_Spec_ARM round trips to JSON and back losslessly -func RunJSONSerializationTestForPrometheusRuleGroup_Spec_ARM(subject PrometheusRuleGroup_Spec_ARM) string { - // Serialize to JSON - bin, err := json.Marshal(subject) - if err != nil { - return err.Error() - } - - // Deserialize back into memory - var actual PrometheusRuleGroup_Spec_ARM - err = json.Unmarshal(bin, &actual) - if err != nil { - return err.Error() - } - - // Check for outcome - match := cmp.Equal(subject, actual, cmpopts.EquateEmpty()) - if !match { - actualFmt := pretty.Sprint(actual) - subjectFmt := pretty.Sprint(subject) - result := diff.Diff(subjectFmt, actualFmt) - return result - } - - return "" -} - -// Generator of PrometheusRuleGroup_Spec_ARM instances for property testing - lazily instantiated by -// PrometheusRuleGroup_Spec_ARMGenerator() -var prometheusRuleGroup_Spec_ARMGenerator gopter.Gen - -// PrometheusRuleGroup_Spec_ARMGenerator returns a generator of PrometheusRuleGroup_Spec_ARM instances for property testing. -// We first initialize prometheusRuleGroup_Spec_ARMGenerator with a simplified generator based on the -// fields with primitive types then replacing it with a more complex one that also handles complex fields -// to ensure any cycles in the object graph properly terminate. -func PrometheusRuleGroup_Spec_ARMGenerator() gopter.Gen { - if prometheusRuleGroup_Spec_ARMGenerator != nil { - return prometheusRuleGroup_Spec_ARMGenerator - } - - generators := make(map[string]gopter.Gen) - AddIndependentPropertyGeneratorsForPrometheusRuleGroup_Spec_ARM(generators) - prometheusRuleGroup_Spec_ARMGenerator = gen.Struct(reflect.TypeOf(PrometheusRuleGroup_Spec_ARM{}), generators) - - // The above call to gen.Struct() captures the map, so create a new one - generators = make(map[string]gopter.Gen) - AddIndependentPropertyGeneratorsForPrometheusRuleGroup_Spec_ARM(generators) - AddRelatedPropertyGeneratorsForPrometheusRuleGroup_Spec_ARM(generators) - prometheusRuleGroup_Spec_ARMGenerator = gen.Struct(reflect.TypeOf(PrometheusRuleGroup_Spec_ARM{}), generators) - - return prometheusRuleGroup_Spec_ARMGenerator -} - -// AddIndependentPropertyGeneratorsForPrometheusRuleGroup_Spec_ARM is a factory method for creating gopter generators -func AddIndependentPropertyGeneratorsForPrometheusRuleGroup_Spec_ARM(gens map[string]gopter.Gen) { - gens["Location"] = gen.PtrOf(gen.AlphaString()) - gens["Name"] = gen.AlphaString() - gens["Tags"] = gen.MapOf( - gen.AlphaString(), - gen.AlphaString()) -} - -// AddRelatedPropertyGeneratorsForPrometheusRuleGroup_Spec_ARM is a factory method for creating gopter generators -func AddRelatedPropertyGeneratorsForPrometheusRuleGroup_Spec_ARM(gens map[string]gopter.Gen) { - gens["Properties"] = gen.PtrOf(PrometheusRuleGroupProperties_ARMGenerator()) -} - -func Test_PrometheusRuleResolveConfiguration_ARM_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { - t.Parallel() - parameters := gopter.DefaultTestParameters() - parameters.MinSuccessfulTests = 100 - parameters.MaxSize = 3 - properties := gopter.NewProperties(parameters) - properties.Property( - "Round trip of PrometheusRuleResolveConfiguration_ARM via JSON returns original", - prop.ForAll(RunJSONSerializationTestForPrometheusRuleResolveConfiguration_ARM, PrometheusRuleResolveConfiguration_ARMGenerator())) - properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout)) -} - -// RunJSONSerializationTestForPrometheusRuleResolveConfiguration_ARM runs a test to see if a specific instance of PrometheusRuleResolveConfiguration_ARM round trips to JSON and back losslessly -func RunJSONSerializationTestForPrometheusRuleResolveConfiguration_ARM(subject PrometheusRuleResolveConfiguration_ARM) string { - // Serialize to JSON - bin, err := json.Marshal(subject) - if err != nil { - return err.Error() - } - - // Deserialize back into memory - var actual PrometheusRuleResolveConfiguration_ARM - err = json.Unmarshal(bin, &actual) - if err != nil { - return err.Error() - } - - // Check for outcome - match := cmp.Equal(subject, actual, cmpopts.EquateEmpty()) - if !match { - actualFmt := pretty.Sprint(actual) - subjectFmt := pretty.Sprint(subject) - result := diff.Diff(subjectFmt, actualFmt) - return result - } - - return "" -} - -// Generator of PrometheusRuleResolveConfiguration_ARM instances for property testing - lazily instantiated by -// PrometheusRuleResolveConfiguration_ARMGenerator() -var prometheusRuleResolveConfiguration_ARMGenerator gopter.Gen - -// PrometheusRuleResolveConfiguration_ARMGenerator returns a generator of PrometheusRuleResolveConfiguration_ARM instances for property testing. -func PrometheusRuleResolveConfiguration_ARMGenerator() gopter.Gen { - if prometheusRuleResolveConfiguration_ARMGenerator != nil { - return prometheusRuleResolveConfiguration_ARMGenerator - } - - generators := make(map[string]gopter.Gen) - AddIndependentPropertyGeneratorsForPrometheusRuleResolveConfiguration_ARM(generators) - prometheusRuleResolveConfiguration_ARMGenerator = gen.Struct(reflect.TypeOf(PrometheusRuleResolveConfiguration_ARM{}), generators) - - return prometheusRuleResolveConfiguration_ARMGenerator -} - -// AddIndependentPropertyGeneratorsForPrometheusRuleResolveConfiguration_ARM is a factory method for creating gopter generators -func AddIndependentPropertyGeneratorsForPrometheusRuleResolveConfiguration_ARM(gens map[string]gopter.Gen) { - gens["AutoResolved"] = gen.PtrOf(gen.Bool()) - gens["TimeToResolve"] = gen.PtrOf(gen.AlphaString()) -} - -func Test_PrometheusRule_ARM_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { - t.Parallel() - parameters := gopter.DefaultTestParameters() - parameters.MinSuccessfulTests = 100 - parameters.MaxSize = 3 - properties := gopter.NewProperties(parameters) - properties.Property( - "Round trip of PrometheusRule_ARM via JSON returns original", - prop.ForAll(RunJSONSerializationTestForPrometheusRule_ARM, PrometheusRule_ARMGenerator())) - properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout)) -} - -// RunJSONSerializationTestForPrometheusRule_ARM runs a test to see if a specific instance of PrometheusRule_ARM round trips to JSON and back losslessly -func RunJSONSerializationTestForPrometheusRule_ARM(subject PrometheusRule_ARM) string { - // Serialize to JSON - bin, err := json.Marshal(subject) - if err != nil { - return err.Error() - } - - // Deserialize back into memory - var actual PrometheusRule_ARM - err = json.Unmarshal(bin, &actual) - if err != nil { - return err.Error() - } - - // Check for outcome - match := cmp.Equal(subject, actual, cmpopts.EquateEmpty()) - if !match { - actualFmt := pretty.Sprint(actual) - subjectFmt := pretty.Sprint(subject) - result := diff.Diff(subjectFmt, actualFmt) - return result - } - - return "" -} - -// Generator of PrometheusRule_ARM instances for property testing - lazily instantiated by PrometheusRule_ARMGenerator() -var prometheusRule_ARMGenerator gopter.Gen - -// PrometheusRule_ARMGenerator returns a generator of PrometheusRule_ARM instances for property testing. -// We first initialize prometheusRule_ARMGenerator with a simplified generator based on the -// fields with primitive types then replacing it with a more complex one that also handles complex fields -// to ensure any cycles in the object graph properly terminate. -func PrometheusRule_ARMGenerator() gopter.Gen { - if prometheusRule_ARMGenerator != nil { - return prometheusRule_ARMGenerator - } - - generators := make(map[string]gopter.Gen) - AddIndependentPropertyGeneratorsForPrometheusRule_ARM(generators) - prometheusRule_ARMGenerator = gen.Struct(reflect.TypeOf(PrometheusRule_ARM{}), generators) - - // The above call to gen.Struct() captures the map, so create a new one - generators = make(map[string]gopter.Gen) - AddIndependentPropertyGeneratorsForPrometheusRule_ARM(generators) - AddRelatedPropertyGeneratorsForPrometheusRule_ARM(generators) - prometheusRule_ARMGenerator = gen.Struct(reflect.TypeOf(PrometheusRule_ARM{}), generators) - - return prometheusRule_ARMGenerator -} - -// AddIndependentPropertyGeneratorsForPrometheusRule_ARM is a factory method for creating gopter generators -func AddIndependentPropertyGeneratorsForPrometheusRule_ARM(gens map[string]gopter.Gen) { - gens["Alert"] = gen.PtrOf(gen.AlphaString()) - gens["Annotations"] = gen.MapOf( - gen.AlphaString(), - gen.AlphaString()) - gens["Enabled"] = gen.PtrOf(gen.Bool()) - gens["Expression"] = gen.PtrOf(gen.AlphaString()) - gens["For"] = gen.PtrOf(gen.AlphaString()) - gens["Labels"] = gen.MapOf( - gen.AlphaString(), - gen.AlphaString()) - gens["Record"] = gen.PtrOf(gen.AlphaString()) - gens["Severity"] = gen.PtrOf(gen.Int()) -} - -// AddRelatedPropertyGeneratorsForPrometheusRule_ARM is a factory method for creating gopter generators -func AddRelatedPropertyGeneratorsForPrometheusRule_ARM(gens map[string]gopter.Gen) { - gens["Actions"] = gen.SliceOf(PrometheusRuleGroupAction_ARMGenerator()) - gens["ResolveConfiguration"] = gen.PtrOf(PrometheusRuleResolveConfiguration_ARMGenerator()) -} diff --git a/v2/api/alertsmanagement/v1api20230301/prometheus_rule_group_status_arm_types_gen_test.go b/v2/api/alertsmanagement/v1api20230301/prometheus_rule_group_status_arm_types_gen_test.go deleted file mode 100644 index ec54b6cd3c..0000000000 --- a/v2/api/alertsmanagement/v1api20230301/prometheus_rule_group_status_arm_types_gen_test.go +++ /dev/null @@ -1,466 +0,0 @@ -// Code generated by azure-service-operator-codegen. DO NOT EDIT. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. -package v1api20230301 - -import ( - "encoding/json" - "github.com/google/go-cmp/cmp" - "github.com/google/go-cmp/cmp/cmpopts" - "github.com/kr/pretty" - "github.com/kylelemons/godebug/diff" - "github.com/leanovate/gopter" - "github.com/leanovate/gopter/gen" - "github.com/leanovate/gopter/prop" - "os" - "reflect" - "testing" -) - -func Test_PrometheusRuleGroupAction_STATUS_ARM_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { - t.Parallel() - parameters := gopter.DefaultTestParameters() - parameters.MinSuccessfulTests = 80 - parameters.MaxSize = 3 - properties := gopter.NewProperties(parameters) - properties.Property( - "Round trip of PrometheusRuleGroupAction_STATUS_ARM via JSON returns original", - prop.ForAll(RunJSONSerializationTestForPrometheusRuleGroupAction_STATUS_ARM, PrometheusRuleGroupAction_STATUS_ARMGenerator())) - properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout)) -} - -// RunJSONSerializationTestForPrometheusRuleGroupAction_STATUS_ARM runs a test to see if a specific instance of PrometheusRuleGroupAction_STATUS_ARM round trips to JSON and back losslessly -func RunJSONSerializationTestForPrometheusRuleGroupAction_STATUS_ARM(subject PrometheusRuleGroupAction_STATUS_ARM) string { - // Serialize to JSON - bin, err := json.Marshal(subject) - if err != nil { - return err.Error() - } - - // Deserialize back into memory - var actual PrometheusRuleGroupAction_STATUS_ARM - err = json.Unmarshal(bin, &actual) - if err != nil { - return err.Error() - } - - // Check for outcome - match := cmp.Equal(subject, actual, cmpopts.EquateEmpty()) - if !match { - actualFmt := pretty.Sprint(actual) - subjectFmt := pretty.Sprint(subject) - result := diff.Diff(subjectFmt, actualFmt) - return result - } - - return "" -} - -// Generator of PrometheusRuleGroupAction_STATUS_ARM instances for property testing - lazily instantiated by -// PrometheusRuleGroupAction_STATUS_ARMGenerator() -var prometheusRuleGroupAction_STATUS_ARMGenerator gopter.Gen - -// PrometheusRuleGroupAction_STATUS_ARMGenerator returns a generator of PrometheusRuleGroupAction_STATUS_ARM instances for property testing. -func PrometheusRuleGroupAction_STATUS_ARMGenerator() gopter.Gen { - if prometheusRuleGroupAction_STATUS_ARMGenerator != nil { - return prometheusRuleGroupAction_STATUS_ARMGenerator - } - - generators := make(map[string]gopter.Gen) - AddIndependentPropertyGeneratorsForPrometheusRuleGroupAction_STATUS_ARM(generators) - prometheusRuleGroupAction_STATUS_ARMGenerator = gen.Struct(reflect.TypeOf(PrometheusRuleGroupAction_STATUS_ARM{}), generators) - - return prometheusRuleGroupAction_STATUS_ARMGenerator -} - -// AddIndependentPropertyGeneratorsForPrometheusRuleGroupAction_STATUS_ARM is a factory method for creating gopter generators -func AddIndependentPropertyGeneratorsForPrometheusRuleGroupAction_STATUS_ARM(gens map[string]gopter.Gen) { - gens["ActionGroupId"] = gen.PtrOf(gen.AlphaString()) - gens["ActionProperties"] = gen.MapOf( - gen.AlphaString(), - gen.AlphaString()) -} - -func Test_PrometheusRuleGroupProperties_STATUS_ARM_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { - t.Parallel() - parameters := gopter.DefaultTestParameters() - parameters.MinSuccessfulTests = 80 - parameters.MaxSize = 3 - properties := gopter.NewProperties(parameters) - properties.Property( - "Round trip of PrometheusRuleGroupProperties_STATUS_ARM via JSON returns original", - prop.ForAll(RunJSONSerializationTestForPrometheusRuleGroupProperties_STATUS_ARM, PrometheusRuleGroupProperties_STATUS_ARMGenerator())) - properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout)) -} - -// RunJSONSerializationTestForPrometheusRuleGroupProperties_STATUS_ARM runs a test to see if a specific instance of PrometheusRuleGroupProperties_STATUS_ARM round trips to JSON and back losslessly -func RunJSONSerializationTestForPrometheusRuleGroupProperties_STATUS_ARM(subject PrometheusRuleGroupProperties_STATUS_ARM) string { - // Serialize to JSON - bin, err := json.Marshal(subject) - if err != nil { - return err.Error() - } - - // Deserialize back into memory - var actual PrometheusRuleGroupProperties_STATUS_ARM - err = json.Unmarshal(bin, &actual) - if err != nil { - return err.Error() - } - - // Check for outcome - match := cmp.Equal(subject, actual, cmpopts.EquateEmpty()) - if !match { - actualFmt := pretty.Sprint(actual) - subjectFmt := pretty.Sprint(subject) - result := diff.Diff(subjectFmt, actualFmt) - return result - } - - return "" -} - -// Generator of PrometheusRuleGroupProperties_STATUS_ARM instances for property testing - lazily instantiated by -// PrometheusRuleGroupProperties_STATUS_ARMGenerator() -var prometheusRuleGroupProperties_STATUS_ARMGenerator gopter.Gen - -// PrometheusRuleGroupProperties_STATUS_ARMGenerator returns a generator of PrometheusRuleGroupProperties_STATUS_ARM instances for property testing. -// We first initialize prometheusRuleGroupProperties_STATUS_ARMGenerator with a simplified generator based on the -// fields with primitive types then replacing it with a more complex one that also handles complex fields -// to ensure any cycles in the object graph properly terminate. -func PrometheusRuleGroupProperties_STATUS_ARMGenerator() gopter.Gen { - if prometheusRuleGroupProperties_STATUS_ARMGenerator != nil { - return prometheusRuleGroupProperties_STATUS_ARMGenerator - } - - generators := make(map[string]gopter.Gen) - AddIndependentPropertyGeneratorsForPrometheusRuleGroupProperties_STATUS_ARM(generators) - prometheusRuleGroupProperties_STATUS_ARMGenerator = gen.Struct(reflect.TypeOf(PrometheusRuleGroupProperties_STATUS_ARM{}), generators) - - // The above call to gen.Struct() captures the map, so create a new one - generators = make(map[string]gopter.Gen) - AddIndependentPropertyGeneratorsForPrometheusRuleGroupProperties_STATUS_ARM(generators) - AddRelatedPropertyGeneratorsForPrometheusRuleGroupProperties_STATUS_ARM(generators) - prometheusRuleGroupProperties_STATUS_ARMGenerator = gen.Struct(reflect.TypeOf(PrometheusRuleGroupProperties_STATUS_ARM{}), generators) - - return prometheusRuleGroupProperties_STATUS_ARMGenerator -} - -// AddIndependentPropertyGeneratorsForPrometheusRuleGroupProperties_STATUS_ARM is a factory method for creating gopter generators -func AddIndependentPropertyGeneratorsForPrometheusRuleGroupProperties_STATUS_ARM(gens map[string]gopter.Gen) { - gens["ClusterName"] = gen.PtrOf(gen.AlphaString()) - gens["Description"] = gen.PtrOf(gen.AlphaString()) - gens["Enabled"] = gen.PtrOf(gen.Bool()) - gens["Interval"] = gen.PtrOf(gen.AlphaString()) - gens["Scopes"] = gen.SliceOf(gen.AlphaString()) -} - -// AddRelatedPropertyGeneratorsForPrometheusRuleGroupProperties_STATUS_ARM is a factory method for creating gopter generators -func AddRelatedPropertyGeneratorsForPrometheusRuleGroupProperties_STATUS_ARM(gens map[string]gopter.Gen) { - gens["Rules"] = gen.SliceOf(PrometheusRule_STATUS_ARMGenerator()) -} - -func Test_PrometheusRuleGroup_STATUS_ARM_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { - t.Parallel() - parameters := gopter.DefaultTestParameters() - parameters.MinSuccessfulTests = 80 - parameters.MaxSize = 3 - properties := gopter.NewProperties(parameters) - properties.Property( - "Round trip of PrometheusRuleGroup_STATUS_ARM via JSON returns original", - prop.ForAll(RunJSONSerializationTestForPrometheusRuleGroup_STATUS_ARM, PrometheusRuleGroup_STATUS_ARMGenerator())) - properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout)) -} - -// RunJSONSerializationTestForPrometheusRuleGroup_STATUS_ARM runs a test to see if a specific instance of PrometheusRuleGroup_STATUS_ARM round trips to JSON and back losslessly -func RunJSONSerializationTestForPrometheusRuleGroup_STATUS_ARM(subject PrometheusRuleGroup_STATUS_ARM) string { - // Serialize to JSON - bin, err := json.Marshal(subject) - if err != nil { - return err.Error() - } - - // Deserialize back into memory - var actual PrometheusRuleGroup_STATUS_ARM - err = json.Unmarshal(bin, &actual) - if err != nil { - return err.Error() - } - - // Check for outcome - match := cmp.Equal(subject, actual, cmpopts.EquateEmpty()) - if !match { - actualFmt := pretty.Sprint(actual) - subjectFmt := pretty.Sprint(subject) - result := diff.Diff(subjectFmt, actualFmt) - return result - } - - return "" -} - -// Generator of PrometheusRuleGroup_STATUS_ARM instances for property testing - lazily instantiated by -// PrometheusRuleGroup_STATUS_ARMGenerator() -var prometheusRuleGroup_STATUS_ARMGenerator gopter.Gen - -// PrometheusRuleGroup_STATUS_ARMGenerator returns a generator of PrometheusRuleGroup_STATUS_ARM instances for property testing. -// We first initialize prometheusRuleGroup_STATUS_ARMGenerator with a simplified generator based on the -// fields with primitive types then replacing it with a more complex one that also handles complex fields -// to ensure any cycles in the object graph properly terminate. -func PrometheusRuleGroup_STATUS_ARMGenerator() gopter.Gen { - if prometheusRuleGroup_STATUS_ARMGenerator != nil { - return prometheusRuleGroup_STATUS_ARMGenerator - } - - generators := make(map[string]gopter.Gen) - AddIndependentPropertyGeneratorsForPrometheusRuleGroup_STATUS_ARM(generators) - prometheusRuleGroup_STATUS_ARMGenerator = gen.Struct(reflect.TypeOf(PrometheusRuleGroup_STATUS_ARM{}), generators) - - // The above call to gen.Struct() captures the map, so create a new one - generators = make(map[string]gopter.Gen) - AddIndependentPropertyGeneratorsForPrometheusRuleGroup_STATUS_ARM(generators) - AddRelatedPropertyGeneratorsForPrometheusRuleGroup_STATUS_ARM(generators) - prometheusRuleGroup_STATUS_ARMGenerator = gen.Struct(reflect.TypeOf(PrometheusRuleGroup_STATUS_ARM{}), generators) - - return prometheusRuleGroup_STATUS_ARMGenerator -} - -// AddIndependentPropertyGeneratorsForPrometheusRuleGroup_STATUS_ARM is a factory method for creating gopter generators -func AddIndependentPropertyGeneratorsForPrometheusRuleGroup_STATUS_ARM(gens map[string]gopter.Gen) { - gens["Id"] = gen.PtrOf(gen.AlphaString()) - gens["Location"] = gen.PtrOf(gen.AlphaString()) - gens["Name"] = gen.PtrOf(gen.AlphaString()) - gens["Tags"] = gen.MapOf( - gen.AlphaString(), - gen.AlphaString()) - gens["Type"] = gen.PtrOf(gen.AlphaString()) -} - -// AddRelatedPropertyGeneratorsForPrometheusRuleGroup_STATUS_ARM is a factory method for creating gopter generators -func AddRelatedPropertyGeneratorsForPrometheusRuleGroup_STATUS_ARM(gens map[string]gopter.Gen) { - gens["Properties"] = gen.PtrOf(PrometheusRuleGroupProperties_STATUS_ARMGenerator()) - gens["SystemData"] = gen.PtrOf(SystemData_STATUS_ARMGenerator()) -} - -func Test_PrometheusRuleResolveConfiguration_STATUS_ARM_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { - t.Parallel() - parameters := gopter.DefaultTestParameters() - parameters.MinSuccessfulTests = 80 - parameters.MaxSize = 3 - properties := gopter.NewProperties(parameters) - properties.Property( - "Round trip of PrometheusRuleResolveConfiguration_STATUS_ARM via JSON returns original", - prop.ForAll(RunJSONSerializationTestForPrometheusRuleResolveConfiguration_STATUS_ARM, PrometheusRuleResolveConfiguration_STATUS_ARMGenerator())) - properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout)) -} - -// RunJSONSerializationTestForPrometheusRuleResolveConfiguration_STATUS_ARM runs a test to see if a specific instance of PrometheusRuleResolveConfiguration_STATUS_ARM round trips to JSON and back losslessly -func RunJSONSerializationTestForPrometheusRuleResolveConfiguration_STATUS_ARM(subject PrometheusRuleResolveConfiguration_STATUS_ARM) string { - // Serialize to JSON - bin, err := json.Marshal(subject) - if err != nil { - return err.Error() - } - - // Deserialize back into memory - var actual PrometheusRuleResolveConfiguration_STATUS_ARM - err = json.Unmarshal(bin, &actual) - if err != nil { - return err.Error() - } - - // Check for outcome - match := cmp.Equal(subject, actual, cmpopts.EquateEmpty()) - if !match { - actualFmt := pretty.Sprint(actual) - subjectFmt := pretty.Sprint(subject) - result := diff.Diff(subjectFmt, actualFmt) - return result - } - - return "" -} - -// Generator of PrometheusRuleResolveConfiguration_STATUS_ARM instances for property testing - lazily instantiated by -// PrometheusRuleResolveConfiguration_STATUS_ARMGenerator() -var prometheusRuleResolveConfiguration_STATUS_ARMGenerator gopter.Gen - -// PrometheusRuleResolveConfiguration_STATUS_ARMGenerator returns a generator of PrometheusRuleResolveConfiguration_STATUS_ARM instances for property testing. -func PrometheusRuleResolveConfiguration_STATUS_ARMGenerator() gopter.Gen { - if prometheusRuleResolveConfiguration_STATUS_ARMGenerator != nil { - return prometheusRuleResolveConfiguration_STATUS_ARMGenerator - } - - generators := make(map[string]gopter.Gen) - AddIndependentPropertyGeneratorsForPrometheusRuleResolveConfiguration_STATUS_ARM(generators) - prometheusRuleResolveConfiguration_STATUS_ARMGenerator = gen.Struct(reflect.TypeOf(PrometheusRuleResolveConfiguration_STATUS_ARM{}), generators) - - return prometheusRuleResolveConfiguration_STATUS_ARMGenerator -} - -// AddIndependentPropertyGeneratorsForPrometheusRuleResolveConfiguration_STATUS_ARM is a factory method for creating gopter generators -func AddIndependentPropertyGeneratorsForPrometheusRuleResolveConfiguration_STATUS_ARM(gens map[string]gopter.Gen) { - gens["AutoResolved"] = gen.PtrOf(gen.Bool()) - gens["TimeToResolve"] = gen.PtrOf(gen.AlphaString()) -} - -func Test_PrometheusRule_STATUS_ARM_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { - t.Parallel() - parameters := gopter.DefaultTestParameters() - parameters.MinSuccessfulTests = 80 - parameters.MaxSize = 3 - properties := gopter.NewProperties(parameters) - properties.Property( - "Round trip of PrometheusRule_STATUS_ARM via JSON returns original", - prop.ForAll(RunJSONSerializationTestForPrometheusRule_STATUS_ARM, PrometheusRule_STATUS_ARMGenerator())) - properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout)) -} - -// RunJSONSerializationTestForPrometheusRule_STATUS_ARM runs a test to see if a specific instance of PrometheusRule_STATUS_ARM round trips to JSON and back losslessly -func RunJSONSerializationTestForPrometheusRule_STATUS_ARM(subject PrometheusRule_STATUS_ARM) string { - // Serialize to JSON - bin, err := json.Marshal(subject) - if err != nil { - return err.Error() - } - - // Deserialize back into memory - var actual PrometheusRule_STATUS_ARM - err = json.Unmarshal(bin, &actual) - if err != nil { - return err.Error() - } - - // Check for outcome - match := cmp.Equal(subject, actual, cmpopts.EquateEmpty()) - if !match { - actualFmt := pretty.Sprint(actual) - subjectFmt := pretty.Sprint(subject) - result := diff.Diff(subjectFmt, actualFmt) - return result - } - - return "" -} - -// Generator of PrometheusRule_STATUS_ARM instances for property testing - lazily instantiated by -// PrometheusRule_STATUS_ARMGenerator() -var prometheusRule_STATUS_ARMGenerator gopter.Gen - -// PrometheusRule_STATUS_ARMGenerator returns a generator of PrometheusRule_STATUS_ARM instances for property testing. -// We first initialize prometheusRule_STATUS_ARMGenerator with a simplified generator based on the -// fields with primitive types then replacing it with a more complex one that also handles complex fields -// to ensure any cycles in the object graph properly terminate. -func PrometheusRule_STATUS_ARMGenerator() gopter.Gen { - if prometheusRule_STATUS_ARMGenerator != nil { - return prometheusRule_STATUS_ARMGenerator - } - - generators := make(map[string]gopter.Gen) - AddIndependentPropertyGeneratorsForPrometheusRule_STATUS_ARM(generators) - prometheusRule_STATUS_ARMGenerator = gen.Struct(reflect.TypeOf(PrometheusRule_STATUS_ARM{}), generators) - - // The above call to gen.Struct() captures the map, so create a new one - generators = make(map[string]gopter.Gen) - AddIndependentPropertyGeneratorsForPrometheusRule_STATUS_ARM(generators) - AddRelatedPropertyGeneratorsForPrometheusRule_STATUS_ARM(generators) - prometheusRule_STATUS_ARMGenerator = gen.Struct(reflect.TypeOf(PrometheusRule_STATUS_ARM{}), generators) - - return prometheusRule_STATUS_ARMGenerator -} - -// AddIndependentPropertyGeneratorsForPrometheusRule_STATUS_ARM is a factory method for creating gopter generators -func AddIndependentPropertyGeneratorsForPrometheusRule_STATUS_ARM(gens map[string]gopter.Gen) { - gens["Alert"] = gen.PtrOf(gen.AlphaString()) - gens["Annotations"] = gen.MapOf( - gen.AlphaString(), - gen.AlphaString()) - gens["Enabled"] = gen.PtrOf(gen.Bool()) - gens["Expression"] = gen.PtrOf(gen.AlphaString()) - gens["For"] = gen.PtrOf(gen.AlphaString()) - gens["Labels"] = gen.MapOf( - gen.AlphaString(), - gen.AlphaString()) - gens["Record"] = gen.PtrOf(gen.AlphaString()) - gens["Severity"] = gen.PtrOf(gen.Int()) -} - -// AddRelatedPropertyGeneratorsForPrometheusRule_STATUS_ARM is a factory method for creating gopter generators -func AddRelatedPropertyGeneratorsForPrometheusRule_STATUS_ARM(gens map[string]gopter.Gen) { - gens["Actions"] = gen.SliceOf(PrometheusRuleGroupAction_STATUS_ARMGenerator()) - gens["ResolveConfiguration"] = gen.PtrOf(PrometheusRuleResolveConfiguration_STATUS_ARMGenerator()) -} - -func Test_SystemData_STATUS_ARM_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { - t.Parallel() - parameters := gopter.DefaultTestParameters() - parameters.MinSuccessfulTests = 80 - parameters.MaxSize = 3 - properties := gopter.NewProperties(parameters) - properties.Property( - "Round trip of SystemData_STATUS_ARM via JSON returns original", - prop.ForAll(RunJSONSerializationTestForSystemData_STATUS_ARM, SystemData_STATUS_ARMGenerator())) - properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout)) -} - -// RunJSONSerializationTestForSystemData_STATUS_ARM runs a test to see if a specific instance of SystemData_STATUS_ARM round trips to JSON and back losslessly -func RunJSONSerializationTestForSystemData_STATUS_ARM(subject SystemData_STATUS_ARM) string { - // Serialize to JSON - bin, err := json.Marshal(subject) - if err != nil { - return err.Error() - } - - // Deserialize back into memory - var actual SystemData_STATUS_ARM - err = json.Unmarshal(bin, &actual) - if err != nil { - return err.Error() - } - - // Check for outcome - match := cmp.Equal(subject, actual, cmpopts.EquateEmpty()) - if !match { - actualFmt := pretty.Sprint(actual) - subjectFmt := pretty.Sprint(subject) - result := diff.Diff(subjectFmt, actualFmt) - return result - } - - return "" -} - -// Generator of SystemData_STATUS_ARM instances for property testing - lazily instantiated by -// SystemData_STATUS_ARMGenerator() -var systemData_STATUS_ARMGenerator gopter.Gen - -// SystemData_STATUS_ARMGenerator returns a generator of SystemData_STATUS_ARM instances for property testing. -func SystemData_STATUS_ARMGenerator() gopter.Gen { - if systemData_STATUS_ARMGenerator != nil { - return systemData_STATUS_ARMGenerator - } - - generators := make(map[string]gopter.Gen) - AddIndependentPropertyGeneratorsForSystemData_STATUS_ARM(generators) - systemData_STATUS_ARMGenerator = gen.Struct(reflect.TypeOf(SystemData_STATUS_ARM{}), generators) - - return systemData_STATUS_ARMGenerator -} - -// AddIndependentPropertyGeneratorsForSystemData_STATUS_ARM is a factory method for creating gopter generators -func AddIndependentPropertyGeneratorsForSystemData_STATUS_ARM(gens map[string]gopter.Gen) { - gens["CreatedAt"] = gen.PtrOf(gen.AlphaString()) - gens["CreatedBy"] = gen.PtrOf(gen.AlphaString()) - gens["CreatedByType"] = gen.PtrOf(gen.OneConstOf( - SystemData_CreatedByType_STATUS_Application, - SystemData_CreatedByType_STATUS_Key, - SystemData_CreatedByType_STATUS_ManagedIdentity, - SystemData_CreatedByType_STATUS_User)) - gens["LastModifiedAt"] = gen.PtrOf(gen.AlphaString()) - gens["LastModifiedBy"] = gen.PtrOf(gen.AlphaString()) - gens["LastModifiedByType"] = gen.PtrOf(gen.OneConstOf( - SystemData_LastModifiedByType_STATUS_Application, - SystemData_LastModifiedByType_STATUS_Key, - SystemData_LastModifiedByType_STATUS_ManagedIdentity, - SystemData_LastModifiedByType_STATUS_User)) -} diff --git a/v2/api/alertsmanagement/v1api20230301/prometheus_rule_group_types_gen.go b/v2/api/alertsmanagement/v1api20230301/prometheus_rule_group_types_gen.go index be90c9a900..bcca15e8a5 100644 --- a/v2/api/alertsmanagement/v1api20230301/prometheus_rule_group_types_gen.go +++ b/v2/api/alertsmanagement/v1api20230301/prometheus_rule_group_types_gen.go @@ -5,6 +5,7 @@ package v1api20230301 import ( "fmt" + arm "github.com/Azure/azure-service-operator/v2/api/alertsmanagement/v1api20230301/arm" storage "github.com/Azure/azure-service-operator/v2/api/alertsmanagement/v1api20230301/storage" "github.com/Azure/azure-service-operator/v2/internal/reflecthelpers" "github.com/Azure/azure-service-operator/v2/pkg/genruntime" @@ -378,7 +379,7 @@ func (group *PrometheusRuleGroup_Spec) ConvertToARM(resolved genruntime.ConvertT if group == nil { return nil, nil } - result := &PrometheusRuleGroup_Spec_ARM{} + result := &arm.PrometheusRuleGroup_Spec{} // Set property "Location": if group.Location != nil { @@ -396,7 +397,7 @@ func (group *PrometheusRuleGroup_Spec) ConvertToARM(resolved genruntime.ConvertT group.Interval != nil || group.Rules != nil || group.ScopesReferences != nil { - result.Properties = &PrometheusRuleGroupProperties_ARM{} + result.Properties = &arm.PrometheusRuleGroupProperties{} } if group.ClusterName != nil { clusterName := *group.ClusterName @@ -419,7 +420,7 @@ func (group *PrometheusRuleGroup_Spec) ConvertToARM(resolved genruntime.ConvertT if err != nil { return nil, err } - result.Properties.Rules = append(result.Properties.Rules, *item_ARM.(*PrometheusRule_ARM)) + result.Properties.Rules = append(result.Properties.Rules, *item_ARM.(*arm.PrometheusRule)) } for _, item := range group.ScopesReferences { itemARMID, err := resolved.ResolvedReferences.Lookup(item) @@ -441,14 +442,14 @@ func (group *PrometheusRuleGroup_Spec) ConvertToARM(resolved genruntime.ConvertT // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (group *PrometheusRuleGroup_Spec) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &PrometheusRuleGroup_Spec_ARM{} + return &arm.PrometheusRuleGroup_Spec{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (group *PrometheusRuleGroup_Spec) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(PrometheusRuleGroup_Spec_ARM) + typedInput, ok := armInput.(arm.PrometheusRuleGroup_Spec) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected PrometheusRuleGroup_Spec_ARM, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.PrometheusRuleGroup_Spec, got %T", armInput) } // Set property "AzureName": @@ -889,14 +890,14 @@ var _ genruntime.FromARMConverter = &PrometheusRuleGroup_STATUS{} // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (group *PrometheusRuleGroup_STATUS) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &PrometheusRuleGroup_STATUS_ARM{} + return &arm.PrometheusRuleGroup_STATUS{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (group *PrometheusRuleGroup_STATUS) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(PrometheusRuleGroup_STATUS_ARM) + typedInput, ok := armInput.(arm.PrometheusRuleGroup_STATUS) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected PrometheusRuleGroup_STATUS_ARM, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.PrometheusRuleGroup_STATUS, got %T", armInput) } // Set property "ClusterName": @@ -1208,7 +1209,7 @@ func (rule *PrometheusRule) ConvertToARM(resolved genruntime.ConvertToARMResolve if rule == nil { return nil, nil } - result := &PrometheusRule_ARM{} + result := &arm.PrometheusRule{} // Set property "Actions": for _, item := range rule.Actions { @@ -1216,7 +1217,7 @@ func (rule *PrometheusRule) ConvertToARM(resolved genruntime.ConvertToARMResolve if err != nil { return nil, err } - result.Actions = append(result.Actions, *item_ARM.(*PrometheusRuleGroupAction_ARM)) + result.Actions = append(result.Actions, *item_ARM.(*arm.PrometheusRuleGroupAction)) } // Set property "Alert": @@ -1271,7 +1272,7 @@ func (rule *PrometheusRule) ConvertToARM(resolved genruntime.ConvertToARMResolve if err != nil { return nil, err } - resolveConfiguration := *resolveConfiguration_ARM.(*PrometheusRuleResolveConfiguration_ARM) + resolveConfiguration := *resolveConfiguration_ARM.(*arm.PrometheusRuleResolveConfiguration) result.ResolveConfiguration = &resolveConfiguration } @@ -1285,14 +1286,14 @@ func (rule *PrometheusRule) ConvertToARM(resolved genruntime.ConvertToARMResolve // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (rule *PrometheusRule) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &PrometheusRule_ARM{} + return &arm.PrometheusRule{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (rule *PrometheusRule) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(PrometheusRule_ARM) + typedInput, ok := armInput.(arm.PrometheusRule) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected PrometheusRule_ARM, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.PrometheusRule, got %T", armInput) } // Set property "Actions": @@ -1619,14 +1620,14 @@ var _ genruntime.FromARMConverter = &PrometheusRule_STATUS{} // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (rule *PrometheusRule_STATUS) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &PrometheusRule_STATUS_ARM{} + return &arm.PrometheusRule_STATUS{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (rule *PrometheusRule_STATUS) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(PrometheusRule_STATUS_ARM) + typedInput, ok := armInput.(arm.PrometheusRule_STATUS) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected PrometheusRule_STATUS_ARM, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.PrometheusRule_STATUS, got %T", armInput) } // Set property "Actions": @@ -1872,14 +1873,14 @@ var _ genruntime.FromARMConverter = &SystemData_STATUS{} // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (data *SystemData_STATUS) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &SystemData_STATUS_ARM{} + return &arm.SystemData_STATUS{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (data *SystemData_STATUS) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(SystemData_STATUS_ARM) + typedInput, ok := armInput.(arm.SystemData_STATUS) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected SystemData_STATUS_ARM, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.SystemData_STATUS, got %T", armInput) } // Set property "CreatedAt": @@ -2019,7 +2020,7 @@ func (action *PrometheusRuleGroupAction) ConvertToARM(resolved genruntime.Conver if action == nil { return nil, nil } - result := &PrometheusRuleGroupAction_ARM{} + result := &arm.PrometheusRuleGroupAction{} // Set property "ActionGroupId": if action.ActionGroupReference != nil { @@ -2043,14 +2044,14 @@ func (action *PrometheusRuleGroupAction) ConvertToARM(resolved genruntime.Conver // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (action *PrometheusRuleGroupAction) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &PrometheusRuleGroupAction_ARM{} + return &arm.PrometheusRuleGroupAction{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (action *PrometheusRuleGroupAction) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(PrometheusRuleGroupAction_ARM) + typedInput, ok := armInput.(arm.PrometheusRuleGroupAction) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected PrometheusRuleGroupAction_ARM, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.PrometheusRuleGroupAction, got %T", armInput) } // no assignment for property "ActionGroupReference" @@ -2143,14 +2144,14 @@ var _ genruntime.FromARMConverter = &PrometheusRuleGroupAction_STATUS{} // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (action *PrometheusRuleGroupAction_STATUS) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &PrometheusRuleGroupAction_STATUS_ARM{} + return &arm.PrometheusRuleGroupAction_STATUS{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (action *PrometheusRuleGroupAction_STATUS) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(PrometheusRuleGroupAction_STATUS_ARM) + typedInput, ok := armInput.(arm.PrometheusRuleGroupAction_STATUS) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected PrometheusRuleGroupAction_STATUS_ARM, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.PrometheusRuleGroupAction_STATUS, got %T", armInput) } // Set property "ActionGroupId": @@ -2222,7 +2223,7 @@ func (configuration *PrometheusRuleResolveConfiguration) ConvertToARM(resolved g if configuration == nil { return nil, nil } - result := &PrometheusRuleResolveConfiguration_ARM{} + result := &arm.PrometheusRuleResolveConfiguration{} // Set property "AutoResolved": if configuration.AutoResolved != nil { @@ -2240,14 +2241,14 @@ func (configuration *PrometheusRuleResolveConfiguration) ConvertToARM(resolved g // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (configuration *PrometheusRuleResolveConfiguration) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &PrometheusRuleResolveConfiguration_ARM{} + return &arm.PrometheusRuleResolveConfiguration{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (configuration *PrometheusRuleResolveConfiguration) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(PrometheusRuleResolveConfiguration_ARM) + typedInput, ok := armInput.(arm.PrometheusRuleResolveConfiguration) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected PrometheusRuleResolveConfiguration_ARM, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.PrometheusRuleResolveConfiguration, got %T", armInput) } // Set property "AutoResolved": @@ -2342,14 +2343,14 @@ var _ genruntime.FromARMConverter = &PrometheusRuleResolveConfiguration_STATUS{} // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (configuration *PrometheusRuleResolveConfiguration_STATUS) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &PrometheusRuleResolveConfiguration_STATUS_ARM{} + return &arm.PrometheusRuleResolveConfiguration_STATUS{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (configuration *PrometheusRuleResolveConfiguration_STATUS) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(PrometheusRuleResolveConfiguration_STATUS_ARM) + typedInput, ok := armInput.(arm.PrometheusRuleResolveConfiguration_STATUS) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected PrometheusRuleResolveConfiguration_STATUS_ARM, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.PrometheusRuleResolveConfiguration_STATUS, got %T", armInput) } // Set property "AutoResolved": @@ -2413,6 +2414,40 @@ func (configuration *PrometheusRuleResolveConfiguration_STATUS) AssignProperties return nil } +type SystemData_CreatedByType_STATUS string + +const ( + SystemData_CreatedByType_STATUS_Application = SystemData_CreatedByType_STATUS("Application") + SystemData_CreatedByType_STATUS_Key = SystemData_CreatedByType_STATUS("Key") + SystemData_CreatedByType_STATUS_ManagedIdentity = SystemData_CreatedByType_STATUS("ManagedIdentity") + SystemData_CreatedByType_STATUS_User = SystemData_CreatedByType_STATUS("User") +) + +// Mapping from string to SystemData_CreatedByType_STATUS +var systemData_CreatedByType_STATUS_Values = map[string]SystemData_CreatedByType_STATUS{ + "application": SystemData_CreatedByType_STATUS_Application, + "key": SystemData_CreatedByType_STATUS_Key, + "managedidentity": SystemData_CreatedByType_STATUS_ManagedIdentity, + "user": SystemData_CreatedByType_STATUS_User, +} + +type SystemData_LastModifiedByType_STATUS string + +const ( + SystemData_LastModifiedByType_STATUS_Application = SystemData_LastModifiedByType_STATUS("Application") + SystemData_LastModifiedByType_STATUS_Key = SystemData_LastModifiedByType_STATUS("Key") + SystemData_LastModifiedByType_STATUS_ManagedIdentity = SystemData_LastModifiedByType_STATUS("ManagedIdentity") + SystemData_LastModifiedByType_STATUS_User = SystemData_LastModifiedByType_STATUS("User") +) + +// Mapping from string to SystemData_LastModifiedByType_STATUS +var systemData_LastModifiedByType_STATUS_Values = map[string]SystemData_LastModifiedByType_STATUS{ + "application": SystemData_LastModifiedByType_STATUS_Application, + "key": SystemData_LastModifiedByType_STATUS_Key, + "managedidentity": SystemData_LastModifiedByType_STATUS_ManagedIdentity, + "user": SystemData_LastModifiedByType_STATUS_User, +} + func init() { SchemeBuilder.Register(&PrometheusRuleGroup{}, &PrometheusRuleGroupList{}) } diff --git a/v2/api/alertsmanagement/v1api20230301/structure.txt b/v2/api/alertsmanagement/v1api20230301/structure.txt index 42bee56222..91bb30977e 100644 --- a/v2/api/alertsmanagement/v1api20230301/structure.txt +++ b/v2/api/alertsmanagement/v1api20230301/structure.txt @@ -2,129 +2,20 @@ github.com/Azure/azure-service-operator/v2/api/alertsmanagement/v1api20230301 ├── APIVersion: Enum (1 value) │ └── "2023-03-01" -├── PrometheusRuleGroup: Resource -│ ├── Owner: resources/v1apiv20191001.ResourceGroup -│ ├── Spec: Object (10 properties) -│ │ ├── AzureName: Validated (1 rule) -│ │ │ └── Rule 0: Pattern: "^[^:@/#{}%&+*<>?]+$" -│ │ ├── ClusterName: *string -│ │ ├── Description: *string -│ │ ├── Enabled: *bool -│ │ ├── Interval: *string -│ │ ├── Location: *string -│ │ ├── Owner: *genruntime.KnownResourceReference -│ │ ├── Rules: Object (10 properties)[] -│ │ │ ├── Actions: Object (2 properties)[] -│ │ │ │ ├── ActionGroupReference: *genruntime.ResourceReference -│ │ │ │ └── ActionProperties: map[string]string -│ │ │ ├── Alert: *string -│ │ │ ├── Annotations: map[string]string -│ │ │ ├── Enabled: *bool -│ │ │ ├── Expression: *string -│ │ │ ├── For: *string -│ │ │ ├── Labels: map[string]string -│ │ │ ├── Record: *string -│ │ │ ├── ResolveConfiguration: *Object (2 properties) -│ │ │ │ ├── AutoResolved: *bool -│ │ │ │ └── TimeToResolve: *string -│ │ │ └── Severity: *int -│ │ ├── ScopesReferences: genruntime.ResourceReference[] -│ │ └── Tags: map[string]string -│ └── Status: Object (13 properties) -│ ├── ClusterName: *string -│ ├── Conditions: conditions.Condition[] -│ ├── Description: *string -│ ├── Enabled: *bool -│ ├── Id: *string -│ ├── Interval: *string -│ ├── Location: *string -│ ├── Name: *string -│ ├── Rules: Object (10 properties)[] -│ │ ├── Actions: Object (2 properties)[] -│ │ │ ├── ActionGroupId: *string -│ │ │ └── ActionProperties: map[string]string -│ │ ├── Alert: *string -│ │ ├── Annotations: map[string]string -│ │ ├── Enabled: *bool -│ │ ├── Expression: *string -│ │ ├── For: *string -│ │ ├── Labels: map[string]string -│ │ ├── Record: *string -│ │ ├── ResolveConfiguration: *Object (2 properties) -│ │ │ ├── AutoResolved: *bool -│ │ │ └── TimeToResolve: *string -│ │ └── Severity: *int -│ ├── Scopes: string[] -│ ├── SystemData: *Object (6 properties) -│ │ ├── CreatedAt: *string -│ │ ├── CreatedBy: *string -│ │ ├── CreatedByType: *Enum (4 values) -│ │ │ ├── "Application" -│ │ │ ├── "Key" -│ │ │ ├── "ManagedIdentity" -│ │ │ └── "User" -│ │ ├── LastModifiedAt: *string -│ │ ├── LastModifiedBy: *string -│ │ └── LastModifiedByType: *Enum (4 values) -│ │ ├── "Application" -│ │ ├── "Key" -│ │ ├── "ManagedIdentity" -│ │ └── "User" -│ ├── Tags: map[string]string -│ └── Type: *string -├── PrometheusRuleGroup_STATUS_ARM: Object (7 properties) -│ ├── Id: *string -│ ├── Location: *string -│ ├── Name: *string -│ ├── Properties: *Object (6 properties) -│ │ ├── ClusterName: *string -│ │ ├── Description: *string -│ │ ├── Enabled: *bool -│ │ ├── Interval: *string -│ │ ├── Rules: Object (10 properties)[] -│ │ │ ├── Actions: Object (2 properties)[] -│ │ │ │ ├── ActionGroupId: *string -│ │ │ │ └── ActionProperties: map[string]string -│ │ │ ├── Alert: *string -│ │ │ ├── Annotations: map[string]string -│ │ │ ├── Enabled: *bool -│ │ │ ├── Expression: *string -│ │ │ ├── For: *string -│ │ │ ├── Labels: map[string]string -│ │ │ ├── Record: *string -│ │ │ ├── ResolveConfiguration: *Object (2 properties) -│ │ │ │ ├── AutoResolved: *bool -│ │ │ │ └── TimeToResolve: *string -│ │ │ └── Severity: *int -│ │ └── Scopes: string[] -│ ├── SystemData: *Object (6 properties) -│ │ ├── CreatedAt: *string -│ │ ├── CreatedBy: *string -│ │ ├── CreatedByType: *Enum (4 values) -│ │ │ ├── "Application" -│ │ │ ├── "Key" -│ │ │ ├── "ManagedIdentity" -│ │ │ └── "User" -│ │ ├── LastModifiedAt: *string -│ │ ├── LastModifiedBy: *string -│ │ └── LastModifiedByType: *Enum (4 values) -│ │ ├── "Application" -│ │ ├── "Key" -│ │ ├── "ManagedIdentity" -│ │ └── "User" -│ ├── Tags: map[string]string -│ └── Type: *string -└── PrometheusRuleGroup_Spec_ARM: Object (4 properties) - ├── Location: *string - ├── Name: string - ├── Properties: *Object (6 properties) +└── PrometheusRuleGroup: Resource + ├── Owner: resources/v1apiv20191001.ResourceGroup + ├── Spec: Object (10 properties) + │ ├── AzureName: Validated (1 rule) + │ │ └── Rule 0: Pattern: "^[^:@/#{}%&+*<>?]+$" │ ├── ClusterName: *string │ ├── Description: *string │ ├── Enabled: *bool │ ├── Interval: *string + │ ├── Location: *string + │ ├── Owner: *genruntime.KnownResourceReference │ ├── Rules: Object (10 properties)[] │ │ ├── Actions: Object (2 properties)[] - │ │ │ ├── ActionGroupId: *string + │ │ │ ├── ActionGroupReference: *genruntime.ResourceReference │ │ │ └── ActionProperties: map[string]string │ │ ├── Alert: *string │ │ ├── Annotations: map[string]string @@ -137,5 +28,47 @@ github.com/Azure/azure-service-operator/v2/api/alertsmanagement/v1api20230301 │ │ │ ├── AutoResolved: *bool │ │ │ └── TimeToResolve: *string │ │ └── Severity: *int - │ └── Scopes: string[] - └── Tags: map[string]string + │ ├── ScopesReferences: genruntime.ResourceReference[] + │ └── Tags: map[string]string + └── Status: Object (13 properties) + ├── ClusterName: *string + ├── Conditions: conditions.Condition[] + ├── Description: *string + ├── Enabled: *bool + ├── Id: *string + ├── Interval: *string + ├── Location: *string + ├── Name: *string + ├── Rules: Object (10 properties)[] + │ ├── Actions: Object (2 properties)[] + │ │ ├── ActionGroupId: *string + │ │ └── ActionProperties: map[string]string + │ ├── Alert: *string + │ ├── Annotations: map[string]string + │ ├── Enabled: *bool + │ ├── Expression: *string + │ ├── For: *string + │ ├── Labels: map[string]string + │ ├── Record: *string + │ ├── ResolveConfiguration: *Object (2 properties) + │ │ ├── AutoResolved: *bool + │ │ └── TimeToResolve: *string + │ └── Severity: *int + ├── Scopes: string[] + ├── SystemData: *Object (6 properties) + │ ├── CreatedAt: *string + │ ├── CreatedBy: *string + │ ├── CreatedByType: *Enum (4 values) + │ │ ├── "Application" + │ │ ├── "Key" + │ │ ├── "ManagedIdentity" + │ │ └── "User" + │ ├── LastModifiedAt: *string + │ ├── LastModifiedBy: *string + │ └── LastModifiedByType: *Enum (4 values) + │ ├── "Application" + │ ├── "Key" + │ ├── "ManagedIdentity" + │ └── "User" + ├── Tags: map[string]string + └── Type: *string diff --git a/v2/api/monitor/v1api20230403/account_status_arm_types_gen_test.go b/v2/api/monitor/v1api20230403/account_status_arm_types_gen_test.go deleted file mode 100644 index c463fa905a..0000000000 --- a/v2/api/monitor/v1api20230403/account_status_arm_types_gen_test.go +++ /dev/null @@ -1,442 +0,0 @@ -// Code generated by azure-service-operator-codegen. DO NOT EDIT. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. -package v1api20230403 - -import ( - "encoding/json" - "github.com/google/go-cmp/cmp" - "github.com/google/go-cmp/cmp/cmpopts" - "github.com/kr/pretty" - "github.com/kylelemons/godebug/diff" - "github.com/leanovate/gopter" - "github.com/leanovate/gopter/gen" - "github.com/leanovate/gopter/prop" - "os" - "reflect" - "testing" -) - -func Test_Account_STATUS_ARM_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { - t.Parallel() - parameters := gopter.DefaultTestParameters() - parameters.MinSuccessfulTests = 80 - parameters.MaxSize = 3 - properties := gopter.NewProperties(parameters) - properties.Property( - "Round trip of Account_STATUS_ARM via JSON returns original", - prop.ForAll(RunJSONSerializationTestForAccount_STATUS_ARM, Account_STATUS_ARMGenerator())) - properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout)) -} - -// RunJSONSerializationTestForAccount_STATUS_ARM runs a test to see if a specific instance of Account_STATUS_ARM round trips to JSON and back losslessly -func RunJSONSerializationTestForAccount_STATUS_ARM(subject Account_STATUS_ARM) string { - // Serialize to JSON - bin, err := json.Marshal(subject) - if err != nil { - return err.Error() - } - - // Deserialize back into memory - var actual Account_STATUS_ARM - err = json.Unmarshal(bin, &actual) - if err != nil { - return err.Error() - } - - // Check for outcome - match := cmp.Equal(subject, actual, cmpopts.EquateEmpty()) - if !match { - actualFmt := pretty.Sprint(actual) - subjectFmt := pretty.Sprint(subject) - result := diff.Diff(subjectFmt, actualFmt) - return result - } - - return "" -} - -// Generator of Account_STATUS_ARM instances for property testing - lazily instantiated by Account_STATUS_ARMGenerator() -var account_STATUS_ARMGenerator gopter.Gen - -// Account_STATUS_ARMGenerator returns a generator of Account_STATUS_ARM instances for property testing. -// We first initialize account_STATUS_ARMGenerator with a simplified generator based on the -// fields with primitive types then replacing it with a more complex one that also handles complex fields -// to ensure any cycles in the object graph properly terminate. -func Account_STATUS_ARMGenerator() gopter.Gen { - if account_STATUS_ARMGenerator != nil { - return account_STATUS_ARMGenerator - } - - generators := make(map[string]gopter.Gen) - AddIndependentPropertyGeneratorsForAccount_STATUS_ARM(generators) - account_STATUS_ARMGenerator = gen.Struct(reflect.TypeOf(Account_STATUS_ARM{}), generators) - - // The above call to gen.Struct() captures the map, so create a new one - generators = make(map[string]gopter.Gen) - AddIndependentPropertyGeneratorsForAccount_STATUS_ARM(generators) - AddRelatedPropertyGeneratorsForAccount_STATUS_ARM(generators) - account_STATUS_ARMGenerator = gen.Struct(reflect.TypeOf(Account_STATUS_ARM{}), generators) - - return account_STATUS_ARMGenerator -} - -// AddIndependentPropertyGeneratorsForAccount_STATUS_ARM is a factory method for creating gopter generators -func AddIndependentPropertyGeneratorsForAccount_STATUS_ARM(gens map[string]gopter.Gen) { - gens["Etag"] = gen.PtrOf(gen.AlphaString()) - gens["Id"] = gen.PtrOf(gen.AlphaString()) - gens["Location"] = gen.PtrOf(gen.AlphaString()) - gens["Name"] = gen.PtrOf(gen.AlphaString()) - gens["Tags"] = gen.MapOf( - gen.AlphaString(), - gen.AlphaString()) - gens["Type"] = gen.PtrOf(gen.AlphaString()) -} - -// AddRelatedPropertyGeneratorsForAccount_STATUS_ARM is a factory method for creating gopter generators -func AddRelatedPropertyGeneratorsForAccount_STATUS_ARM(gens map[string]gopter.Gen) { - gens["Properties"] = gen.PtrOf(AzureMonitorWorkspace_STATUS_ARMGenerator()) - gens["SystemData"] = gen.PtrOf(SystemData_STATUS_ARMGenerator()) -} - -func Test_AzureMonitorWorkspace_STATUS_ARM_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { - t.Parallel() - parameters := gopter.DefaultTestParameters() - parameters.MinSuccessfulTests = 80 - parameters.MaxSize = 3 - properties := gopter.NewProperties(parameters) - properties.Property( - "Round trip of AzureMonitorWorkspace_STATUS_ARM via JSON returns original", - prop.ForAll(RunJSONSerializationTestForAzureMonitorWorkspace_STATUS_ARM, AzureMonitorWorkspace_STATUS_ARMGenerator())) - properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout)) -} - -// RunJSONSerializationTestForAzureMonitorWorkspace_STATUS_ARM runs a test to see if a specific instance of AzureMonitorWorkspace_STATUS_ARM round trips to JSON and back losslessly -func RunJSONSerializationTestForAzureMonitorWorkspace_STATUS_ARM(subject AzureMonitorWorkspace_STATUS_ARM) string { - // Serialize to JSON - bin, err := json.Marshal(subject) - if err != nil { - return err.Error() - } - - // Deserialize back into memory - var actual AzureMonitorWorkspace_STATUS_ARM - err = json.Unmarshal(bin, &actual) - if err != nil { - return err.Error() - } - - // Check for outcome - match := cmp.Equal(subject, actual, cmpopts.EquateEmpty()) - if !match { - actualFmt := pretty.Sprint(actual) - subjectFmt := pretty.Sprint(subject) - result := diff.Diff(subjectFmt, actualFmt) - return result - } - - return "" -} - -// Generator of AzureMonitorWorkspace_STATUS_ARM instances for property testing - lazily instantiated by -// AzureMonitorWorkspace_STATUS_ARMGenerator() -var azureMonitorWorkspace_STATUS_ARMGenerator gopter.Gen - -// AzureMonitorWorkspace_STATUS_ARMGenerator returns a generator of AzureMonitorWorkspace_STATUS_ARM instances for property testing. -// We first initialize azureMonitorWorkspace_STATUS_ARMGenerator with a simplified generator based on the -// fields with primitive types then replacing it with a more complex one that also handles complex fields -// to ensure any cycles in the object graph properly terminate. -func AzureMonitorWorkspace_STATUS_ARMGenerator() gopter.Gen { - if azureMonitorWorkspace_STATUS_ARMGenerator != nil { - return azureMonitorWorkspace_STATUS_ARMGenerator - } - - generators := make(map[string]gopter.Gen) - AddIndependentPropertyGeneratorsForAzureMonitorWorkspace_STATUS_ARM(generators) - azureMonitorWorkspace_STATUS_ARMGenerator = gen.Struct(reflect.TypeOf(AzureMonitorWorkspace_STATUS_ARM{}), generators) - - // The above call to gen.Struct() captures the map, so create a new one - generators = make(map[string]gopter.Gen) - AddIndependentPropertyGeneratorsForAzureMonitorWorkspace_STATUS_ARM(generators) - AddRelatedPropertyGeneratorsForAzureMonitorWorkspace_STATUS_ARM(generators) - azureMonitorWorkspace_STATUS_ARMGenerator = gen.Struct(reflect.TypeOf(AzureMonitorWorkspace_STATUS_ARM{}), generators) - - return azureMonitorWorkspace_STATUS_ARMGenerator -} - -// AddIndependentPropertyGeneratorsForAzureMonitorWorkspace_STATUS_ARM is a factory method for creating gopter generators -func AddIndependentPropertyGeneratorsForAzureMonitorWorkspace_STATUS_ARM(gens map[string]gopter.Gen) { - gens["AccountId"] = gen.PtrOf(gen.AlphaString()) - gens["ProvisioningState"] = gen.PtrOf(gen.OneConstOf( - AzureMonitorWorkspace_ProvisioningState_STATUS_Canceled, - AzureMonitorWorkspace_ProvisioningState_STATUS_Creating, - AzureMonitorWorkspace_ProvisioningState_STATUS_Deleting, - AzureMonitorWorkspace_ProvisioningState_STATUS_Failed, - AzureMonitorWorkspace_ProvisioningState_STATUS_Succeeded)) - gens["PublicNetworkAccess"] = gen.PtrOf(gen.OneConstOf(AzureMonitorWorkspace_PublicNetworkAccess_STATUS_Disabled, AzureMonitorWorkspace_PublicNetworkAccess_STATUS_Enabled)) -} - -// AddRelatedPropertyGeneratorsForAzureMonitorWorkspace_STATUS_ARM is a factory method for creating gopter generators -func AddRelatedPropertyGeneratorsForAzureMonitorWorkspace_STATUS_ARM(gens map[string]gopter.Gen) { - gens["DefaultIngestionSettings"] = gen.PtrOf(IngestionSettings_STATUS_ARMGenerator()) - gens["Metrics"] = gen.PtrOf(Metrics_STATUS_ARMGenerator()) - gens["PrivateEndpointConnections"] = gen.SliceOf(PrivateEndpointConnection_STATUS_ARMGenerator()) -} - -func Test_IngestionSettings_STATUS_ARM_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { - t.Parallel() - parameters := gopter.DefaultTestParameters() - parameters.MinSuccessfulTests = 80 - parameters.MaxSize = 3 - properties := gopter.NewProperties(parameters) - properties.Property( - "Round trip of IngestionSettings_STATUS_ARM via JSON returns original", - prop.ForAll(RunJSONSerializationTestForIngestionSettings_STATUS_ARM, IngestionSettings_STATUS_ARMGenerator())) - properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout)) -} - -// RunJSONSerializationTestForIngestionSettings_STATUS_ARM runs a test to see if a specific instance of IngestionSettings_STATUS_ARM round trips to JSON and back losslessly -func RunJSONSerializationTestForIngestionSettings_STATUS_ARM(subject IngestionSettings_STATUS_ARM) string { - // Serialize to JSON - bin, err := json.Marshal(subject) - if err != nil { - return err.Error() - } - - // Deserialize back into memory - var actual IngestionSettings_STATUS_ARM - err = json.Unmarshal(bin, &actual) - if err != nil { - return err.Error() - } - - // Check for outcome - match := cmp.Equal(subject, actual, cmpopts.EquateEmpty()) - if !match { - actualFmt := pretty.Sprint(actual) - subjectFmt := pretty.Sprint(subject) - result := diff.Diff(subjectFmt, actualFmt) - return result - } - - return "" -} - -// Generator of IngestionSettings_STATUS_ARM instances for property testing - lazily instantiated by -// IngestionSettings_STATUS_ARMGenerator() -var ingestionSettings_STATUS_ARMGenerator gopter.Gen - -// IngestionSettings_STATUS_ARMGenerator returns a generator of IngestionSettings_STATUS_ARM instances for property testing. -func IngestionSettings_STATUS_ARMGenerator() gopter.Gen { - if ingestionSettings_STATUS_ARMGenerator != nil { - return ingestionSettings_STATUS_ARMGenerator - } - - generators := make(map[string]gopter.Gen) - AddIndependentPropertyGeneratorsForIngestionSettings_STATUS_ARM(generators) - ingestionSettings_STATUS_ARMGenerator = gen.Struct(reflect.TypeOf(IngestionSettings_STATUS_ARM{}), generators) - - return ingestionSettings_STATUS_ARMGenerator -} - -// AddIndependentPropertyGeneratorsForIngestionSettings_STATUS_ARM is a factory method for creating gopter generators -func AddIndependentPropertyGeneratorsForIngestionSettings_STATUS_ARM(gens map[string]gopter.Gen) { - gens["DataCollectionEndpointResourceId"] = gen.PtrOf(gen.AlphaString()) - gens["DataCollectionRuleResourceId"] = gen.PtrOf(gen.AlphaString()) -} - -func Test_Metrics_STATUS_ARM_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { - t.Parallel() - parameters := gopter.DefaultTestParameters() - parameters.MinSuccessfulTests = 80 - parameters.MaxSize = 3 - properties := gopter.NewProperties(parameters) - properties.Property( - "Round trip of Metrics_STATUS_ARM via JSON returns original", - prop.ForAll(RunJSONSerializationTestForMetrics_STATUS_ARM, Metrics_STATUS_ARMGenerator())) - properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout)) -} - -// RunJSONSerializationTestForMetrics_STATUS_ARM runs a test to see if a specific instance of Metrics_STATUS_ARM round trips to JSON and back losslessly -func RunJSONSerializationTestForMetrics_STATUS_ARM(subject Metrics_STATUS_ARM) string { - // Serialize to JSON - bin, err := json.Marshal(subject) - if err != nil { - return err.Error() - } - - // Deserialize back into memory - var actual Metrics_STATUS_ARM - err = json.Unmarshal(bin, &actual) - if err != nil { - return err.Error() - } - - // Check for outcome - match := cmp.Equal(subject, actual, cmpopts.EquateEmpty()) - if !match { - actualFmt := pretty.Sprint(actual) - subjectFmt := pretty.Sprint(subject) - result := diff.Diff(subjectFmt, actualFmt) - return result - } - - return "" -} - -// Generator of Metrics_STATUS_ARM instances for property testing - lazily instantiated by Metrics_STATUS_ARMGenerator() -var metrics_STATUS_ARMGenerator gopter.Gen - -// Metrics_STATUS_ARMGenerator returns a generator of Metrics_STATUS_ARM instances for property testing. -func Metrics_STATUS_ARMGenerator() gopter.Gen { - if metrics_STATUS_ARMGenerator != nil { - return metrics_STATUS_ARMGenerator - } - - generators := make(map[string]gopter.Gen) - AddIndependentPropertyGeneratorsForMetrics_STATUS_ARM(generators) - metrics_STATUS_ARMGenerator = gen.Struct(reflect.TypeOf(Metrics_STATUS_ARM{}), generators) - - return metrics_STATUS_ARMGenerator -} - -// AddIndependentPropertyGeneratorsForMetrics_STATUS_ARM is a factory method for creating gopter generators -func AddIndependentPropertyGeneratorsForMetrics_STATUS_ARM(gens map[string]gopter.Gen) { - gens["InternalId"] = gen.PtrOf(gen.AlphaString()) - gens["PrometheusQueryEndpoint"] = gen.PtrOf(gen.AlphaString()) -} - -func Test_PrivateEndpointConnection_STATUS_ARM_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { - t.Parallel() - parameters := gopter.DefaultTestParameters() - parameters.MinSuccessfulTests = 80 - parameters.MaxSize = 3 - properties := gopter.NewProperties(parameters) - properties.Property( - "Round trip of PrivateEndpointConnection_STATUS_ARM via JSON returns original", - prop.ForAll(RunJSONSerializationTestForPrivateEndpointConnection_STATUS_ARM, PrivateEndpointConnection_STATUS_ARMGenerator())) - properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout)) -} - -// RunJSONSerializationTestForPrivateEndpointConnection_STATUS_ARM runs a test to see if a specific instance of PrivateEndpointConnection_STATUS_ARM round trips to JSON and back losslessly -func RunJSONSerializationTestForPrivateEndpointConnection_STATUS_ARM(subject PrivateEndpointConnection_STATUS_ARM) string { - // Serialize to JSON - bin, err := json.Marshal(subject) - if err != nil { - return err.Error() - } - - // Deserialize back into memory - var actual PrivateEndpointConnection_STATUS_ARM - err = json.Unmarshal(bin, &actual) - if err != nil { - return err.Error() - } - - // Check for outcome - match := cmp.Equal(subject, actual, cmpopts.EquateEmpty()) - if !match { - actualFmt := pretty.Sprint(actual) - subjectFmt := pretty.Sprint(subject) - result := diff.Diff(subjectFmt, actualFmt) - return result - } - - return "" -} - -// Generator of PrivateEndpointConnection_STATUS_ARM instances for property testing - lazily instantiated by -// PrivateEndpointConnection_STATUS_ARMGenerator() -var privateEndpointConnection_STATUS_ARMGenerator gopter.Gen - -// PrivateEndpointConnection_STATUS_ARMGenerator returns a generator of PrivateEndpointConnection_STATUS_ARM instances for property testing. -func PrivateEndpointConnection_STATUS_ARMGenerator() gopter.Gen { - if privateEndpointConnection_STATUS_ARMGenerator != nil { - return privateEndpointConnection_STATUS_ARMGenerator - } - - generators := make(map[string]gopter.Gen) - AddIndependentPropertyGeneratorsForPrivateEndpointConnection_STATUS_ARM(generators) - privateEndpointConnection_STATUS_ARMGenerator = gen.Struct(reflect.TypeOf(PrivateEndpointConnection_STATUS_ARM{}), generators) - - return privateEndpointConnection_STATUS_ARMGenerator -} - -// AddIndependentPropertyGeneratorsForPrivateEndpointConnection_STATUS_ARM is a factory method for creating gopter generators -func AddIndependentPropertyGeneratorsForPrivateEndpointConnection_STATUS_ARM(gens map[string]gopter.Gen) { - gens["Id"] = gen.PtrOf(gen.AlphaString()) -} - -func Test_SystemData_STATUS_ARM_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { - t.Parallel() - parameters := gopter.DefaultTestParameters() - parameters.MinSuccessfulTests = 80 - parameters.MaxSize = 3 - properties := gopter.NewProperties(parameters) - properties.Property( - "Round trip of SystemData_STATUS_ARM via JSON returns original", - prop.ForAll(RunJSONSerializationTestForSystemData_STATUS_ARM, SystemData_STATUS_ARMGenerator())) - properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout)) -} - -// RunJSONSerializationTestForSystemData_STATUS_ARM runs a test to see if a specific instance of SystemData_STATUS_ARM round trips to JSON and back losslessly -func RunJSONSerializationTestForSystemData_STATUS_ARM(subject SystemData_STATUS_ARM) string { - // Serialize to JSON - bin, err := json.Marshal(subject) - if err != nil { - return err.Error() - } - - // Deserialize back into memory - var actual SystemData_STATUS_ARM - err = json.Unmarshal(bin, &actual) - if err != nil { - return err.Error() - } - - // Check for outcome - match := cmp.Equal(subject, actual, cmpopts.EquateEmpty()) - if !match { - actualFmt := pretty.Sprint(actual) - subjectFmt := pretty.Sprint(subject) - result := diff.Diff(subjectFmt, actualFmt) - return result - } - - return "" -} - -// Generator of SystemData_STATUS_ARM instances for property testing - lazily instantiated by -// SystemData_STATUS_ARMGenerator() -var systemData_STATUS_ARMGenerator gopter.Gen - -// SystemData_STATUS_ARMGenerator returns a generator of SystemData_STATUS_ARM instances for property testing. -func SystemData_STATUS_ARMGenerator() gopter.Gen { - if systemData_STATUS_ARMGenerator != nil { - return systemData_STATUS_ARMGenerator - } - - generators := make(map[string]gopter.Gen) - AddIndependentPropertyGeneratorsForSystemData_STATUS_ARM(generators) - systemData_STATUS_ARMGenerator = gen.Struct(reflect.TypeOf(SystemData_STATUS_ARM{}), generators) - - return systemData_STATUS_ARMGenerator -} - -// AddIndependentPropertyGeneratorsForSystemData_STATUS_ARM is a factory method for creating gopter generators -func AddIndependentPropertyGeneratorsForSystemData_STATUS_ARM(gens map[string]gopter.Gen) { - gens["CreatedAt"] = gen.PtrOf(gen.AlphaString()) - gens["CreatedBy"] = gen.PtrOf(gen.AlphaString()) - gens["CreatedByType"] = gen.PtrOf(gen.OneConstOf( - SystemData_CreatedByType_STATUS_Application, - SystemData_CreatedByType_STATUS_Key, - SystemData_CreatedByType_STATUS_ManagedIdentity, - SystemData_CreatedByType_STATUS_User)) - gens["LastModifiedAt"] = gen.PtrOf(gen.AlphaString()) - gens["LastModifiedBy"] = gen.PtrOf(gen.AlphaString()) - gens["LastModifiedByType"] = gen.PtrOf(gen.OneConstOf( - SystemData_LastModifiedByType_STATUS_Application, - SystemData_LastModifiedByType_STATUS_Key, - SystemData_LastModifiedByType_STATUS_ManagedIdentity, - SystemData_LastModifiedByType_STATUS_User)) -} diff --git a/v2/api/monitor/v1api20230403/account_types_gen.go b/v2/api/monitor/v1api20230403/account_types_gen.go index 7051d27784..f13428775f 100644 --- a/v2/api/monitor/v1api20230403/account_types_gen.go +++ b/v2/api/monitor/v1api20230403/account_types_gen.go @@ -5,6 +5,7 @@ package v1api20230403 import ( "fmt" + arm "github.com/Azure/azure-service-operator/v2/api/monitor/v1api20230403/arm" storage "github.com/Azure/azure-service-operator/v2/api/monitor/v1api20230403/storage" "github.com/Azure/azure-service-operator/v2/internal/reflecthelpers" "github.com/Azure/azure-service-operator/v2/pkg/genruntime" @@ -350,7 +351,7 @@ func (account *Account_Spec) ConvertToARM(resolved genruntime.ConvertToARMResolv if account == nil { return nil, nil } - result := &Account_Spec_ARM{} + result := &arm.Account_Spec{} // Set property "Location": if account.Location != nil { @@ -373,14 +374,14 @@ func (account *Account_Spec) ConvertToARM(resolved genruntime.ConvertToARMResolv // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (account *Account_Spec) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &Account_Spec_ARM{} + return &arm.Account_Spec{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (account *Account_Spec) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(Account_Spec_ARM) + typedInput, ok := armInput.(arm.Account_Spec) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected Account_Spec_ARM, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.Account_Spec, got %T", armInput) } // Set property "AzureName": @@ -640,14 +641,14 @@ var _ genruntime.FromARMConverter = &Account_STATUS{} // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (account *Account_STATUS) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &Account_STATUS_ARM{} + return &arm.Account_STATUS{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (account *Account_STATUS) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(Account_STATUS_ARM) + typedInput, ok := armInput.(arm.Account_STATUS) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected Account_STATUS_ARM, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.Account_STATUS, got %T", armInput) } // Set property "AccountId": @@ -1037,14 +1038,14 @@ var _ genruntime.FromARMConverter = &IngestionSettings_STATUS{} // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (settings *IngestionSettings_STATUS) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &IngestionSettings_STATUS_ARM{} + return &arm.IngestionSettings_STATUS{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (settings *IngestionSettings_STATUS) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(IngestionSettings_STATUS_ARM) + typedInput, ok := armInput.(arm.IngestionSettings_STATUS) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected IngestionSettings_STATUS_ARM, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.IngestionSettings_STATUS, got %T", armInput) } // Set property "DataCollectionEndpointResourceId": @@ -1111,14 +1112,14 @@ var _ genruntime.FromARMConverter = &Metrics_STATUS{} // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (metrics *Metrics_STATUS) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &Metrics_STATUS_ARM{} + return &arm.Metrics_STATUS{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (metrics *Metrics_STATUS) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(Metrics_STATUS_ARM) + typedInput, ok := armInput.(arm.Metrics_STATUS) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected Metrics_STATUS_ARM, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.Metrics_STATUS, got %T", armInput) } // Set property "InternalId": @@ -1183,14 +1184,14 @@ var _ genruntime.FromARMConverter = &PrivateEndpointConnection_STATUS{} // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (connection *PrivateEndpointConnection_STATUS) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &PrivateEndpointConnection_STATUS_ARM{} + return &arm.PrivateEndpointConnection_STATUS{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (connection *PrivateEndpointConnection_STATUS) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(PrivateEndpointConnection_STATUS_ARM) + typedInput, ok := armInput.(arm.PrivateEndpointConnection_STATUS) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected PrivateEndpointConnection_STATUS_ARM, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.PrivateEndpointConnection_STATUS, got %T", armInput) } // Set property "Id": @@ -1257,14 +1258,14 @@ var _ genruntime.FromARMConverter = &SystemData_STATUS{} // NewEmptyARMValue returns an empty ARM value suitable for deserializing into func (data *SystemData_STATUS) NewEmptyARMValue() genruntime.ARMResourceStatus { - return &SystemData_STATUS_ARM{} + return &arm.SystemData_STATUS{} } // PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object func (data *SystemData_STATUS) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error { - typedInput, ok := armInput.(SystemData_STATUS_ARM) + typedInput, ok := armInput.(arm.SystemData_STATUS) if !ok { - return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected SystemData_STATUS_ARM, got %T", armInput) + return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.SystemData_STATUS, got %T", armInput) } // Set property "CreatedAt": @@ -1388,6 +1389,40 @@ func (data *SystemData_STATUS) AssignProperties_To_SystemData_STATUS(destination return nil } +type SystemData_CreatedByType_STATUS string + +const ( + SystemData_CreatedByType_STATUS_Application = SystemData_CreatedByType_STATUS("Application") + SystemData_CreatedByType_STATUS_Key = SystemData_CreatedByType_STATUS("Key") + SystemData_CreatedByType_STATUS_ManagedIdentity = SystemData_CreatedByType_STATUS("ManagedIdentity") + SystemData_CreatedByType_STATUS_User = SystemData_CreatedByType_STATUS("User") +) + +// Mapping from string to SystemData_CreatedByType_STATUS +var systemData_CreatedByType_STATUS_Values = map[string]SystemData_CreatedByType_STATUS{ + "application": SystemData_CreatedByType_STATUS_Application, + "key": SystemData_CreatedByType_STATUS_Key, + "managedidentity": SystemData_CreatedByType_STATUS_ManagedIdentity, + "user": SystemData_CreatedByType_STATUS_User, +} + +type SystemData_LastModifiedByType_STATUS string + +const ( + SystemData_LastModifiedByType_STATUS_Application = SystemData_LastModifiedByType_STATUS("Application") + SystemData_LastModifiedByType_STATUS_Key = SystemData_LastModifiedByType_STATUS("Key") + SystemData_LastModifiedByType_STATUS_ManagedIdentity = SystemData_LastModifiedByType_STATUS("ManagedIdentity") + SystemData_LastModifiedByType_STATUS_User = SystemData_LastModifiedByType_STATUS("User") +) + +// Mapping from string to SystemData_LastModifiedByType_STATUS +var systemData_LastModifiedByType_STATUS_Values = map[string]SystemData_LastModifiedByType_STATUS{ + "application": SystemData_LastModifiedByType_STATUS_Application, + "key": SystemData_LastModifiedByType_STATUS_Key, + "managedidentity": SystemData_LastModifiedByType_STATUS_ManagedIdentity, + "user": SystemData_LastModifiedByType_STATUS_User, +} + func init() { SchemeBuilder.Register(&Account{}, &AccountList{}) } diff --git a/v2/api/monitor/v1api20230403/account_spec_arm_types_gen.go b/v2/api/monitor/v1api20230403/arm/account_spec_types_gen.go similarity index 73% rename from v2/api/monitor/v1api20230403/account_spec_arm_types_gen.go rename to v2/api/monitor/v1api20230403/arm/account_spec_types_gen.go index 8dd77d7bc6..11b3e0b372 100644 --- a/v2/api/monitor/v1api20230403/account_spec_arm_types_gen.go +++ b/v2/api/monitor/v1api20230403/arm/account_spec_types_gen.go @@ -1,11 +1,11 @@ // Code generated by azure-service-operator-codegen. DO NOT EDIT. // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -package v1api20230403 +package arm import "github.com/Azure/azure-service-operator/v2/pkg/genruntime" -type Account_Spec_ARM struct { +type Account_Spec struct { // Location: The geo-location where the resource lives Location *string `json:"location,omitempty"` Name string `json:"name,omitempty"` @@ -14,19 +14,19 @@ type Account_Spec_ARM struct { Tags map[string]string `json:"tags,omitempty"` } -var _ genruntime.ARMResourceSpec = &Account_Spec_ARM{} +var _ genruntime.ARMResourceSpec = &Account_Spec{} // GetAPIVersion returns the ARM API version of the resource. This is always "2023-04-03" -func (account Account_Spec_ARM) GetAPIVersion() string { +func (account Account_Spec) GetAPIVersion() string { return string(APIVersion_Value) } // GetName returns the Name of the resource -func (account *Account_Spec_ARM) GetName() string { +func (account *Account_Spec) GetName() string { return account.Name } // GetType returns the ARM Type of the resource. This is always "Microsoft.Monitor/accounts" -func (account *Account_Spec_ARM) GetType() string { +func (account *Account_Spec) GetType() string { return "Microsoft.Monitor/accounts" } diff --git a/v2/api/monitor/v1api20230403/account_spec_arm_types_gen_test.go b/v2/api/monitor/v1api20230403/arm/account_spec_types_gen_test.go similarity index 51% rename from v2/api/monitor/v1api20230403/account_spec_arm_types_gen_test.go rename to v2/api/monitor/v1api20230403/arm/account_spec_types_gen_test.go index cb0d6d9aa7..dc4c6fb53f 100644 --- a/v2/api/monitor/v1api20230403/account_spec_arm_types_gen_test.go +++ b/v2/api/monitor/v1api20230403/arm/account_spec_types_gen_test.go @@ -1,7 +1,7 @@ // Code generated by azure-service-operator-codegen. DO NOT EDIT. // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -package v1api20230403 +package arm import ( "encoding/json" @@ -17,20 +17,20 @@ import ( "testing" ) -func Test_Account_Spec_ARM_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { +func Test_Account_Spec_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { t.Parallel() parameters := gopter.DefaultTestParameters() parameters.MinSuccessfulTests = 80 parameters.MaxSize = 3 properties := gopter.NewProperties(parameters) properties.Property( - "Round trip of Account_Spec_ARM via JSON returns original", - prop.ForAll(RunJSONSerializationTestForAccount_Spec_ARM, Account_Spec_ARMGenerator())) + "Round trip of Account_Spec via JSON returns original", + prop.ForAll(RunJSONSerializationTestForAccount_Spec, Account_SpecGenerator())) properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout)) } -// RunJSONSerializationTestForAccount_Spec_ARM runs a test to see if a specific instance of Account_Spec_ARM round trips to JSON and back losslessly -func RunJSONSerializationTestForAccount_Spec_ARM(subject Account_Spec_ARM) string { +// RunJSONSerializationTestForAccount_Spec runs a test to see if a specific instance of Account_Spec round trips to JSON and back losslessly +func RunJSONSerializationTestForAccount_Spec(subject Account_Spec) string { // Serialize to JSON bin, err := json.Marshal(subject) if err != nil { @@ -38,7 +38,7 @@ func RunJSONSerializationTestForAccount_Spec_ARM(subject Account_Spec_ARM) strin } // Deserialize back into memory - var actual Account_Spec_ARM + var actual Account_Spec err = json.Unmarshal(bin, &actual) if err != nil { return err.Error() @@ -56,24 +56,24 @@ func RunJSONSerializationTestForAccount_Spec_ARM(subject Account_Spec_ARM) strin return "" } -// Generator of Account_Spec_ARM instances for property testing - lazily instantiated by Account_Spec_ARMGenerator() -var account_Spec_ARMGenerator gopter.Gen +// Generator of Account_Spec instances for property testing - lazily instantiated by Account_SpecGenerator() +var account_SpecGenerator gopter.Gen -// Account_Spec_ARMGenerator returns a generator of Account_Spec_ARM instances for property testing. -func Account_Spec_ARMGenerator() gopter.Gen { - if account_Spec_ARMGenerator != nil { - return account_Spec_ARMGenerator +// Account_SpecGenerator returns a generator of Account_Spec instances for property testing. +func Account_SpecGenerator() gopter.Gen { + if account_SpecGenerator != nil { + return account_SpecGenerator } generators := make(map[string]gopter.Gen) - AddIndependentPropertyGeneratorsForAccount_Spec_ARM(generators) - account_Spec_ARMGenerator = gen.Struct(reflect.TypeOf(Account_Spec_ARM{}), generators) + AddIndependentPropertyGeneratorsForAccount_Spec(generators) + account_SpecGenerator = gen.Struct(reflect.TypeOf(Account_Spec{}), generators) - return account_Spec_ARMGenerator + return account_SpecGenerator } -// AddIndependentPropertyGeneratorsForAccount_Spec_ARM is a factory method for creating gopter generators -func AddIndependentPropertyGeneratorsForAccount_Spec_ARM(gens map[string]gopter.Gen) { +// AddIndependentPropertyGeneratorsForAccount_Spec is a factory method for creating gopter generators +func AddIndependentPropertyGeneratorsForAccount_Spec(gens map[string]gopter.Gen) { gens["Location"] = gen.PtrOf(gen.AlphaString()) gens["Name"] = gen.AlphaString() gens["Tags"] = gen.MapOf( diff --git a/v2/api/monitor/v1api20230403/account_status_arm_types_gen.go b/v2/api/monitor/v1api20230403/arm/account_status_types_gen.go similarity index 55% rename from v2/api/monitor/v1api20230403/account_status_arm_types_gen.go rename to v2/api/monitor/v1api20230403/arm/account_status_types_gen.go index 5612f1f497..228bcc08df 100644 --- a/v2/api/monitor/v1api20230403/account_status_arm_types_gen.go +++ b/v2/api/monitor/v1api20230403/arm/account_status_types_gen.go @@ -1,9 +1,11 @@ // Code generated by azure-service-operator-codegen. DO NOT EDIT. // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -package v1api20230403 +package arm -type Account_STATUS_ARM struct { +import v20230403 "github.com/Azure/azure-service-operator/v2/api/monitor/v1api20230403" + +type Account_STATUS struct { // Etag: Resource entity tag (ETag) Etag *string `json:"etag,omitempty"` @@ -18,10 +20,10 @@ type Account_STATUS_ARM struct { Name *string `json:"name,omitempty"` // Properties: Resource properties - Properties *AzureMonitorWorkspace_STATUS_ARM `json:"properties,omitempty"` + Properties *AzureMonitorWorkspace_STATUS `json:"properties,omitempty"` // SystemData: Azure Resource Manager metadata containing createdBy and modifiedBy information. - SystemData *SystemData_STATUS_ARM `json:"systemData,omitempty"` + SystemData *SystemData_STATUS `json:"systemData,omitempty"` // Tags: Resource tags. Tags map[string]string `json:"tags,omitempty"` @@ -31,28 +33,28 @@ type Account_STATUS_ARM struct { } // Properties of an Azure Monitor Workspace -type AzureMonitorWorkspace_STATUS_ARM struct { +type AzureMonitorWorkspace_STATUS struct { // AccountId: The immutable Id of the Azure Monitor Workspace. This property is read-only. AccountId *string `json:"accountId,omitempty"` // DefaultIngestionSettings: The Data Collection Rule and Endpoint used for ingestion by default. - DefaultIngestionSettings *IngestionSettings_STATUS_ARM `json:"defaultIngestionSettings,omitempty"` + DefaultIngestionSettings *IngestionSettings_STATUS `json:"defaultIngestionSettings,omitempty"` // Metrics: Properties related to the metrics container in the Azure Monitor Workspace - Metrics *Metrics_STATUS_ARM `json:"metrics,omitempty"` + Metrics *Metrics_STATUS `json:"metrics,omitempty"` // PrivateEndpointConnections: List of private endpoint connections - PrivateEndpointConnections []PrivateEndpointConnection_STATUS_ARM `json:"privateEndpointConnections,omitempty"` + PrivateEndpointConnections []PrivateEndpointConnection_STATUS `json:"privateEndpointConnections,omitempty"` // ProvisioningState: The provisioning state of the Azure Monitor Workspace. Set to Succeeded if everything is healthy. - ProvisioningState *AzureMonitorWorkspace_ProvisioningState_STATUS `json:"provisioningState,omitempty"` + ProvisioningState *v20230403.AzureMonitorWorkspace_ProvisioningState_STATUS `json:"provisioningState,omitempty"` // PublicNetworkAccess: Gets or sets allow or disallow public network access to Azure Monitor Workspace - PublicNetworkAccess *AzureMonitorWorkspace_PublicNetworkAccess_STATUS `json:"publicNetworkAccess,omitempty"` + PublicNetworkAccess *v20230403.AzureMonitorWorkspace_PublicNetworkAccess_STATUS `json:"publicNetworkAccess,omitempty"` } // Metadata pertaining to creation and last modification of the resource. -type SystemData_STATUS_ARM struct { +type SystemData_STATUS struct { // CreatedAt: The timestamp of resource creation (UTC). CreatedAt *string `json:"createdAt,omitempty"` @@ -60,7 +62,7 @@ type SystemData_STATUS_ARM struct { CreatedBy *string `json:"createdBy,omitempty"` // CreatedByType: The type of identity that created the resource. - CreatedByType *SystemData_CreatedByType_STATUS `json:"createdByType,omitempty"` + CreatedByType *v20230403.SystemData_CreatedByType_STATUS `json:"createdByType,omitempty"` // LastModifiedAt: The timestamp of resource last modification (UTC) LastModifiedAt *string `json:"lastModifiedAt,omitempty"` @@ -69,11 +71,11 @@ type SystemData_STATUS_ARM struct { LastModifiedBy *string `json:"lastModifiedBy,omitempty"` // LastModifiedByType: The type of identity that last modified the resource. - LastModifiedByType *SystemData_LastModifiedByType_STATUS `json:"lastModifiedByType,omitempty"` + LastModifiedByType *v20230403.SystemData_LastModifiedByType_STATUS `json:"lastModifiedByType,omitempty"` } // Settings for data ingestion -type IngestionSettings_STATUS_ARM struct { +type IngestionSettings_STATUS struct { // DataCollectionEndpointResourceId: The Azure resource Id of the default data collection endpoint for this Azure Monitor // Workspace. DataCollectionEndpointResourceId *string `json:"dataCollectionEndpointResourceId,omitempty"` @@ -83,7 +85,7 @@ type IngestionSettings_STATUS_ARM struct { } // Properties related to the metrics container in the Azure Monitor Workspace -type Metrics_STATUS_ARM struct { +type Metrics_STATUS struct { // InternalId: An internal identifier for the metrics container. Only to be used by the system InternalId *string `json:"internalId,omitempty"` @@ -92,42 +94,8 @@ type Metrics_STATUS_ARM struct { } // The private endpoint connection resource. -type PrivateEndpointConnection_STATUS_ARM struct { +type PrivateEndpointConnection_STATUS struct { // Id: Fully qualified resource ID for the resource. E.g. // "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}" Id *string `json:"id,omitempty"` } - -type SystemData_CreatedByType_STATUS string - -const ( - SystemData_CreatedByType_STATUS_Application = SystemData_CreatedByType_STATUS("Application") - SystemData_CreatedByType_STATUS_Key = SystemData_CreatedByType_STATUS("Key") - SystemData_CreatedByType_STATUS_ManagedIdentity = SystemData_CreatedByType_STATUS("ManagedIdentity") - SystemData_CreatedByType_STATUS_User = SystemData_CreatedByType_STATUS("User") -) - -// Mapping from string to SystemData_CreatedByType_STATUS -var systemData_CreatedByType_STATUS_Values = map[string]SystemData_CreatedByType_STATUS{ - "application": SystemData_CreatedByType_STATUS_Application, - "key": SystemData_CreatedByType_STATUS_Key, - "managedidentity": SystemData_CreatedByType_STATUS_ManagedIdentity, - "user": SystemData_CreatedByType_STATUS_User, -} - -type SystemData_LastModifiedByType_STATUS string - -const ( - SystemData_LastModifiedByType_STATUS_Application = SystemData_LastModifiedByType_STATUS("Application") - SystemData_LastModifiedByType_STATUS_Key = SystemData_LastModifiedByType_STATUS("Key") - SystemData_LastModifiedByType_STATUS_ManagedIdentity = SystemData_LastModifiedByType_STATUS("ManagedIdentity") - SystemData_LastModifiedByType_STATUS_User = SystemData_LastModifiedByType_STATUS("User") -) - -// Mapping from string to SystemData_LastModifiedByType_STATUS -var systemData_LastModifiedByType_STATUS_Values = map[string]SystemData_LastModifiedByType_STATUS{ - "application": SystemData_LastModifiedByType_STATUS_Application, - "key": SystemData_LastModifiedByType_STATUS_Key, - "managedidentity": SystemData_LastModifiedByType_STATUS_ManagedIdentity, - "user": SystemData_LastModifiedByType_STATUS_User, -} diff --git a/v2/api/monitor/v1api20230403/arm/account_status_types_gen_test.go b/v2/api/monitor/v1api20230403/arm/account_status_types_gen_test.go new file mode 100644 index 0000000000..88ecf4874f --- /dev/null +++ b/v2/api/monitor/v1api20230403/arm/account_status_types_gen_test.go @@ -0,0 +1,442 @@ +// Code generated by azure-service-operator-codegen. DO NOT EDIT. +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. +package arm + +import ( + "encoding/json" + v20230403 "github.com/Azure/azure-service-operator/v2/api/monitor/v1api20230403" + "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" + "github.com/kr/pretty" + "github.com/kylelemons/godebug/diff" + "github.com/leanovate/gopter" + "github.com/leanovate/gopter/gen" + "github.com/leanovate/gopter/prop" + "os" + "reflect" + "testing" +) + +func Test_Account_STATUS_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { + t.Parallel() + parameters := gopter.DefaultTestParameters() + parameters.MinSuccessfulTests = 80 + parameters.MaxSize = 3 + properties := gopter.NewProperties(parameters) + properties.Property( + "Round trip of Account_STATUS via JSON returns original", + prop.ForAll(RunJSONSerializationTestForAccount_STATUS, Account_STATUSGenerator())) + properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout)) +} + +// RunJSONSerializationTestForAccount_STATUS runs a test to see if a specific instance of Account_STATUS round trips to JSON and back losslessly +func RunJSONSerializationTestForAccount_STATUS(subject Account_STATUS) string { + // Serialize to JSON + bin, err := json.Marshal(subject) + if err != nil { + return err.Error() + } + + // Deserialize back into memory + var actual Account_STATUS + err = json.Unmarshal(bin, &actual) + if err != nil { + return err.Error() + } + + // Check for outcome + match := cmp.Equal(subject, actual, cmpopts.EquateEmpty()) + if !match { + actualFmt := pretty.Sprint(actual) + subjectFmt := pretty.Sprint(subject) + result := diff.Diff(subjectFmt, actualFmt) + return result + } + + return "" +} + +// Generator of Account_STATUS instances for property testing - lazily instantiated by Account_STATUSGenerator() +var account_STATUSGenerator gopter.Gen + +// Account_STATUSGenerator returns a generator of Account_STATUS instances for property testing. +// We first initialize account_STATUSGenerator with a simplified generator based on the +// fields with primitive types then replacing it with a more complex one that also handles complex fields +// to ensure any cycles in the object graph properly terminate. +func Account_STATUSGenerator() gopter.Gen { + if account_STATUSGenerator != nil { + return account_STATUSGenerator + } + + generators := make(map[string]gopter.Gen) + AddIndependentPropertyGeneratorsForAccount_STATUS(generators) + account_STATUSGenerator = gen.Struct(reflect.TypeOf(Account_STATUS{}), generators) + + // The above call to gen.Struct() captures the map, so create a new one + generators = make(map[string]gopter.Gen) + AddIndependentPropertyGeneratorsForAccount_STATUS(generators) + AddRelatedPropertyGeneratorsForAccount_STATUS(generators) + account_STATUSGenerator = gen.Struct(reflect.TypeOf(Account_STATUS{}), generators) + + return account_STATUSGenerator +} + +// AddIndependentPropertyGeneratorsForAccount_STATUS is a factory method for creating gopter generators +func AddIndependentPropertyGeneratorsForAccount_STATUS(gens map[string]gopter.Gen) { + gens["Etag"] = gen.PtrOf(gen.AlphaString()) + gens["Id"] = gen.PtrOf(gen.AlphaString()) + gens["Location"] = gen.PtrOf(gen.AlphaString()) + gens["Name"] = gen.PtrOf(gen.AlphaString()) + gens["Tags"] = gen.MapOf( + gen.AlphaString(), + gen.AlphaString()) + gens["Type"] = gen.PtrOf(gen.AlphaString()) +} + +// AddRelatedPropertyGeneratorsForAccount_STATUS is a factory method for creating gopter generators +func AddRelatedPropertyGeneratorsForAccount_STATUS(gens map[string]gopter.Gen) { + gens["Properties"] = gen.PtrOf(AzureMonitorWorkspace_STATUSGenerator()) + gens["SystemData"] = gen.PtrOf(SystemData_STATUSGenerator()) +} + +func Test_AzureMonitorWorkspace_STATUS_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { + t.Parallel() + parameters := gopter.DefaultTestParameters() + parameters.MinSuccessfulTests = 80 + parameters.MaxSize = 3 + properties := gopter.NewProperties(parameters) + properties.Property( + "Round trip of AzureMonitorWorkspace_STATUS via JSON returns original", + prop.ForAll(RunJSONSerializationTestForAzureMonitorWorkspace_STATUS, AzureMonitorWorkspace_STATUSGenerator())) + properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout)) +} + +// RunJSONSerializationTestForAzureMonitorWorkspace_STATUS runs a test to see if a specific instance of AzureMonitorWorkspace_STATUS round trips to JSON and back losslessly +func RunJSONSerializationTestForAzureMonitorWorkspace_STATUS(subject AzureMonitorWorkspace_STATUS) string { + // Serialize to JSON + bin, err := json.Marshal(subject) + if err != nil { + return err.Error() + } + + // Deserialize back into memory + var actual AzureMonitorWorkspace_STATUS + err = json.Unmarshal(bin, &actual) + if err != nil { + return err.Error() + } + + // Check for outcome + match := cmp.Equal(subject, actual, cmpopts.EquateEmpty()) + if !match { + actualFmt := pretty.Sprint(actual) + subjectFmt := pretty.Sprint(subject) + result := diff.Diff(subjectFmt, actualFmt) + return result + } + + return "" +} + +// Generator of AzureMonitorWorkspace_STATUS instances for property testing - lazily instantiated by +// AzureMonitorWorkspace_STATUSGenerator() +var azureMonitorWorkspace_STATUSGenerator gopter.Gen + +// AzureMonitorWorkspace_STATUSGenerator returns a generator of AzureMonitorWorkspace_STATUS instances for property testing. +// We first initialize azureMonitorWorkspace_STATUSGenerator with a simplified generator based on the +// fields with primitive types then replacing it with a more complex one that also handles complex fields +// to ensure any cycles in the object graph properly terminate. +func AzureMonitorWorkspace_STATUSGenerator() gopter.Gen { + if azureMonitorWorkspace_STATUSGenerator != nil { + return azureMonitorWorkspace_STATUSGenerator + } + + generators := make(map[string]gopter.Gen) + AddIndependentPropertyGeneratorsForAzureMonitorWorkspace_STATUS(generators) + azureMonitorWorkspace_STATUSGenerator = gen.Struct(reflect.TypeOf(AzureMonitorWorkspace_STATUS{}), generators) + + // The above call to gen.Struct() captures the map, so create a new one + generators = make(map[string]gopter.Gen) + AddIndependentPropertyGeneratorsForAzureMonitorWorkspace_STATUS(generators) + AddRelatedPropertyGeneratorsForAzureMonitorWorkspace_STATUS(generators) + azureMonitorWorkspace_STATUSGenerator = gen.Struct(reflect.TypeOf(AzureMonitorWorkspace_STATUS{}), generators) + + return azureMonitorWorkspace_STATUSGenerator +} + +// AddIndependentPropertyGeneratorsForAzureMonitorWorkspace_STATUS is a factory method for creating gopter generators +func AddIndependentPropertyGeneratorsForAzureMonitorWorkspace_STATUS(gens map[string]gopter.Gen) { + gens["AccountId"] = gen.PtrOf(gen.AlphaString()) +} + +// AddRelatedPropertyGeneratorsForAzureMonitorWorkspace_STATUS is a factory method for creating gopter generators +func AddRelatedPropertyGeneratorsForAzureMonitorWorkspace_STATUS(gens map[string]gopter.Gen) { + gens["DefaultIngestionSettings"] = gen.PtrOf(IngestionSettings_STATUSGenerator()) + gens["Metrics"] = gen.PtrOf(Metrics_STATUSGenerator()) + gens["PrivateEndpointConnections"] = gen.SliceOf(PrivateEndpointConnection_STATUSGenerator()) + gens["ProvisioningState"] = gen.PtrOf(v20230403.AzureMonitorWorkspace_ProvisioningState_STATUSGenerator()) + gens["PublicNetworkAccess"] = gen.PtrOf(v20230403.AzureMonitorWorkspace_PublicNetworkAccess_STATUSGenerator()) +} + +func Test_IngestionSettings_STATUS_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { + t.Parallel() + parameters := gopter.DefaultTestParameters() + parameters.MinSuccessfulTests = 80 + parameters.MaxSize = 3 + properties := gopter.NewProperties(parameters) + properties.Property( + "Round trip of IngestionSettings_STATUS via JSON returns original", + prop.ForAll(RunJSONSerializationTestForIngestionSettings_STATUS, IngestionSettings_STATUSGenerator())) + properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout)) +} + +// RunJSONSerializationTestForIngestionSettings_STATUS runs a test to see if a specific instance of IngestionSettings_STATUS round trips to JSON and back losslessly +func RunJSONSerializationTestForIngestionSettings_STATUS(subject IngestionSettings_STATUS) string { + // Serialize to JSON + bin, err := json.Marshal(subject) + if err != nil { + return err.Error() + } + + // Deserialize back into memory + var actual IngestionSettings_STATUS + err = json.Unmarshal(bin, &actual) + if err != nil { + return err.Error() + } + + // Check for outcome + match := cmp.Equal(subject, actual, cmpopts.EquateEmpty()) + if !match { + actualFmt := pretty.Sprint(actual) + subjectFmt := pretty.Sprint(subject) + result := diff.Diff(subjectFmt, actualFmt) + return result + } + + return "" +} + +// Generator of IngestionSettings_STATUS instances for property testing - lazily instantiated by +// IngestionSettings_STATUSGenerator() +var ingestionSettings_STATUSGenerator gopter.Gen + +// IngestionSettings_STATUSGenerator returns a generator of IngestionSettings_STATUS instances for property testing. +func IngestionSettings_STATUSGenerator() gopter.Gen { + if ingestionSettings_STATUSGenerator != nil { + return ingestionSettings_STATUSGenerator + } + + generators := make(map[string]gopter.Gen) + AddIndependentPropertyGeneratorsForIngestionSettings_STATUS(generators) + ingestionSettings_STATUSGenerator = gen.Struct(reflect.TypeOf(IngestionSettings_STATUS{}), generators) + + return ingestionSettings_STATUSGenerator +} + +// AddIndependentPropertyGeneratorsForIngestionSettings_STATUS is a factory method for creating gopter generators +func AddIndependentPropertyGeneratorsForIngestionSettings_STATUS(gens map[string]gopter.Gen) { + gens["DataCollectionEndpointResourceId"] = gen.PtrOf(gen.AlphaString()) + gens["DataCollectionRuleResourceId"] = gen.PtrOf(gen.AlphaString()) +} + +func Test_Metrics_STATUS_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { + t.Parallel() + parameters := gopter.DefaultTestParameters() + parameters.MinSuccessfulTests = 80 + parameters.MaxSize = 3 + properties := gopter.NewProperties(parameters) + properties.Property( + "Round trip of Metrics_STATUS via JSON returns original", + prop.ForAll(RunJSONSerializationTestForMetrics_STATUS, Metrics_STATUSGenerator())) + properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout)) +} + +// RunJSONSerializationTestForMetrics_STATUS runs a test to see if a specific instance of Metrics_STATUS round trips to JSON and back losslessly +func RunJSONSerializationTestForMetrics_STATUS(subject Metrics_STATUS) string { + // Serialize to JSON + bin, err := json.Marshal(subject) + if err != nil { + return err.Error() + } + + // Deserialize back into memory + var actual Metrics_STATUS + err = json.Unmarshal(bin, &actual) + if err != nil { + return err.Error() + } + + // Check for outcome + match := cmp.Equal(subject, actual, cmpopts.EquateEmpty()) + if !match { + actualFmt := pretty.Sprint(actual) + subjectFmt := pretty.Sprint(subject) + result := diff.Diff(subjectFmt, actualFmt) + return result + } + + return "" +} + +// Generator of Metrics_STATUS instances for property testing - lazily instantiated by Metrics_STATUSGenerator() +var metrics_STATUSGenerator gopter.Gen + +// Metrics_STATUSGenerator returns a generator of Metrics_STATUS instances for property testing. +func Metrics_STATUSGenerator() gopter.Gen { + if metrics_STATUSGenerator != nil { + return metrics_STATUSGenerator + } + + generators := make(map[string]gopter.Gen) + AddIndependentPropertyGeneratorsForMetrics_STATUS(generators) + metrics_STATUSGenerator = gen.Struct(reflect.TypeOf(Metrics_STATUS{}), generators) + + return metrics_STATUSGenerator +} + +// AddIndependentPropertyGeneratorsForMetrics_STATUS is a factory method for creating gopter generators +func AddIndependentPropertyGeneratorsForMetrics_STATUS(gens map[string]gopter.Gen) { + gens["InternalId"] = gen.PtrOf(gen.AlphaString()) + gens["PrometheusQueryEndpoint"] = gen.PtrOf(gen.AlphaString()) +} + +func Test_PrivateEndpointConnection_STATUS_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { + t.Parallel() + parameters := gopter.DefaultTestParameters() + parameters.MinSuccessfulTests = 80 + parameters.MaxSize = 3 + properties := gopter.NewProperties(parameters) + properties.Property( + "Round trip of PrivateEndpointConnection_STATUS via JSON returns original", + prop.ForAll(RunJSONSerializationTestForPrivateEndpointConnection_STATUS, PrivateEndpointConnection_STATUSGenerator())) + properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout)) +} + +// RunJSONSerializationTestForPrivateEndpointConnection_STATUS runs a test to see if a specific instance of PrivateEndpointConnection_STATUS round trips to JSON and back losslessly +func RunJSONSerializationTestForPrivateEndpointConnection_STATUS(subject PrivateEndpointConnection_STATUS) string { + // Serialize to JSON + bin, err := json.Marshal(subject) + if err != nil { + return err.Error() + } + + // Deserialize back into memory + var actual PrivateEndpointConnection_STATUS + err = json.Unmarshal(bin, &actual) + if err != nil { + return err.Error() + } + + // Check for outcome + match := cmp.Equal(subject, actual, cmpopts.EquateEmpty()) + if !match { + actualFmt := pretty.Sprint(actual) + subjectFmt := pretty.Sprint(subject) + result := diff.Diff(subjectFmt, actualFmt) + return result + } + + return "" +} + +// Generator of PrivateEndpointConnection_STATUS instances for property testing - lazily instantiated by +// PrivateEndpointConnection_STATUSGenerator() +var privateEndpointConnection_STATUSGenerator gopter.Gen + +// PrivateEndpointConnection_STATUSGenerator returns a generator of PrivateEndpointConnection_STATUS instances for property testing. +func PrivateEndpointConnection_STATUSGenerator() gopter.Gen { + if privateEndpointConnection_STATUSGenerator != nil { + return privateEndpointConnection_STATUSGenerator + } + + generators := make(map[string]gopter.Gen) + AddIndependentPropertyGeneratorsForPrivateEndpointConnection_STATUS(generators) + privateEndpointConnection_STATUSGenerator = gen.Struct(reflect.TypeOf(PrivateEndpointConnection_STATUS{}), generators) + + return privateEndpointConnection_STATUSGenerator +} + +// AddIndependentPropertyGeneratorsForPrivateEndpointConnection_STATUS is a factory method for creating gopter generators +func AddIndependentPropertyGeneratorsForPrivateEndpointConnection_STATUS(gens map[string]gopter.Gen) { + gens["Id"] = gen.PtrOf(gen.AlphaString()) +} + +func Test_SystemData_STATUS_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { + t.Parallel() + parameters := gopter.DefaultTestParameters() + parameters.MinSuccessfulTests = 80 + parameters.MaxSize = 3 + properties := gopter.NewProperties(parameters) + properties.Property( + "Round trip of SystemData_STATUS via JSON returns original", + prop.ForAll(RunJSONSerializationTestForSystemData_STATUS, SystemData_STATUSGenerator())) + properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout)) +} + +// RunJSONSerializationTestForSystemData_STATUS runs a test to see if a specific instance of SystemData_STATUS round trips to JSON and back losslessly +func RunJSONSerializationTestForSystemData_STATUS(subject SystemData_STATUS) string { + // Serialize to JSON + bin, err := json.Marshal(subject) + if err != nil { + return err.Error() + } + + // Deserialize back into memory + var actual SystemData_STATUS + err = json.Unmarshal(bin, &actual) + if err != nil { + return err.Error() + } + + // Check for outcome + match := cmp.Equal(subject, actual, cmpopts.EquateEmpty()) + if !match { + actualFmt := pretty.Sprint(actual) + subjectFmt := pretty.Sprint(subject) + result := diff.Diff(subjectFmt, actualFmt) + return result + } + + return "" +} + +// Generator of SystemData_STATUS instances for property testing - lazily instantiated by SystemData_STATUSGenerator() +var systemData_STATUSGenerator gopter.Gen + +// SystemData_STATUSGenerator returns a generator of SystemData_STATUS instances for property testing. +// We first initialize systemData_STATUSGenerator with a simplified generator based on the +// fields with primitive types then replacing it with a more complex one that also handles complex fields +// to ensure any cycles in the object graph properly terminate. +func SystemData_STATUSGenerator() gopter.Gen { + if systemData_STATUSGenerator != nil { + return systemData_STATUSGenerator + } + + generators := make(map[string]gopter.Gen) + AddIndependentPropertyGeneratorsForSystemData_STATUS(generators) + systemData_STATUSGenerator = gen.Struct(reflect.TypeOf(SystemData_STATUS{}), generators) + + // The above call to gen.Struct() captures the map, so create a new one + generators = make(map[string]gopter.Gen) + AddIndependentPropertyGeneratorsForSystemData_STATUS(generators) + AddRelatedPropertyGeneratorsForSystemData_STATUS(generators) + systemData_STATUSGenerator = gen.Struct(reflect.TypeOf(SystemData_STATUS{}), generators) + + return systemData_STATUSGenerator +} + +// AddIndependentPropertyGeneratorsForSystemData_STATUS is a factory method for creating gopter generators +func AddIndependentPropertyGeneratorsForSystemData_STATUS(gens map[string]gopter.Gen) { + gens["CreatedAt"] = gen.PtrOf(gen.AlphaString()) + gens["CreatedBy"] = gen.PtrOf(gen.AlphaString()) + gens["LastModifiedAt"] = gen.PtrOf(gen.AlphaString()) + gens["LastModifiedBy"] = gen.PtrOf(gen.AlphaString()) +} + +// AddRelatedPropertyGeneratorsForSystemData_STATUS is a factory method for creating gopter generators +func AddRelatedPropertyGeneratorsForSystemData_STATUS(gens map[string]gopter.Gen) { + gens["CreatedByType"] = gen.PtrOf(v20230403.SystemData_CreatedByType_STATUSGenerator()) + gens["LastModifiedByType"] = gen.PtrOf(v20230403.SystemData_LastModifiedByType_STATUSGenerator()) +} diff --git a/v2/api/monitor/v1api20230403/arm/structure.txt b/v2/api/monitor/v1api20230403/arm/structure.txt new file mode 100644 index 0000000000..a1ad413bd3 --- /dev/null +++ b/v2/api/monitor/v1api20230403/arm/structure.txt @@ -0,0 +1,32 @@ +// Code generated by azure-service-operator-codegen. DO NOT EDIT. +github.com/Azure/azure-service-operator/v2/api/monitor/v1api20230403/arm +├── Account_STATUS: Object (8 properties) +│ ├── Etag: *string +│ ├── Id: *string +│ ├── Location: *string +│ ├── Name: *string +│ ├── Properties: *Object (6 properties) +│ │ ├── AccountId: *string +│ │ ├── DefaultIngestionSettings: *Object (2 properties) +│ │ │ ├── DataCollectionEndpointResourceId: *string +│ │ │ └── DataCollectionRuleResourceId: *string +│ │ ├── Metrics: *Object (2 properties) +│ │ │ ├── InternalId: *string +│ │ │ └── PrometheusQueryEndpoint: *string +│ │ ├── PrivateEndpointConnections: Object (1 property)[] +│ │ │ └── Id: *string +│ │ ├── ProvisioningState: *monitor/v1api20230403.AzureMonitorWorkspace_ProvisioningState_STATUS +│ │ └── PublicNetworkAccess: *monitor/v1api20230403.AzureMonitorWorkspace_PublicNetworkAccess_STATUS +│ ├── SystemData: *Object (6 properties) +│ │ ├── CreatedAt: *string +│ │ ├── CreatedBy: *string +│ │ ├── CreatedByType: *monitor/v1api20230403.SystemData_CreatedByType_STATUS +│ │ ├── LastModifiedAt: *string +│ │ ├── LastModifiedBy: *string +│ │ └── LastModifiedByType: *monitor/v1api20230403.SystemData_LastModifiedByType_STATUS +│ ├── Tags: map[string]string +│ └── Type: *string +└── Account_Spec: Object (3 properties) + ├── Location: *string + ├── Name: string + └── Tags: map[string]string diff --git a/v2/api/monitor/v1api20230403/structure.txt b/v2/api/monitor/v1api20230403/structure.txt index 16b4dfa933..a612d5bbe6 100644 --- a/v2/api/monitor/v1api20230403/structure.txt +++ b/v2/api/monitor/v1api20230403/structure.txt @@ -2,96 +2,51 @@ github.com/Azure/azure-service-operator/v2/api/monitor/v1api20230403 ├── APIVersion: Enum (1 value) │ └── "2023-04-03" -├── Account: Resource -│ ├── Owner: resources/v1apiv20191001.ResourceGroup -│ ├── Spec: Object (4 properties) -│ │ ├── AzureName: string -│ │ ├── Location: *string -│ │ ├── Owner: *genruntime.KnownResourceReference -│ │ └── Tags: map[string]string -│ └── Status: Object (14 properties) -│ ├── AccountId: *string -│ ├── Conditions: conditions.Condition[] -│ ├── DefaultIngestionSettings: *Object (2 properties) -│ │ ├── DataCollectionEndpointResourceId: *string -│ │ └── DataCollectionRuleResourceId: *string -│ ├── Etag: *string -│ ├── Id: *string -│ ├── Location: *string -│ ├── Metrics: *Object (2 properties) -│ │ ├── InternalId: *string -│ │ └── PrometheusQueryEndpoint: *string -│ ├── Name: *string -│ ├── PrivateEndpointConnections: Object (1 property)[] -│ │ └── Id: *string -│ ├── ProvisioningState: *Enum (5 values) -│ │ ├── "Canceled" -│ │ ├── "Creating" -│ │ ├── "Deleting" -│ │ ├── "Failed" -│ │ └── "Succeeded" -│ ├── PublicNetworkAccess: *Enum (2 values) -│ │ ├── "Disabled" -│ │ └── "Enabled" -│ ├── SystemData: *Object (6 properties) -│ │ ├── CreatedAt: *string -│ │ ├── CreatedBy: *string -│ │ ├── CreatedByType: *Enum (4 values) -│ │ │ ├── "Application" -│ │ │ ├── "Key" -│ │ │ ├── "ManagedIdentity" -│ │ │ └── "User" -│ │ ├── LastModifiedAt: *string -│ │ ├── LastModifiedBy: *string -│ │ └── LastModifiedByType: *Enum (4 values) -│ │ ├── "Application" -│ │ ├── "Key" -│ │ ├── "ManagedIdentity" -│ │ └── "User" -│ ├── Tags: map[string]string -│ └── Type: *string -├── Account_STATUS_ARM: Object (8 properties) -│ ├── Etag: *string -│ ├── Id: *string -│ ├── Location: *string -│ ├── Name: *string -│ ├── Properties: *Object (6 properties) -│ │ ├── AccountId: *string -│ │ ├── DefaultIngestionSettings: *Object (2 properties) -│ │ │ ├── DataCollectionEndpointResourceId: *string -│ │ │ └── DataCollectionRuleResourceId: *string -│ │ ├── Metrics: *Object (2 properties) -│ │ │ ├── InternalId: *string -│ │ │ └── PrometheusQueryEndpoint: *string -│ │ ├── PrivateEndpointConnections: Object (1 property)[] -│ │ │ └── Id: *string -│ │ ├── ProvisioningState: *Enum (5 values) -│ │ │ ├── "Canceled" -│ │ │ ├── "Creating" -│ │ │ ├── "Deleting" -│ │ │ ├── "Failed" -│ │ │ └── "Succeeded" -│ │ └── PublicNetworkAccess: *Enum (2 values) -│ │ ├── "Disabled" -│ │ └── "Enabled" -│ ├── SystemData: *Object (6 properties) -│ │ ├── CreatedAt: *string -│ │ ├── CreatedBy: *string -│ │ ├── CreatedByType: *Enum (4 values) -│ │ │ ├── "Application" -│ │ │ ├── "Key" -│ │ │ ├── "ManagedIdentity" -│ │ │ └── "User" -│ │ ├── LastModifiedAt: *string -│ │ ├── LastModifiedBy: *string -│ │ └── LastModifiedByType: *Enum (4 values) -│ │ ├── "Application" -│ │ ├── "Key" -│ │ ├── "ManagedIdentity" -│ │ └── "User" -│ ├── Tags: map[string]string -│ └── Type: *string -└── Account_Spec_ARM: Object (3 properties) - ├── Location: *string - ├── Name: string - └── Tags: map[string]string +└── Account: Resource + ├── Owner: resources/v1apiv20191001.ResourceGroup + ├── Spec: Object (4 properties) + │ ├── AzureName: string + │ ├── Location: *string + │ ├── Owner: *genruntime.KnownResourceReference + │ └── Tags: map[string]string + └── Status: Object (14 properties) + ├── AccountId: *string + ├── Conditions: conditions.Condition[] + ├── DefaultIngestionSettings: *Object (2 properties) + │ ├── DataCollectionEndpointResourceId: *string + │ └── DataCollectionRuleResourceId: *string + ├── Etag: *string + ├── Id: *string + ├── Location: *string + ├── Metrics: *Object (2 properties) + │ ├── InternalId: *string + │ └── PrometheusQueryEndpoint: *string + ├── Name: *string + ├── PrivateEndpointConnections: Object (1 property)[] + │ └── Id: *string + ├── ProvisioningState: *Enum (5 values) + │ ├── "Canceled" + │ ├── "Creating" + │ ├── "Deleting" + │ ├── "Failed" + │ └── "Succeeded" + ├── PublicNetworkAccess: *Enum (2 values) + │ ├── "Disabled" + │ └── "Enabled" + ├── SystemData: *Object (6 properties) + │ ├── CreatedAt: *string + │ ├── CreatedBy: *string + │ ├── CreatedByType: *Enum (4 values) + │ │ ├── "Application" + │ │ ├── "Key" + │ │ ├── "ManagedIdentity" + │ │ └── "User" + │ ├── LastModifiedAt: *string + │ ├── LastModifiedBy: *string + │ └── LastModifiedByType: *Enum (4 values) + │ ├── "Application" + │ ├── "Key" + │ ├── "ManagedIdentity" + │ └── "User" + ├── Tags: map[string]string + └── Type: *string From 36fa4bd588b7d185089704dc65ece3ac5ade0bf7 Mon Sep 17 00:00:00 2001 From: Bevan Arps Date: Mon, 10 Jun 2024 12:50:30 +1200 Subject: [PATCH 15/15] Update golden files --- .../person-v20200101_test.golden | 60 ------------------- .../person-v20211231-storage_test.golden | 40 ++++++------- .../person-v20200101-storage_test.golden | 56 +++++++++-------- .../person-v20211231_test.golden | 6 +- 4 files changed, 50 insertions(+), 112 deletions(-) diff --git a/v2/tools/generator/internal/codegen/pipeline/testdata/TestGolden_InjectJsonSerializationTests/person-v20200101_test.golden b/v2/tools/generator/internal/codegen/pipeline/testdata/TestGolden_InjectJsonSerializationTests/person-v20200101_test.golden index 5fc750541d..0de52ff9c1 100644 --- a/v2/tools/generator/internal/codegen/pipeline/testdata/TestGolden_InjectJsonSerializationTests/person-v20200101_test.golden +++ b/v2/tools/generator/internal/codegen/pipeline/testdata/TestGolden_InjectJsonSerializationTests/person-v20200101_test.golden @@ -138,66 +138,6 @@ func AddIndependentPropertyGeneratorsForPerson_STATUS(gens map[string]gopter.Gen gens["Status"] = gen.AlphaString() } -func Test_Person_STATUS_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { - t.Parallel() - parameters := gopter.DefaultTestParameters() - parameters.MinSuccessfulTests = 80 - parameters.MaxSize = 3 - properties := gopter.NewProperties(parameters) - properties.Property( - "Round trip of Person_STATUS via JSON returns original", - prop.ForAll(RunJSONSerializationTestForPerson_STATUS, Person_STATUSGenerator())) - properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout)) -} - -// RunJSONSerializationTestForPerson_STATUS runs a test to see if a specific instance of Person_STATUS round trips to JSON and back losslessly -func RunJSONSerializationTestForPerson_STATUS(subject Person_STATUS) string { - // Serialize to JSON - bin, err := json.Marshal(subject) - if err != nil { - return err.Error() - } - - // Deserialize back into memory - var actual Person_STATUS - err = json.Unmarshal(bin, &actual) - if err != nil { - return err.Error() - } - - // Check for outcome - match := cmp.Equal(subject, actual, cmpopts.EquateEmpty()) - if !match { - actualFmt := pretty.Sprint(actual) - subjectFmt := pretty.Sprint(subject) - result := diff.Diff(subjectFmt, actualFmt) - return result - } - - return "" -} - -// Generator of Person_STATUS instances for property testing - lazily instantiated by Person_STATUSGenerator() -var person_STATUSGenerator gopter.Gen - -// Person_STATUSGenerator returns a generator of Person_STATUS instances for property testing. -func Person_STATUSGenerator() gopter.Gen { - if person_STATUSGenerator != nil { - return person_STATUSGenerator - } - - generators := make(map[string]gopter.Gen) - AddIndependentPropertyGeneratorsForPerson_STATUS(generators) - person_STATUSGenerator = gen.Struct(reflect.TypeOf(Person_STATUS{}), generators) - - return person_STATUSGenerator -} - -// AddIndependentPropertyGeneratorsForPerson_STATUS is a factory method for creating gopter generators -func AddIndependentPropertyGeneratorsForPerson_STATUS(gens map[string]gopter.Gen) { - gens["Status"] = gen.AlphaString() -} - func Test_Person_Spec_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { t.Parallel() parameters := gopter.DefaultTestParameters() diff --git a/v2/tools/generator/internal/codegen/pipeline/testdata/TestGolden_InjectJsonSerializationTests/person-v20211231-storage_test.golden b/v2/tools/generator/internal/codegen/pipeline/testdata/TestGolden_InjectJsonSerializationTests/person-v20211231-storage_test.golden index 42e5126129..cbec87bd95 100644 --- a/v2/tools/generator/internal/codegen/pipeline/testdata/TestGolden_InjectJsonSerializationTests/person-v20211231-storage_test.golden +++ b/v2/tools/generator/internal/codegen/pipeline/testdata/TestGolden_InjectJsonSerializationTests/person-v20211231-storage_test.golden @@ -81,17 +81,17 @@ func AddIndependentPropertyGeneratorsForAddress(gens map[string]gopter.Gen) { func Test_Person_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { t.Parallel() parameters := gopter.DefaultTestParameters() - parameters.MinSuccessfulTests = 100 + parameters.MinSuccessfulTests = 20 parameters.MaxSize = 3 properties := gopter.NewProperties(parameters) properties.Property( - "Round trip of Address via JSON returns original", - prop.ForAll(RunJSONSerializationTestForAddress, AddressGenerator())) + "Round trip of Person via JSON returns original", + prop.ForAll(RunJSONSerializationTestForPerson, PersonGenerator())) properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout)) } -// RunJSONSerializationTestForAddress runs a test to see if a specific instance of Address round trips to JSON and back losslessly -func RunJSONSerializationTestForAddress(subject Address) string { +// RunJSONSerializationTestForPerson runs a test to see if a specific instance of Person round trips to JSON and back losslessly +func RunJSONSerializationTestForPerson(subject Person) string { // Serialize to JSON bin, err := json.Marshal(subject) if err != nil { @@ -99,7 +99,7 @@ func RunJSONSerializationTestForAddress(subject Address) string { } // Deserialize back into memory - var actual Address + var actual Person err = json.Unmarshal(bin, &actual) if err != nil { return err.Error() @@ -117,32 +117,32 @@ func RunJSONSerializationTestForAddress(subject Address) string { return "" } -// Generator of Address instances for property testing - lazily instantiated by AddressGenerator() -var addressGenerator gopter.Gen +// Generator of Person instances for property testing - lazily instantiated by PersonGenerator() +var personGenerator gopter.Gen -// AddressGenerator returns a generator of Address instances for property testing. -func AddressGenerator() gopter.Gen { - if addressGenerator != nil { - return addressGenerator +// PersonGenerator returns a generator of Person instances for property testing. +func PersonGenerator() gopter.Gen { + if personGenerator != nil { + return personGenerator } generators := make(map[string]gopter.Gen) - AddIndependentPropertyGeneratorsForAddress(generators) - addressGenerator = gen.Struct(reflect.TypeOf(Address{}), generators) + AddRelatedPropertyGeneratorsForPerson(generators) + personGenerator = gen.Struct(reflect.TypeOf(Person{}), generators) - return addressGenerator + return personGenerator } -// AddIndependentPropertyGeneratorsForAddress is a factory method for creating gopter generators -func AddIndependentPropertyGeneratorsForAddress(gens map[string]gopter.Gen) { - gens["City"] = gen.PtrOf(gen.AlphaString()) - gens["FullAddress"] = gen.PtrOf(gen.AlphaString()) +// AddRelatedPropertyGeneratorsForPerson is a factory method for creating gopter generators +func AddRelatedPropertyGeneratorsForPerson(gens map[string]gopter.Gen) { + gens["Spec"] = Person_SpecGenerator() + gens["Status"] = Person_STATUSGenerator() } func Test_Person_STATUS_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { t.Parallel() parameters := gopter.DefaultTestParameters() - parameters.MinSuccessfulTests = 20 + parameters.MinSuccessfulTests = 80 parameters.MaxSize = 3 properties := gopter.NewProperties(parameters) properties.Property( diff --git a/v2/tools/generator/internal/codegen/pipeline/testdata/TestGolden_InjectResourceConversionTestCases/person-v20200101-storage_test.golden b/v2/tools/generator/internal/codegen/pipeline/testdata/TestGolden_InjectResourceConversionTestCases/person-v20200101-storage_test.golden index 2657d78c6c..8a946bdf8f 100644 --- a/v2/tools/generator/internal/codegen/pipeline/testdata/TestGolden_InjectResourceConversionTestCases/person-v20200101-storage_test.golden +++ b/v2/tools/generator/internal/codegen/pipeline/testdata/TestGolden_InjectResourceConversionTestCases/person-v20200101-storage_test.golden @@ -164,32 +164,32 @@ func AddRelatedPropertyGeneratorsForPerson(gens map[string]gopter.Gen) { gens["Status"] = Person_STATUSGenerator() } -func Test_Person_Spec_WhenPropertiesConverted_RoundTripsWithoutLoss(t *testing.T) { +func Test_Person_STATUS_WhenPropertiesConverted_RoundTripsWithoutLoss(t *testing.T) { t.Parallel() parameters := gopter.DefaultTestParameters() parameters.MaxSize = 10 properties := gopter.NewProperties(parameters) properties.Property( - "Round trip from Person_Spec to Person_Spec via AssignProperties_To_Person_Spec & AssignProperties_From_Person_Spec returns original", - prop.ForAll(RunPropertyAssignmentTestForPerson_Spec, Person_SpecGenerator())) + "Round trip from Person_STATUS to Person_STATUS via AssignProperties_To_Person_STATUS & AssignProperties_From_Person_STATUS returns original", + prop.ForAll(RunPropertyAssignmentTestForPerson_STATUS, Person_STATUSGenerator())) properties.TestingRun(t, gopter.NewFormatedReporter(false, 240, os.Stdout)) } -// RunPropertyAssignmentTestForPerson_Spec tests if a specific instance of Person_Spec can be assigned to storage and back losslessly -func RunPropertyAssignmentTestForPerson_Spec(subject Person_Spec) string { +// RunPropertyAssignmentTestForPerson_STATUS tests if a specific instance of Person_STATUS can be assigned to storage and back losslessly +func RunPropertyAssignmentTestForPerson_STATUS(subject Person_STATUS) string { // Copy subject to make sure assignment doesn't modify it copied := subject.DeepCopy() // Use AssignPropertiesTo() for the first stage of conversion - var other storage.Person_Spec - err := copied.AssignProperties_To_Person_Spec(&other) + var other storage.Person_STATUS + err := copied.AssignProperties_To_Person_STATUS(&other) if err != nil { return err.Error() } // Use AssignPropertiesFrom() to convert back to our original type - var actual Person_Spec - err = actual.AssignProperties_From_Person_Spec(&other) + var actual Person_STATUS + err = actual.AssignProperties_From_Person_STATUS(&other) if err != nil { return err.Error() } @@ -206,20 +206,20 @@ func RunPropertyAssignmentTestForPerson_Spec(subject Person_Spec) string { return "" } -func Test_Person_Spec_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { +func Test_Person_STATUS_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { t.Parallel() parameters := gopter.DefaultTestParameters() parameters.MinSuccessfulTests = 80 parameters.MaxSize = 3 properties := gopter.NewProperties(parameters) properties.Property( - "Round trip of Person_Spec via JSON returns original", - prop.ForAll(RunJSONSerializationTestForPerson_Spec, Person_SpecGenerator())) + "Round trip of Person_STATUS via JSON returns original", + prop.ForAll(RunJSONSerializationTestForPerson_STATUS, Person_STATUSGenerator())) properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout)) } -// RunJSONSerializationTestForPerson_Spec runs a test to see if a specific instance of Person_Spec round trips to JSON and back losslessly -func RunJSONSerializationTestForPerson_Spec(subject Person_Spec) string { +// RunJSONSerializationTestForPerson_STATUS runs a test to see if a specific instance of Person_STATUS round trips to JSON and back losslessly +func RunJSONSerializationTestForPerson_STATUS(subject Person_STATUS) string { // Serialize to JSON bin, err := json.Marshal(subject) if err != nil { @@ -227,7 +227,7 @@ func RunJSONSerializationTestForPerson_Spec(subject Person_Spec) string { } // Deserialize back into memory - var actual Person_Spec + var actual Person_STATUS err = json.Unmarshal(bin, &actual) if err != nil { return err.Error() @@ -245,27 +245,25 @@ func RunJSONSerializationTestForPerson_Spec(subject Person_Spec) string { return "" } -// Generator of Person_Spec instances for property testing - lazily instantiated by Person_SpecGenerator() -var person_SpecGenerator gopter.Gen +// Generator of Person_STATUS instances for property testing - lazily instantiated by Person_STATUSGenerator() +var person_STATUSGenerator gopter.Gen -// Person_SpecGenerator returns a generator of Person_Spec instances for property testing. -func Person_SpecGenerator() gopter.Gen { - if person_SpecGenerator != nil { - return person_SpecGenerator +// Person_STATUSGenerator returns a generator of Person_STATUS instances for property testing. +func Person_STATUSGenerator() gopter.Gen { + if person_STATUSGenerator != nil { + return person_STATUSGenerator } generators := make(map[string]gopter.Gen) - AddIndependentPropertyGeneratorsForPerson_Spec(generators) - person_SpecGenerator = gen.Struct(reflect.TypeOf(Person_Spec{}), generators) + AddIndependentPropertyGeneratorsForPerson_STATUS(generators) + person_STATUSGenerator = gen.Struct(reflect.TypeOf(Person_STATUS{}), generators) - return person_SpecGenerator + return person_STATUSGenerator } -// AddIndependentPropertyGeneratorsForPerson_Spec is a factory method for creating gopter generators -func AddIndependentPropertyGeneratorsForPerson_Spec(gens map[string]gopter.Gen) { - gens["FamilyName"] = gen.PtrOf(gen.AlphaString()) - gens["FullName"] = gen.PtrOf(gen.AlphaString()) - gens["KnownAs"] = gen.PtrOf(gen.AlphaString()) +// AddIndependentPropertyGeneratorsForPerson_STATUS is a factory method for creating gopter generators +func AddIndependentPropertyGeneratorsForPerson_STATUS(gens map[string]gopter.Gen) { + gens["Status"] = gen.PtrOf(gen.AlphaString()) } func Test_Person_Spec_WhenPropertiesConverted_RoundTripsWithoutLoss(t *testing.T) { diff --git a/v2/tools/generator/internal/codegen/pipeline/testdata/TestGolden_InjectResourceConversionTestCases/person-v20211231_test.golden b/v2/tools/generator/internal/codegen/pipeline/testdata/TestGolden_InjectResourceConversionTestCases/person-v20211231_test.golden index 9225f7f767..6db5bc1c24 100644 --- a/v2/tools/generator/internal/codegen/pipeline/testdata/TestGolden_InjectResourceConversionTestCases/person-v20211231_test.golden +++ b/v2/tools/generator/internal/codegen/pipeline/testdata/TestGolden_InjectResourceConversionTestCases/person-v20211231_test.golden @@ -194,7 +194,7 @@ func RunPropertyAssignmentTestForPerson(subject Person) string { return err.Error() } - // Check for outcome + // Check for a match match := cmp.Equal(subject, actual, cmpopts.EquateEmpty()) if !match { actualFmt := pretty.Sprint(actual) @@ -233,7 +233,7 @@ func RunJSONSerializationTestForPerson(subject Person) string { return err.Error() } - // Compare actual with what we started with + // Check for outcome match := cmp.Equal(subject, actual, cmpopts.EquateEmpty()) if !match { actualFmt := pretty.Sprint(actual) @@ -312,7 +312,7 @@ func RunPropertyAssignmentTestForPerson_STATUS(subject Person_STATUS) string { func Test_Person_STATUS_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) { t.Parallel() parameters := gopter.DefaultTestParameters() - parameters.MinSuccessfulTests = 20 + parameters.MinSuccessfulTests = 80 parameters.MaxSize = 3 properties := gopter.NewProperties(parameters) properties.Property(