-
Notifications
You must be signed in to change notification settings - Fork 107
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
initial commit for leaf setters #281
base: master
Are you sure you want to change the base?
initial commit for leaf setters #281
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here (e.g. What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
|
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
@robshakir |
@robshakir I shouldn't get the error because I already defined it but I don't know why it happens P.S. Resolved |
@robshakir |
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.
Thanks for the contribution, there are some technical issues with this change that I've pointed out in the review.
Additionally, there's no unit testing for this change -- please add tests that both check the generated sets of methods are correct for the individual code, as well as an integration test that does this across a real input module (integration test with goyang). You can see some examples of these in TestSimpleStructs
in codegen_test.go
.
Also, please let's add a test to schema_tests
in this package that tests more than just string fields.
Happy to discuss this design more if there's more info required as to the implementation here.
Thanks!
r.
goLeafSetterTemplate = ` | ||
// Set{{ .Name }} sets the value of the leaf {{ .Name }} from the {{ .Receiver }} | ||
// struct. | ||
func (t *{{ .Receiver }}) Set{{ .Name }}(val string) { |
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'm not sure that you can just take a string
as an argument, there are different types of fields that we have within the generated structs. Given that this is the case, we need to handle different inputs here. Determining the type that is needed should likely be from the input type that is in the generatedLeafSetter
that you created. There are some other details that you'll need though, such as the name of the generated union, such that you can call To_XXX
for these types.
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.
@robshakir
Thanks for your comments. That is a good point. I will start working on it but before that what types you would suggest to support? I will let you know if I have more questions.
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 think I figured that out.
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.
May I ask you how do you generate the expected output for the testcases? It says the following but it is not clear for me:
This package was generated by codegen-tests
using the following YANG input files: .....
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.
Please take a look at this code and I think it handles any type. Please let me know what you think. I also have a test case ready but I am not sure how do you generate the expected output in advance.
// goLeafSetterTemplate defines a template for a function that, for a
// particular leaf, generates a setter method.
goLeafSetterTemplate = `
// Set{{ .Name }} sets the value of the leaf {{ .Name }} from the {{ .Receiver }}
// struct.
func (t *{{ .Receiver }}) Set{{ .Name }}(val interface{}) {
if t == nil || val == nil {
return
}
t.{{ .Name }} = ygot.ToPtr(val).(*{{ .Type }})
}
`
if t == nil || val == "" { | ||
return | ||
} | ||
t.{{ .Name }} = ygot.String(val) |
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.
Same comment as above re: whether you can use string
.
This likely highlights a test coverage gap -- we should add tests to schema_tests
which give an integration test against a YANG model that has >1 different field type.
Initial commit for adding leaf setters