Generate get/set management policy

Signed-off-by: Hasan Turken <turkenh@gmail.com>
This commit is contained in:
Hasan Turken 2022-11-29 18:00:19 +03:00
parent 806c0b0109
commit 350d1d88b4
No known key found for this signature in database
GPG Key ID: EE8BB9CB12F58415
4 changed files with 70 additions and 6 deletions

View File

@ -114,6 +114,8 @@ func GenerateManaged(filename, header string, p *packages.Package) error {
"GetWriteConnectionSecretToReference": method.NewGetWriteConnectionSecretToReference(receiver, RuntimeImport),
"SetPublishConnectionDetailsTo": method.NewSetPublishConnectionDetailsTo(receiver, RuntimeImport),
"GetPublishConnectionDetailsTo": method.NewGetPublishConnectionDetailsTo(receiver, RuntimeImport),
"SetManagementPolicy": method.NewSetManagementPolicy(receiver, RuntimeImport),
"GetManagementPolicy": method.NewGetManagementPolicy(receiver, RuntimeImport),
"SetDeletionPolicy": method.NewSetDeletionPolicy(receiver, RuntimeImport),
"GetDeletionPolicy": method.NewGetDeletionPolicy(receiver, RuntimeImport),
}

View File

@ -55,7 +55,8 @@ func TestBreakingChanges(t *testing.T) {
},
"spec": {
Properties: map[string]v1.JSONSchemaProps{
"deletionPolicy": {},
"managementPolicy": {},
"deletionPolicy": {},
"forProvider": {
Properties: map[string]v1.JSONSchemaProps{
"description": {},
@ -124,7 +125,8 @@ func TestBreakingChanges(t *testing.T) {
},
"spec": {
Properties: map[string]v1.JSONSchemaProps{
"deletionPolicy": {},
"managementPolicy": {},
"deletionPolicy": {},
"forProvider": {
Properties: map[string]v1.JSONSchemaProps{
"description": {},
@ -184,7 +186,8 @@ func TestBreakingChanges(t *testing.T) {
Properties: map[string]v1.JSONSchemaProps{
"spec": {
Properties: map[string]v1.JSONSchemaProps{
"deletionPolicy": {},
"deletionPolicy": {},
"managementPolicy": {},
"forProvider": {
Properties: map[string]v1.JSONSchemaProps{
"description": {},
@ -206,7 +209,8 @@ func TestBreakingChanges(t *testing.T) {
Properties: map[string]v1.JSONSchemaProps{
"spec": {
Properties: map[string]v1.JSONSchemaProps{
"deletionPolicy": {},
"deletionPolicy": {},
"managementPolicy": {},
"forProvider": {
Properties: map[string]v1.JSONSchemaProps{
"enableInboundForwarding": {},
@ -248,7 +252,8 @@ func TestBreakingChanges(t *testing.T) {
},
"spec": {
Properties: map[string]v1.JSONSchemaProps{
"deletionPolicy": {},
"managementPolicy": {},
"deletionPolicy": {},
},
},
},
@ -269,7 +274,8 @@ func TestBreakingChanges(t *testing.T) {
},
"spec": {
Properties: map[string]v1.JSONSchemaProps{
"deletionPolicy": {},
"managementPolicy": {},
"deletionPolicy": {},
},
},
},

View File

@ -236,6 +236,28 @@ func NewLocalGetWriteConnectionSecretToReference(receiver, runtime string) New {
}
}
// NewSetManagementPolicy returns a NewMethod that writes a SetManagementPolicy
// method for the supplied Object to the supplied file.
func NewSetManagementPolicy(receiver, runtime string) New {
return func(f *jen.File, o types.Object) {
f.Commentf("SetManagementPolicy of this %s.", o.Name())
f.Func().Params(jen.Id(receiver).Op("*").Id(o.Name())).Id("SetManagementPolicy").Params(jen.Id("r").Qual(runtime, "ManagementPolicy")).Block(
jen.Id(receiver).Dot(fields.NameSpec).Dot("ManagementPolicy").Op("=").Id("r"),
)
}
}
// NewGetManagementPolicy returns a NewMethod that writes a GetManagementPolicy
// method for the supplied Object to the supplied file.
func NewGetManagementPolicy(receiver, runtime string) New {
return func(f *jen.File, o types.Object) {
f.Commentf("GetManagementPolicy of this %s.", o.Name())
f.Func().Params(jen.Id(receiver).Op("*").Id(o.Name())).Id("GetManagementPolicy").Params().Qual(runtime, "ManagementPolicy").Block(
jen.Return(jen.Id(receiver).Dot(fields.NameSpec).Dot("ManagementPolicy")),
)
}
}
// NewSetDeletionPolicy returns a NewMethod that writes a SetDeletionPolicy
// method for the supplied Object to the supplied file.
func NewSetDeletionPolicy(receiver, runtime string) New {

View File

@ -279,6 +279,40 @@ func (t *Type) GetWriteConnectionSecretToReference() *runtime.LocalSecretReferen
}
}
func TestNewSetManagementPolicy(t *testing.T) {
want := `package pkg
import runtime "example.org/runtime"
// SetManagementPolicy of this Type.
func (t *Type) SetManagementPolicy(r runtime.ManagementPolicy) {
t.Spec.ManagementPolicy = r
}
`
f := jen.NewFilePath("pkg")
NewSetManagementPolicy("t", "example.org/runtime")(f, MockObject{Named: "Type"})
if diff := cmp.Diff(want, fmt.Sprintf("%#v", f)); diff != "" {
t.Errorf("NewSetManagementPolicy(): -want, +got\n%s", diff)
}
}
func TestNewGetManagementPolicy(t *testing.T) {
want := `package pkg
import runtime "example.org/runtime"
// GetManagementPolicy of this Type.
func (t *Type) GetManagementPolicy() runtime.ManagementPolicy {
return t.Spec.ManagementPolicy
}
`
f := jen.NewFilePath("pkg")
NewGetManagementPolicy("t", "example.org/runtime")(f, MockObject{Named: "Type"})
if diff := cmp.Diff(want, fmt.Sprintf("%#v", f)); diff != "" {
t.Errorf("NewGetManagementPolicy(): -want, +got\n%s", diff)
}
}
func TestNewSetDeletionPolicy(t *testing.T) {
want := `package pkg