Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
k1LoW committed Jun 13, 2024
1 parent 604b8dc commit 1f7dfdb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
2 changes: 1 addition & 1 deletion rc.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ var defaultHeaderNamesToMask = []string{
type Cacher interface {
// Load loads the request/response cache.
// If the cache is not found, it returns ErrCacheNotFound.
// If not caching, it returns ErrNoCache.
// If the cache is expired, it returns ErrCacheExpired.
// If not caching, it returns ErrShouldNotUseCache.
Load(req *http.Request) (cachedReq *http.Request, cachedRes *http.Response, err error)
// Store stores the response cache.
Store(req *http.Request, res *http.Response, expires time.Time) error
Expand Down
14 changes: 2 additions & 12 deletions testutil/cacher.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package testutil
import (
"crypto/sha1"
"encoding/hex"
"errors"
"io"
"net/http"
"strings"
Expand All @@ -19,12 +18,6 @@ var (
_ Cacher = &GetOnlyCache{}
)

// errCacheNotFound is returned when the cache is not found
var errCacheNotFound error = errors.New("cache not found")

// errNoCache is returned if not caching
var errNoCache error = errors.New("no cache")

type Cacher interface {
Load(req *http.Request) (cachedReq *http.Request, cachedRes *http.Response, err error)
Store(req *http.Request, res *http.Response, expires time.Time) error
Expand Down Expand Up @@ -63,7 +56,7 @@ func (c *AllCache) Load(req *http.Request) (*http.Request, *http.Response, error
cc, ok := c.m[key]
c.mu.Unlock()
if !ok {
return nil, nil, errCacheNotFound
return nil, nil, rc.ErrCacheNotFound
}
cachedReq, cachedRes, err := decodeReqRes(cc)
if err != nil {
Expand Down Expand Up @@ -110,7 +103,7 @@ func (c *GetOnlyCache) Load(req *http.Request) (*http.Request, *http.Response, e
cc, ok := c.m[key]
c.mu.Unlock()
if !ok {
return nil, nil, errCacheNotFound
return nil, nil, rc.ErrCacheNotFound
}
cachedReq, cachedRes, err := decodeReqRes(cc)
if err != nil {
Expand All @@ -123,9 +116,6 @@ func (c *GetOnlyCache) Load(req *http.Request) (*http.Request, *http.Response, e

func (c *GetOnlyCache) Store(req *http.Request, res *http.Response, expires time.Time) error {
c.t.Helper()
if req.Method != http.MethodGet {
return errNoCache
}
key := reqToKey(req)
cc, err := encodeReqRes(req, res)
if err != nil {
Expand Down

0 comments on commit 1f7dfdb

Please sign in to comment.