mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-25 18:18:04 +01:00
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:
parent
ee214f0347
commit
54a857f2aa
@ -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) {
|
||||
|
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user