switch usage directly to errdefs.(ErrAlreadyExists and ErrNotFound)
Signed-off-by: Zou Nengren <zouyee1989@gmail.com>
This commit is contained in:
@@ -24,14 +24,13 @@ import (
|
||||
"github.com/containerd/containerd"
|
||||
"github.com/containerd/containerd/content"
|
||||
"github.com/containerd/containerd/errdefs"
|
||||
"github.com/containerd/containerd/pkg/cri/util"
|
||||
|
||||
imagedigest "github.com/opencontainers/go-digest"
|
||||
"github.com/opencontainers/go-digest/digestset"
|
||||
imageidentity "github.com/opencontainers/image-spec/identity"
|
||||
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
storeutil "github.com/containerd/containerd/pkg/cri/store"
|
||||
"github.com/containerd/containerd/pkg/cri/util"
|
||||
)
|
||||
|
||||
// Image contains all resources associated with the image. All fields
|
||||
@@ -159,7 +158,7 @@ func (s *Store) Resolve(ref string) (string, error) {
|
||||
defer s.lock.RUnlock()
|
||||
id, ok := s.refCache[ref]
|
||||
if !ok {
|
||||
return "", storeutil.ErrNotExist
|
||||
return "", errdefs.ErrNotFound
|
||||
}
|
||||
return id, nil
|
||||
}
|
||||
@@ -222,14 +221,14 @@ func (s *store) get(id string) (Image, error) {
|
||||
digest, err := s.digestSet.Lookup(id)
|
||||
if err != nil {
|
||||
if err == digestset.ErrDigestNotFound {
|
||||
err = storeutil.ErrNotExist
|
||||
err = errdefs.ErrNotFound
|
||||
}
|
||||
return Image{}, err
|
||||
}
|
||||
if i, ok := s.images[digest.String()]; ok {
|
||||
return i, nil
|
||||
}
|
||||
return Image{}, storeutil.ErrNotExist
|
||||
return Image{}, errdefs.ErrNotFound
|
||||
}
|
||||
|
||||
func (s *store) delete(id, ref string) {
|
||||
|
||||
@@ -21,10 +21,10 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/containerd/containerd/errdefs"
|
||||
|
||||
"github.com/opencontainers/go-digest/digestset"
|
||||
assertlib "github.com/stretchr/testify/assert"
|
||||
|
||||
storeutil "github.com/containerd/containerd/pkg/cri/store"
|
||||
)
|
||||
|
||||
func TestInternalStore(t *testing.T) {
|
||||
@@ -128,7 +128,7 @@ func TestInternalStore(t *testing.T) {
|
||||
t.Logf("should be able to delete image")
|
||||
s.delete(truncID, newRef)
|
||||
got, err = s.get(truncID)
|
||||
assert.Equal(storeutil.ErrNotExist, err)
|
||||
assert.Equal(errdefs.ErrNotFound, err)
|
||||
assert.Equal(Image{}, got)
|
||||
|
||||
imageNum--
|
||||
@@ -241,7 +241,7 @@ func TestImageStore(t *testing.T) {
|
||||
if test.image == nil {
|
||||
// Shouldn't be able to index by removed ref.
|
||||
id, err := s.Resolve(test.ref)
|
||||
assert.Equal(storeutil.ErrNotExist, err)
|
||||
assert.Equal(errdefs.ErrNotFound, err)
|
||||
assert.Empty(id)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user