-
Notifications
You must be signed in to change notification settings - Fork 5
fix: correct UnmarshalJSON and add MarshalJSON for CloudConfigFile #66
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
Conversation
|
Just for posterity if anyone wants to mess around with variations of the code, I used this for my own testing before testing with cloud-init itself: https://go.dev/play/p/eWegMtwpleC |
|
Is this related to the automatic encoding/decoding base64 strings that you mentioned earlier today? Edit: Iterations 3, 4, and 5 look the same from the go.dev link. What's the different between them? Are these just multiple runs? |
Yes. Both the unmarshaller/marshaller functions use an auxiliary struct that has
Yeah, I was making sure that multiple iterations weren't seeing an endlessly-recurring base64 encode chain. |
|
Added tests that confirm the behavior I expect. LGTM |
alexlovelltroy
left a comment
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.
LGTM
|
Thanks for adding the tests! Just one small change I added, that being using base64-encoded data instead of plain for the |
Closes #65
Turns out,
UnmarshalJSON()needed to be revised and aMarshalJSON()needed to be added forCloudConfigFile. Base64 encoding/decoding caused byjson.Marshal()/json.Unmarshal()was causing mismatches betweenCloudConfigFile.Encodingand the actual encoding ofCloudConfigFile.Content.For
UnmarshalJSON(), continue unmarshallingContentinto a string, but don't try to base64 decode into the struct.Encodingwill let the reader know if they need to decode it or not.For
MarshalJSON(), use the auxiliary struct likeUnmarshalJSON()does to convert the bytes to a string so thatjson.Marshal()doesn't try to base64-encode the bytes.