-
Notifications
You must be signed in to change notification settings - Fork 226
Support nested Ignore.FieldPaths #119
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
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 |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| // Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"). You may | ||
| // not use this file except in compliance with the License. A copy of the | ||
| // License is located at | ||
| // | ||
| // http://aws.amazon.com/apache2.0/ | ||
| // | ||
| // or in the "license" file accompanying this file. This file is distributed | ||
| // on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| // express or implied. See the License for the specific language governing | ||
| // permissions and limitations under the License. | ||
|
|
||
| package model_test | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "github.com/aws-controllers-k8s/code-generator/pkg/testutil" | ||
| ) | ||
|
|
||
| func TestEKS_IgnoreFieldPaths(t *testing.T) { | ||
| require := require.New(t) | ||
|
|
||
| g := testutil.NewModelForService(t, "eks") | ||
|
|
||
| crds, err := g.GetCRDs() | ||
| require.Nil(err) | ||
|
|
||
| crd := getCRDByName("Nodegroup", crds) | ||
| require.NotNil(crd) | ||
|
|
||
| // fields we have ignored via generator.yaml | ||
| ignoredFieldPaths := []string{ | ||
| "Version", | ||
| "ScalingConfig.DesiredSize", | ||
|
Comment on lines
+37
to
+38
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. Should'nt these be more 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. This is already under But yeah, if we could rewrite it to a unit test then maybe it would look like that, or maybe we should test it through another code path than |
||
| } | ||
| for _, ignoredFieldPath := range ignoredFieldPaths { | ||
| _, found := crd.Fields[ignoredFieldPath] | ||
| require.False(found, "field should be ignored: %v", ignoredFieldPath) | ||
| } | ||
|
|
||
| // Ensure we do not accidentally remove sibling fields | ||
| _, found := crd.Fields["ScalingConfig.MaxSize"] | ||
| require.True(found, "Sibling should be kept when ScalingConfig.DesiredSize is ignored") | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,10 @@ | ||
| ignore: | ||
| field_paths: | ||
| # Test nested field path of multiple levels | ||
| - Nodegroup.Version | ||
| - CreateNodegroupInput.Version | ||
| - CreateNodegroupInput.ScalingConfig.DesiredSize | ||
|
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. Quoting from the docstring: Would it be possible to use 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. Yeah, that works 🤦 Thanks! :D I was trying to help @ikarldasan on slack to get progress on crossplane-contrib/provider-aws#755 - but I didn't know how the generator config worked and dug into this hole. So for that case, to ignore TemplateName, it would simply be: ignore:
field_paths:
- Template.TemplateNameI though that was tested but apparently not :) |
||
|
|
||
| resources: | ||
| FargateProfile: | ||
| renames: | ||
|
|
||
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.
nit:
goimportscan help with separating internal from external importsThere 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 think
goimportsplaces it the same place, it was placed there bygopls. I tried deleting the line and by runninggoimports -w ./pkg/model/model.goI get the same result.The sibling file
code-generator/pkg/model/field.go
Lines 19 to 22 in 2f11b23