Merge pull request #11582 from heww/fix-issue-11564

fix(blob): delete project blob with project_id
This commit is contained in:
Daniel Jiang 2020-04-12 18:00:54 +08:00 committed by GitHub
commit 93f316ccfe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 6 deletions

View File

@ -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

View File

@ -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) {