mirror of
https://github.com/mailgun/groupcache.git
synced 2024-11-16 14:10:04 +00:00
Improved http error tests (#61)
This commit is contained in:
parent
9f417fbc4f
commit
cc3d361eb2
@ -17,8 +17,9 @@ func (e *ErrNotFound) Is(target error) bool {
|
||||
return ok
|
||||
}
|
||||
|
||||
// ErrRemoteCall is returned from `group.Get()` when an error that is not a `ErrNotFound`
|
||||
// is returned during a remote HTTP instance call
|
||||
// ErrRemoteCall is returned from `group.Get()` when a remote GetterFunc returns an
|
||||
// error. When this happens `group.Get()` does not attempt to retrieve the value
|
||||
// via our local GetterFunc.
|
||||
type ErrRemoteCall struct {
|
||||
Msg string
|
||||
}
|
||||
|
25
http_test.go
25
http_test.go
@ -187,21 +187,24 @@ func TestHTTPPool(t *testing.T) {
|
||||
}
|
||||
|
||||
// Get a key that does not exist
|
||||
err := g.Get(ctx, "IDoNotExist", StringSink(&value))
|
||||
err := g.Get(ctx, "IReturnErrNotFound", StringSink(&value))
|
||||
errNotFound := &ErrNotFound{}
|
||||
if !errors.As(err, &errNotFound) {
|
||||
t.Fatal(errors.New("expected error to be 'ErrNotFound'"))
|
||||
}
|
||||
assert.Equal(t, "I do not exist error", errNotFound.Error())
|
||||
assert.Equal(t, "I am a ErrNotFound error", errNotFound.Error())
|
||||
|
||||
// Get a key that is guaranteed to return an error
|
||||
err = g.Get(ctx, "IAlwaysReturnAnError", StringSink(&value))
|
||||
// Get a key that is guaranteed to return a remote error.
|
||||
err = g.Get(ctx, "IReturnErrRemoteCall", StringSink(&value))
|
||||
errRemoteCall := &ErrRemoteCall{}
|
||||
if !errors.As(err, &errRemoteCall) {
|
||||
t.Fatal(errors.New("expected error to be 'ErrRemoteCall'"))
|
||||
}
|
||||
assert.Equal(t, "I am a ErrRemoteCall error", errRemoteCall.Error())
|
||||
|
||||
assert.Equal(t, "I am a GetterFunc error", errRemoteCall.Error())
|
||||
// Get a key that is guaranteed to return an internal (500) error
|
||||
err = g.Get(ctx, "IReturnInternalError", StringSink(&value))
|
||||
assert.Equal(t, "I am a errors.New() error", err.Error())
|
||||
|
||||
}
|
||||
|
||||
@ -220,12 +223,16 @@ func beChildForTestHTTPPool(t *testing.T) {
|
||||
p.Set(addrToURL(addrs)...)
|
||||
|
||||
getter := GetterFunc(func(ctx context.Context, key string, dest Sink) error {
|
||||
if key == "IDoNotExist" {
|
||||
return &ErrNotFound{Msg: "I do not exist error"}
|
||||
if key == "IReturnErrNotFound" {
|
||||
return &ErrNotFound{Msg: "I am a ErrNotFound error"}
|
||||
}
|
||||
|
||||
if key == "IAlwaysReturnAnError" {
|
||||
return &ErrRemoteCall{Msg: "I am a GetterFunc error"}
|
||||
if key == "IReturnErrRemoteCall" {
|
||||
return &ErrRemoteCall{Msg: "I am a ErrRemoteCall error"}
|
||||
}
|
||||
|
||||
if key == "IReturnInternalError" {
|
||||
return errors.New("I am a errors.New() error")
|
||||
}
|
||||
|
||||
if _, err := http.Get(*serverAddr); err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user