Skip to content

Commit

Permalink
Add Conn Refused Tests (#31)
Browse files Browse the repository at this point in the history
* Add Conn Refused Tests
  • Loading branch information
QuangTung97 committed Oct 10, 2023
1 parent 85678d3 commit 284f092
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions plain_memcache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package memproxy

import (
"context"
"errors"
"net"
"testing"
"time"

Expand Down Expand Up @@ -355,3 +357,31 @@ func TestPlainMemcache__Invalid_Key(t *testing.T) {
assert.Equal(t, memcache.ErrInvalidKeyFormat, err)
assert.Equal(t, LeaseGetResponse{}, resp)
}

func TestPlainMemcache__Connection_Error(t *testing.T) {
client, err := memcache.New("localhost:11200", 1)
if err != nil {
panic(err)
}
t.Cleanup(func() {
_ = client.Close()
})

cache := NewPlainMemcache(client,
WithPlainMemcacheLeaseDuration(7),
WithPlainMemcacheSessionProvider(NewSessionProvider()),
)

pipe := cache.Pipeline(context.Background())
fn := pipe.LeaseGet("KEY01", LeaseGetOptions{})

resp, err := fn.Result()

var netErr *net.OpError
isNetErr := errors.As(err, &netErr)
assert.Equal(t, true, isNetErr)
assert.Equal(t, "dial", netErr.Op)
assert.Equal(t, "tcp", netErr.Net)
assert.Equal(t, "connect: connection refused", netErr.Err.Error())
assert.Equal(t, LeaseGetResponse{}, resp)
}

0 comments on commit 284f092

Please sign in to comment.