fix artifact count issue (#16851)

The count should filter out the accessory, the result should be consistent with list method.

Fixes #16816

Signed-off-by: Wang Yan <wangyan@vmware.com>
This commit is contained in:
Wang Yan 2022-05-13 11:48:20 +08:00 committed by GitHub
parent ee214f0347
commit 54a857f2aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 3 deletions

View File

@ -239,7 +239,17 @@ func (c *controller) ensureArtifact(ctx context.Context, repository, digest stri
}
func (c *controller) Count(ctx context.Context, query *q.Query) (int64, error) {
return c.artMgr.Count(ctx, query)
if query != nil {
// ignore the page number and size
query = &q.Query{
Keywords: query.Keywords,
}
}
arts, err := c.List(ctx, query, nil)
if err != nil {
return int64(0), err
}
return int64(len(arts)), nil
}
func (c *controller) List(ctx context.Context, query *q.Query, option *Option) ([]*Artifact, error) {

View File

@ -263,10 +263,26 @@ func (c *controllerTestSuite) TestEnsure() {
}
func (c *controllerTestSuite) TestCount() {
c.artMgr.On("Count", mock.Anything, mock.Anything).Return(int64(1), nil)
c.artMgr.On("List", mock.Anything, mock.Anything).Return([]*artifact.Artifact{
{
ID: 1,
RepositoryID: 1,
},
}, nil)
acc := &basemodel.Default{
Data: accessorymodel.AccessoryData{
ID: 1,
ArtifactID: 2,
SubArtifactID: 1,
Type: accessorymodel.TypeCosignSignature,
},
}
c.accMgr.On("List", mock.Anything, mock.Anything).Return([]accessorymodel.Accessory{
acc,
}, nil)
total, err := c.ctl.Count(nil, nil)
c.Require().Nil(err)
c.Equal(int64(1), total)
c.Equal(int64(0), total)
}
func (c *controllerTestSuite) TestList() {