-
Notifications
You must be signed in to change notification settings - Fork 173
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: minor increase in rueidiscompat coverage #583
feat: minor increase in rueidiscompat coverage #583
Conversation
message.go
Outdated
@@ -1386,3 +1386,8 @@ func (m *prettyRedisMessage) MarshalJSON() ([]byte, error) { | |||
} | |||
return json.Marshal(obj) | |||
} | |||
|
|||
// NewMockResult is a mock method to send back RedisResult with err for test coverage | |||
func NewMockResult(val RedisMessage, err error) RedisResult { |
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 mixed thoughts about this
Because even though this will provide us a way to cover roughly 20 more lines of code in ruediscompat command, we should not probably expose this as a part of rueidis package
But the only alternative to cover most of the other parts inside command would be to introduce interfaces instead of passing concrete structs and a large refactor. Otherwise, it seems difficult to achieve near-100% coverage.
What do you think? @rueian
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.
we should not probably expose this as a part of rueidis package
Agreed. Actually, we don't need this function but we can use the same hack of the mock
package instead:
Lines 22 to 25 in 45cdf7e
func ErrorResult(err error) rueidis.RedisResult { | |
r := result{err: err} | |
return *(*rueidis.RedisResult)(unsafe.Pointer(&r)) | |
} |
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.
Oh wow
This is a great use of unsafePtrs
rueidiscompat/command_test.go
Outdated
@@ -29,6 +29,8 @@ package rueidiscompat | |||
import ( | |||
"errors" | |||
"fmt" | |||
"github.com/redis/rueidis" |
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.
The import should be moved to below.
rueidiscompat/command_test.go
Outdated
@@ -29,6 +29,8 @@ package rueidiscompat | |||
import ( | |||
"errors" | |||
"fmt" | |||
"github.com/redis/rueidis" | |||
"github.com/stretchr/testify/assert" |
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.
Could we avoid introducing a new test dependency?
@@ -8,13 +8,15 @@ require ( | |||
github.com/onsi/ginkgo/v2 v2.15.0 | |||
github.com/onsi/gomega v1.31.1 | |||
github.com/redis/rueidis v1.0.40 | |||
github.com/redis/rueidis/mock v1.0.40 |
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 also add a local replace directive for this.
@@ -3,6 +3,7 @@ module github.com/redis/rueidis/rueidiscompat | |||
go 1.20 | |||
|
|||
replace github.com/redis/rueidis => ../ | |||
replace github.com/redis/rueidis/mock => ../mock |
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.
We should run go mod tidy
again after adding the replace directive.
LGTM. Thanks @SoulPancake! |
part of #487