mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-17 15:55:26 +01:00
Merge pull request #11582 from heww/fix-issue-11564
fix(blob): delete project blob with project_id
This commit is contained in:
commit
93f316ccfe
@ -309,7 +309,7 @@ func (d *dao) DeleteProjectBlob(ctx context.Context, projectID int64, blobIDs ..
|
|||||||
for _, blobID := range blobIDs {
|
for _, blobID := range blobIDs {
|
||||||
ol.Values = append(ol.Values, blobID)
|
ol.Values = append(ol.Values, blobID)
|
||||||
}
|
}
|
||||||
kw := q.KeyWords{"blob_id": ol}
|
kw := q.KeyWords{"blob_id": ol, "project_id": projectID}
|
||||||
qs, err := orm.QuerySetter(ctx, &models.ProjectBlob{}, q.New(kw))
|
qs, err := orm.QuerySetter(ctx, &models.ProjectBlob{}, q.New(kw))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -267,13 +267,59 @@ func (suite *DaoTestSuite) TestExistProjectBlob() {
|
|||||||
func (suite *DaoTestSuite) TestDeleteProjectBlob() {
|
func (suite *DaoTestSuite) TestDeleteProjectBlob() {
|
||||||
ctx := suite.Context()
|
ctx := suite.Context()
|
||||||
|
|
||||||
projectID := int64(1)
|
digest := suite.DigestString()
|
||||||
blobID := int64(1000)
|
blobID, err := suite.dao.CreateBlob(ctx, &models.Blob{Digest: digest})
|
||||||
|
|
||||||
_, err := suite.dao.CreateProjectBlob(ctx, projectID, blobID)
|
|
||||||
suite.Nil(err)
|
suite.Nil(err)
|
||||||
|
|
||||||
suite.Nil(suite.dao.DeleteProjectBlob(ctx, projectID, blobID))
|
projectID1 := int64(1)
|
||||||
|
projectID2 := int64(2)
|
||||||
|
projectID3 := int64(3)
|
||||||
|
|
||||||
|
_, err = suite.dao.CreateProjectBlob(ctx, projectID1, blobID)
|
||||||
|
suite.Nil(err)
|
||||||
|
|
||||||
|
_, err = suite.dao.CreateProjectBlob(ctx, projectID2, blobID)
|
||||||
|
suite.Nil(err)
|
||||||
|
|
||||||
|
{
|
||||||
|
exist, err := suite.dao.ExistProjectBlob(ctx, projectID1, digest)
|
||||||
|
suite.Nil(err)
|
||||||
|
suite.True(exist)
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
exist, err := suite.dao.ExistProjectBlob(ctx, projectID2, digest)
|
||||||
|
suite.Nil(err)
|
||||||
|
suite.True(exist)
|
||||||
|
}
|
||||||
|
|
||||||
|
suite.Nil(suite.dao.DeleteProjectBlob(ctx, projectID3, blobID))
|
||||||
|
|
||||||
|
{
|
||||||
|
exist, err := suite.dao.ExistProjectBlob(ctx, projectID1, digest)
|
||||||
|
suite.Nil(err)
|
||||||
|
suite.True(exist)
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
exist, err := suite.dao.ExistProjectBlob(ctx, projectID2, digest)
|
||||||
|
suite.Nil(err)
|
||||||
|
suite.True(exist)
|
||||||
|
}
|
||||||
|
|
||||||
|
suite.Nil(suite.dao.DeleteProjectBlob(ctx, projectID1, blobID))
|
||||||
|
|
||||||
|
{
|
||||||
|
exist, err := suite.dao.ExistProjectBlob(ctx, projectID1, digest)
|
||||||
|
suite.Nil(err)
|
||||||
|
suite.False(exist)
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
exist, err := suite.dao.ExistProjectBlob(ctx, projectID2, digest)
|
||||||
|
suite.Nil(err)
|
||||||
|
suite.True(exist)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDaoTestSuite(t *testing.T) {
|
func TestDaoTestSuite(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user