-
Notifications
You must be signed in to change notification settings - Fork 78
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
Add redisxtest #484
base: master
Are you sure you want to change the base?
Add redisxtest #484
Changes from all commits
0bcd4fb
1046c61
109ab82
6149f7f
94e25e8
6443170
b9a7d47
a07bb69
a3a0caa
d66f70d
f638087
124335f
acd77b3
481b431
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Package redisxtest provides utilities for baseplate.go/redids/cache/redisx testing. | ||
// | ||
// This includes functions for mocking redis instances. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment here regarding "mocking". I think with the current state of this change the first paragraph is enough for the package doc and we can just remove this paragraph. |
||
package redisxtest |
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,39 @@ | ||||||||||||||
package redisxtest | ||||||||||||||
|
||||||||||||||
import ( | ||||||||||||||
"context" | ||||||||||||||
"testing" | ||||||||||||||
|
||||||||||||||
"github.com/joomcode/redispipe/redis" | ||||||||||||||
"github.com/joomcode/redispipe/redisconn" | ||||||||||||||
|
||||||||||||||
"github.com/reddit/baseplate.go/redis/cache/redisx" | ||||||||||||||
) | ||||||||||||||
|
||||||||||||||
// NewMockRedisClient sets up a redis client for use in testing | ||||||||||||||
func NewMockRedisClient( | ||||||||||||||
Comment on lines
+13
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. now there's nothing really "mocking" here (the mocking part is done via miniredis, which is no longer done here). I would rename this function to
|
||||||||||||||
ctx context.Context, | ||||||||||||||
tb testing.TB, | ||||||||||||||
address string, | ||||||||||||||
opts redisconn.Opts, | ||||||||||||||
) (*redisx.BaseSync, error) { | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looking at how existing tests work, we do need the returned client to be of type
|
||||||||||||||
tb.Helper() | ||||||||||||||
|
||||||||||||||
// Create connection to redis | ||||||||||||||
conn, err := redisconn.Connect(ctx, address, opts) | ||||||||||||||
if err != nil { | ||||||||||||||
return nil, err | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is a testing helper, in my opinion it's better to call t.Fatalf and document that it must be called directly in a test / subtest, rather than do what is inevitable: have every user of this make their own local helper that wraps this helper that does the transition. I prefix my t.Fatalf errors with "SETUP:" to make it clear that it's not a failure of the code under test, and I would name the function "Setup" not "New" to encourage that interpretation as well. |
||||||||||||||
} | ||||||||||||||
Comment on lines
+24
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh and this function no longer need to return an error. this can be just:
Suggested change
|
||||||||||||||
|
||||||||||||||
// Create client | ||||||||||||||
client := redisx.BaseSync{ | ||||||||||||||
SyncCtx: redis.SyncCtx{S: conn}, | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
// Cleanup | ||||||||||||||
tb.Cleanup(func() { | ||||||||||||||
conn.Close() | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. check the error and log it if it fails? |
||||||||||||||
}) | ||||||||||||||
Comment on lines
+33
to
+36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I would move this up to right after the |
||||||||||||||
|
||||||||||||||
return &client, nil | ||||||||||||||
} |
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.
no need to spell out the full
baseplate.go/redids/cache/redisx
, just say "... for redisx testing" is enough.