From 1f7dfdbced55d6a557e7d2e9bedad8a3babdd4ed Mon Sep 17 00:00:00 2001 From: k1LoW Date: Thu, 13 Jun 2024 15:31:19 +0900 Subject: [PATCH] Fix test --- rc.go | 2 +- testutil/cacher.go | 14 ++------------ 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/rc.go b/rc.go index d6f08c8..6271729 100644 --- a/rc.go +++ b/rc.go @@ -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 diff --git a/testutil/cacher.go b/testutil/cacher.go index ff684dc..72c7e8c 100644 --- a/testutil/cacher.go +++ b/testutil/cacher.go @@ -3,7 +3,6 @@ package testutil import ( "crypto/sha1" "encoding/hex" - "errors" "io" "net/http" "strings" @@ -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 @@ -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 { @@ -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 { @@ -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 {