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
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
// ErrRemoteCall is returned from `group.Get()` when an error that is not a `ErrNotFound`
|
// ErrRemoteCall is returned from `group.Get()` when a remote GetterFunc returns an
|
||||||
// is returned during a remote HTTP instance call
|
// error. When this happens `group.Get()` does not attempt to retrieve the value
|
||||||
|
// via our local GetterFunc.
|
||||||
type ErrRemoteCall struct {
|
type ErrRemoteCall struct {
|
||||||
Msg string
|
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
|
// Get a key that does not exist
|
||||||
err := g.Get(ctx, "IDoNotExist", StringSink(&value))
|
err := g.Get(ctx, "IReturnErrNotFound", StringSink(&value))
|
||||||
errNotFound := &ErrNotFound{}
|
errNotFound := &ErrNotFound{}
|
||||||
if !errors.As(err, &errNotFound) {
|
if !errors.As(err, &errNotFound) {
|
||||||
t.Fatal(errors.New("expected error to be '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
|
// Get a key that is guaranteed to return a remote error.
|
||||||
err = g.Get(ctx, "IAlwaysReturnAnError", StringSink(&value))
|
err = g.Get(ctx, "IReturnErrRemoteCall", StringSink(&value))
|
||||||
errRemoteCall := &ErrRemoteCall{}
|
errRemoteCall := &ErrRemoteCall{}
|
||||||
if !errors.As(err, &errRemoteCall) {
|
if !errors.As(err, &errRemoteCall) {
|
||||||
t.Fatal(errors.New("expected error to be '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)...)
|
p.Set(addrToURL(addrs)...)
|
||||||
|
|
||||||
getter := GetterFunc(func(ctx context.Context, key string, dest Sink) error {
|
getter := GetterFunc(func(ctx context.Context, key string, dest Sink) error {
|
||||||
if key == "IDoNotExist" {
|
if key == "IReturnErrNotFound" {
|
||||||
return &ErrNotFound{Msg: "I do not exist error"}
|
return &ErrNotFound{Msg: "I am a ErrNotFound error"}
|
||||||
}
|
}
|
||||||
|
|
||||||
if key == "IAlwaysReturnAnError" {
|
if key == "IReturnErrRemoteCall" {
|
||||||
return &ErrRemoteCall{Msg: "I am a GetterFunc error"}
|
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 {
|
if _, err := http.Get(*serverAddr); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user