Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate Getters/Setters for Management Policy #51

Merged
merged 1 commit into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/angryjet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down
18 changes: 12 additions & 6 deletions cmd/breakingChanges/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {},
Expand Down Expand Up @@ -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": {},
Expand Down Expand Up @@ -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": {},
Expand All @@ -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": {},
Expand Down Expand Up @@ -248,7 +252,8 @@ func TestBreakingChanges(t *testing.T) {
},
"spec": {
Properties: map[string]v1.JSONSchemaProps{
"deletionPolicy": {},
"managementPolicy": {},
"deletionPolicy": {},
},
},
},
Expand All @@ -269,7 +274,8 @@ func TestBreakingChanges(t *testing.T) {
},
"spec": {
Properties: map[string]v1.JSONSchemaProps{
"deletionPolicy": {},
"managementPolicy": {},
"deletionPolicy": {},
},
},
},
Expand Down
22 changes: 22 additions & 0 deletions internal/method/method.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
34 changes: 34 additions & 0 deletions internal/method/method_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down