-
Notifications
You must be signed in to change notification settings - Fork 226
Add support for references within lists of structs #332
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
Changes from all commits
35a37f5
12dde1e
eafb9f5
b20b95a
02b0a42
f2ee190
33343bc
087ca47
9f3d02e
5ccc462
03a83fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -118,7 +118,7 @@ func Test_ReferenceFieldsPresent_NoReferenceConfig(t *testing.T) { | |
|
|
||
| crd := testutil.GetCRDByName(t, g, "Api") | ||
| require.NotNil(crd) | ||
| expected := "false" | ||
| expected := "return false" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Initially I left out the "return" part to make these conditionals reusable in any "if" block... However now i can see that it's not possible to support all the types with that limitation. No objections to the change but i thought of commenting the initial intention of not adding the "return" word.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah I was wondering why that was left out. Hopefully if anything else needs that logic, it can just use the method directly, itself. Nice forward thinking, though |
||
| assert.Equal(expected, code.ReferenceFieldsPresent(crd, "ko")) | ||
| } | ||
|
|
||
|
|
@@ -133,7 +133,7 @@ func Test_ReferenceFieldsPresent_SingleReference(t *testing.T) { | |
|
|
||
| crd := testutil.GetCRDByName(t, g, "Integration") | ||
| require.NotNil(crd) | ||
| expected := "false || (ko.Spec.APIRef != nil)" | ||
| expected := "return false || (ko.Spec.APIRef != nil)" | ||
| assert.Equal(expected, code.ReferenceFieldsPresent(crd, "ko")) | ||
| } | ||
|
|
||
|
|
@@ -150,7 +150,7 @@ func Test_ReferenceFieldsPresent_SliceOfReferences(t *testing.T) { | |
| // just to test code generation for slices of reference | ||
| crd := testutil.GetCRDByName(t, g, "VpcLink") | ||
| require.NotNil(crd) | ||
| expected := "false || (ko.Spec.SecurityGroupRefs != nil) || (ko.Spec.SubnetRefs != nil)" | ||
| expected := "return false || (ko.Spec.SecurityGroupRefs != nil) || (ko.Spec.SubnetRefs != nil)" | ||
| assert.Equal(expected, code.ReferenceFieldsPresent(crd, "ko")) | ||
| } | ||
|
|
||
|
|
@@ -165,6 +165,36 @@ func Test_ReferenceFieldsPresent_NestedReference(t *testing.T) { | |
|
|
||
| crd := testutil.GetCRDByName(t, g, "Authorizer") | ||
| require.NotNil(crd) | ||
| expected := "false || (ko.Spec.JWTConfiguration != nil && ko.Spec.JWTConfiguration.IssuerRef != nil)" | ||
| expected := "return false || (ko.Spec.JWTConfiguration != nil && ko.Spec.JWTConfiguration.IssuerRef != nil)" | ||
| assert.Equal(expected, code.ReferenceFieldsPresent(crd, "ko")) | ||
| } | ||
|
|
||
| func Test_ReferenceFieldsPresent_NestedSliceOfStructsReference(t *testing.T) { | ||
| assert := assert.New(t) | ||
| require := require.New(t) | ||
|
|
||
| g := testutil.NewModelForServiceWithOptions(t, "ec2", | ||
| &testutil.TestingModelOptions{ | ||
| GeneratorConfigFile: "generator-with-nested-reference.yaml", | ||
| }) | ||
|
|
||
| crd := testutil.GetCRDByName(t, g, "RouteTable") | ||
| require.NotNil(crd) | ||
| expected := | ||
| `if ko.Spec.Routes != nil { | ||
| for _, iter32 := range ko.Spec.Routes { | ||
| if iter32.GatewayRef != nil { | ||
| return true | ||
| } | ||
| } | ||
| } | ||
| if ko.Spec.Routes != nil { | ||
| for _, iter35 := range ko.Spec.Routes { | ||
| if iter35.NATGatewayRef != nil { | ||
| return true | ||
| } | ||
| } | ||
| } | ||
| return false || (ko.Spec.VPCRef != nil)` | ||
| assert.Equal(expected, code.ReferenceFieldsPresent(crd, "ko")) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -703,6 +703,7 @@ func (r *CRD) ReferencedServiceNames() (serviceNames []string) { | |
| for serviceName, _ := range serviceNamesMap { | ||
| serviceNames = append(serviceNames, serviceName) | ||
| } | ||
| sort.Strings(serviceNames) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| return serviceNames | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I presume this is to ensure determinism?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I was seeing the imports and schemas jumping around in my git diff