fix(blob): delete project blob with project_id

Closes #11564

Signed-off-by: He Weiwei <hweiwei@vmware.com>
This commit is contained in:
He Weiwei 2020-04-12 04:23:18 +00:00
parent 1a798e833f
commit c585e22d18
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 {
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))
if err != nil {
return err

View File

@ -267,13 +267,59 @@ func (suite *DaoTestSuite) TestExistProjectBlob() {
func (suite *DaoTestSuite) TestDeleteProjectBlob() {
ctx := suite.Context()
projectID := int64(1)
blobID := int64(1000)
_, err := suite.dao.CreateProjectBlob(ctx, projectID, blobID)
digest := suite.DigestString()
blobID, err := suite.dao.CreateBlob(ctx, &models.Blob{Digest: digest})
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) {