refactor: use struct for test request and fix CLI typo#389
Conversation
|
Welcome to the Microcks community! 💖 Thanks and congrats 🎉 for opening your first pull request here! Be sure to follow the pull request template or please update it accordingly. Hope you have a great time there! |
Signed-off-by: Pranjali Bhardwaj <pranjalisharma6543@gmail.com>
|
You are now a Microcks community contributor! 💖 Thanks and congrats 🚀 on merging your first pull request! We are delighted and very proud of you! 👏 📢 If you're using Microcks in your organization, please add your company name to this list. 🙏 It really helps the project to gain momentum and credibility. It's a small contribution back to the project with a big impact. If you need to know why and how to add yourself to the list, please read the blog post "Join the Microcks Adopters list and Empower the vibrant open source Community 🙌" Kudos and please keep going, we need you 🙌 |
Description
Looking through pkg/connectors and it still appeared that CreateTestResult was manually creating the test result using string concatenation to build the JSON. It was a bit of a chore to read and I'm not sure why we needed to add more fields later on, but I replaced it with a proper testRequest struct and json.Marshal.
I used json.We don't need to convert those optional "flags" (like filteredOperations) to JSON because they are already JSON strings from the CLI. Don't worry, I'm not about to unmarshal them and then put them back in the payload, but this way we are able to use omitempty properly.
Also found a typo in the main entry point: NewCommad -> NewCommand. I can't tell if it was by design or not, but I could not find it in any other place than main.go, so I just fixed it.
Related issue(s) : #388
Implementation Summary
Introduced a new struct called internal testRequest into microcks_client.go.
Replaced manual concatenation of strings in CreateTestResult with json.Marshal.
Changed the name of NewCommad to NewCommand in file cmd/cmd.go and main.go.
How I tested this
Rebuilt locally to ensure that the rename didn't cause any problems.
Tested JSON output for omitempty, which seems to work for secretName.
No new test case created for this because it is largely a refactoring of existing behavior, but the existing client tests appear happy.