mirror of
https://github.com/goharbor/harbor.git
synced 2024-10-01 06:47:33 +02:00
fix artifact count issue (#16855)
The count should filter out the accessory, the result should be consistent with list method. Signed-off-by: Wang Yan <wangyan@vmware.com>
This commit is contained in:
parent
991a3180f2
commit
2e442bf25a
@ -237,7 +237,17 @@ func (c *controller) ensureArtifact(ctx context.Context, repository, digest stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *controller) Count(ctx context.Context, query *q.Query) (int64, error) {
|
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) {
|
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() {
|
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)
|
total, err := c.ctl.Count(nil, nil)
|
||||||
c.Require().Nil(err)
|
c.Require().Nil(err)
|
||||||
c.Equal(int64(1), total)
|
c.Equal(int64(0), total)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *controllerTestSuite) TestList() {
|
func (c *controllerTestSuite) TestList() {
|
||||||
|
Loading…
Reference in New Issue
Block a user