-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: Introduce log and refactor logic of cmd #18
Conversation
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.
Generally speaking, as long as there is a command that does both "create the sdk and then create the terraform provider" then I am neutral on splitting things into separate files. I think it makes sense that if there will be separate commands than the command that does both is not called "mktp," so whatever name you want to use is fine. Please put the command in the "cmd" directory with the other commands.
The reason that I don't use "log" to output log messages right now is because of unit testing. Catching and testing the content of log messages that are output using "log" is harder than checking what's written to os.Stderr / os.Stdout. In a testing scenario, you can import "os" and then replace what's saved in os.Stderr / os.Stdout with string buffers, which will allow you to validate log messages written out are as expected.
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 merged #17 into main
branch, so please resolve conflicts.
Regarding splitting command at this stage of the project - I'm not convinced. Maybe later, but for now we have much more other stuff to implement.
Regarding log messages - I prefer to use log
package, because the logger writes to standard error and prints the date and time of each logged message. It has also a nice feature for new lines - if the message being printed does not end in a newline, the logger will add one.
When we take final decision about splitting and logs, I will approve that PR.
…ogic # Conflicts: # cmd/mktp/main.go # go.mod # pkg/mktp/cmd.go # pkg/naming/names.go
I redo some part of the code, and create one file in About the test, right now we assume if error exist it is bad :) joke aside, right now we don't have the test related to different error messages. There are couple nice libraries also introducing more capability for testing from go-kit library, like level etc, which will be nice to have, but still this is another dependencies. |
Thanks, I merged the changes :) |
cmd/main.go
Outdated
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 have a strong preference for the ./cmd
directory to only have other directories, not go code. You mentioned that you reviewed a few other big projects in our last meeting tho, did some of them do this, and you're modeling this after what you found in your investigations?
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.
Yes, ie. Prometheus are constructed that way -> https://github.com/prometheus/prometheus/blob/main/cmd/prometheus/main.go
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 change it a little bit, I added directory there
import ( | ||
"context" | ||
"fmt" | ||
"log" |
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 have a preference to not use log, but instead have the commands take a stdin / stderr / stdout, and then use fmt.Fprintf()
to output messages there, as this setup provides easier access to the log messages output for unit tests / integration tests. If you look at the scm generator, although I don't have any unit tests there, this is modeled in that generator.
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.
But testing is based on the function working correctly and not on function logs. We are expecting that function behave and gives us wanted output :)
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.
In my opinion we can go wit log
approach and in tests focus on function outputs, not logs generated by function.
If in future that decision will not work for us, we can always change it :)
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.
👍
…ogic # Conflicts: # pkg/generate/generator.go
Ultimately we agreed to not splitting the logic for the mktp and mksdk to two different files, rather to refactor the base code and introduce the log instead of io.writer.
Description
Motivation and Context
How Has This Been Tested?
Screenshots (if appropriate)
Types of changes
Checklist