-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
smart diff to testutil.GatherAndCompare #998
Conversation
Signed-off-by: Sourik Ghosh <[email protected]>
review @bwplotka |
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.
Looking good.
I like to idea of using require.Equals
but these are changing existing APIs. I'm reluctant to change existing public APIs.
How about adding equivalent new version of the APIs that have t *testing.T
as a first parameter? and those can use require package under the hood.
Signed-off-by: Sourik Ghosh <[email protected]>
Signed-off-by: Sourik Ghosh <[email protected]>
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.
Rather than MethodNameV2, I'd prefer MethodNameWithTesting
or MethodNameWithT
Ok replacing it with |
Signed-off-by: Sourik Ghosh <[email protected]>
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.
Hey, thanks for this work 💪🏽
It is MUST have functionality, I miss it so much <3
But I think we need to be careful. I think we could improve this PR a bit:
- Ideally we don't force people to import extra (quite large)
testify
module.client_golang
lib is well used library, so we need to be careful here. I think there is no strong need. Proposed alternative. - I am not fan of extra interface (so many extra methods). I think we can remove that and add nice diff without
t *testing.T
- especially if we want to skiptestify
module import.
WDYT?
prometheus/testutil/testutil.go
Outdated
|
||
"github.com/prometheus/common/expfmt" | ||
"github.com/stretchr/testify/require" |
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.
Hm.. is there a way to avoid this package? For a reason we wanted to make sure it's not used, so we are not leaking it.
Since this is not testing code, every project that imports client_golang
needs to import testify
.... I think we want to copy the diff function and maintain here.
See how we did that here https://github.com/efficientgo/tools/blob/main/core/pkg/testutil/testutil.go#L101
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 totally agree. I think I was a little hasty to review this, and I haven't noticed testify is not there already 🙈
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 guess because it's already a transitive dependency.
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.
yeah, I agree too, this makes sense
but the above diff function has a dep on
https://github.com/efficientgo/tools/blob/fe763185946be83b20da626605319733bd7f97cb/core/pkg/testutil/testutil.go#L16 which is not maintained should I transfer the module implementation over here or just simply import it.
Signed-off-by: Sourik Ghosh <[email protected]>
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! Sorry for complaining, but I think there is small risk with the module of choice 🤔 WDYT?
go.mod
Outdated
github.com/golang/protobuf v1.5.2 | ||
github.com/json-iterator/go v1.1.12 | ||
github.com/pmezard/go-difflib v1.0.0 |
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 don't want to be a pain but this module is THIS PACKAGE IS NO LONGER MAINTAINED.
Not the best, since all users depending on our module will have to download it too.
I wonder if it makes sense to just copy the code for now with the required code (with test) over. Looks reasonably small. There is not benefit in depending on module that does not allow merging new changes.
Or we could find different package.
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.
🙃that was my question previously #998 (comment)
Ideally, I would prefer an alternative to the package but I couldn't find a good replacement. So maybe coping small piece of code and maintaining it over here ?!!!
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.
Yea, I think copy might be better
Signed-off-by: Sourik Ghosh <[email protected]>
Signed-off-by: Sourik Ghosh <[email protected]>
@bwplotka Could you please have another look? |
prometheus/testutil/difflib.go
Outdated
// It provides tools to compare sequences of strings and generate textual diffs. | ||
// | ||
// Maintaining `GetUnifiedDiffString` here because original repository | ||
// is no loger maintained.(https://github.com/pmezard/go-difflib) |
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.
// is no loger maintained.(https://github.com/pmezard/go-difflib) | |
// (https://github.com/pmezard/go-difflib) is no longer maintained. |
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 this work, and sorry for lag. Again - please ping me on CNCF slack (:
I found quite important thing to do before we merge, WDYT?
prometheus/testutil/difflib.go
Outdated
@@ -0,0 +1,649 @@ | |||
// Copyright 2022 The Prometheus Authors |
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 believe we want to make sure this is under internal
path so no one can import it. Otherwise we have to care about API, Go doc comments etc.
And I don't client_golang have to be library which offers diffing 🤔
Signed-off-by: Sourik Ghosh <[email protected]>
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.
Finally!
Thanks for your hard work 💪🏽
LGTM
Signed-off-by: Sourik Ghosh [email protected]
closes #996