Skip to content

Commit

Permalink
Updates base on PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
theunrepentantgeek committed Jul 21, 2021
1 parent 1017673 commit 64e9d88
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
8 changes: 4 additions & 4 deletions hack/generator/pkg/astmodel/interface_injector.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ func NewInterfaceInjector() *InterfaceInjector {
}

// Inject modifies the passed type definition by injecting the passed function
func (fi *InterfaceInjector) Inject(def TypeDefinition, implementation *InterfaceImplementation) (TypeDefinition, error) {
result, err := fi.visitor.VisitDefinition(def, implementation)
func (i *InterfaceInjector) Inject(def TypeDefinition, implementation *InterfaceImplementation) (TypeDefinition, error) {
result, err := i.visitor.VisitDefinition(def, implementation)
if err != nil {
return TypeDefinition{}, err
}
Expand All @@ -34,15 +34,15 @@ func (fi *InterfaceInjector) Inject(def TypeDefinition, implementation *Interfac

// injectFunctionIntoObject takes the function provided as a context and includes it on the
// provided object type
func (_ *InterfaceInjector) injectInterfaceIntoObject(
func (i *InterfaceInjector) injectInterfaceIntoObject(
_ *TypeVisitor, ot *ObjectType, ctx interface{}) (Type, error) {
implementation := ctx.(*InterfaceImplementation)
return ot.WithInterface(implementation), nil
}

// injectFunctionIntoResource takes the function provided as a context and includes it on the
// provided resource type
func (_ *InterfaceInjector) injectInterfaceIntoResource(
func (i *InterfaceInjector) injectInterfaceIntoResource(
_ *TypeVisitor, rt *ResourceType, ctx interface{}) (Type, error) {
fn := ctx.(*InterfaceImplementation)
return rt.WithInterface(fn), nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ func ImplementConvertibleInterface(idFactory astmodel.IdentifierFactory) Stage {
return stage
}

// createConvertibleInterfaceImplementation creates the required implementation of conversion.Convertible, ready for
// injection onto the resource. The ConvertTo() and ConvertFrom() methods chain the required conversion between resource
// versions, but are dependent upon previously injected AssignPropertiesTo() and AssignPropertiesFrom() methods to
// actually copy information across. See resource_conversion_function.go for more information.
func createConvertibleInterfaceImplementation(
name astmodel.TypeName,
resource *astmodel.ResourceType,
Expand All @@ -78,4 +82,4 @@ func createConvertibleInterfaceImplementation(
}

return astmodel.NewInterfaceImplementation(astmodel.ConvertibleInterface, conversionFunctions...)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"github.com/Azure/azure-service-operator/hack/generator/pkg/test"
)

// TestInjectConvertibleInterface checks that the pipeline stage does what we expect when run in relative isolation,
// with only a few expected (and closely reated) stages in operation
func TestInjectConvertibleInterface(t *testing.T) {
g := NewGomegaWithT(t)

Expand Down

0 comments on commit 64e9d88

Please sign in to comment.