Skip to content
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

Merged
merged 8 commits into from
Jul 1, 2024

Conversation

SoulPancake
Copy link
Contributor

part of #487

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 {
Copy link
Contributor Author

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

Copy link
Collaborator

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:

rueidis/mock/result.go

Lines 22 to 25 in 45cdf7e

func ErrorResult(err error) rueidis.RedisResult {
r := result{err: err}
return *(*rueidis.RedisResult)(unsafe.Pointer(&r))
}

Copy link
Contributor Author

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

@@ -29,6 +29,8 @@ package rueidiscompat
import (
"errors"
"fmt"
"github.com/redis/rueidis"
Copy link
Collaborator

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.

@@ -29,6 +29,8 @@ package rueidiscompat
import (
"errors"
"fmt"
"github.com/redis/rueidis"
"github.com/stretchr/testify/assert"
Copy link
Collaborator

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?

@SoulPancake SoulPancake changed the title feat: 5% increase in command.go coverage feat: minor increase in rueidiscompat coverage Jun 27, 2024
@SoulPancake SoulPancake marked this pull request as ready for review June 28, 2024 10:00
@@ -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
Copy link
Collaborator

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
Copy link
Collaborator

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.

@SoulPancake SoulPancake requested a review from rueian June 28, 2024 17:51
@rueian
Copy link
Collaborator

rueian commented Jul 1, 2024

LGTM. Thanks @SoulPancake!

@rueian rueian merged commit 4951282 into redis:main Jul 1, 2024
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants