mirror of
https://github.com/goharbor/harbor.git
synced 2025-01-26 09:31:24 +01:00
Log ensureArtifact ConflictErr (#19294)
* Log ensureArtifact ConflictErr Signed-off-by: Shuaiyi Liu <liushuaiyi@gmail.com> * Log ensureArtifact ConflictErr Signed-off-by: Shuaiyi Liu <liushuaiyi@gmail.com> --------- Signed-off-by: Shuaiyi Liu <liushuaiyi@gmail.com> Co-authored-by: Wang Yan <wangyan@vmware.com>
This commit is contained in:
parent
fdc012c237
commit
f17d90fadf
@ -227,6 +227,7 @@ func (c *controller) ensureArtifact(ctx context.Context, repository, digest stri
|
||||
if !errors.IsConflictErr(err) {
|
||||
return false, nil, err
|
||||
}
|
||||
log.Debugf("failed to create artifact %s@%s: %v", repository, digest, err)
|
||||
// if got conflict error, try to get the artifact again
|
||||
artifact, err = c.artMgr.GetByDigest(ctx, repository, digest)
|
||||
if err != nil {
|
||||
|
@ -237,6 +237,21 @@ func (c *controllerTestSuite) TestEnsureArtifact() {
|
||||
c.Require().Nil(err)
|
||||
c.True(created)
|
||||
c.Equal(int64(1), art.ID)
|
||||
|
||||
// reset the mock
|
||||
c.SetupTest()
|
||||
|
||||
// the artifact doesn't exist and get a conflict error on creating the artifact and fail to get again
|
||||
c.repoMgr.On("GetByName", mock.Anything, mock.Anything).Return(&repomodel.RepoRecord{
|
||||
ProjectID: 1,
|
||||
}, nil)
|
||||
c.artMgr.On("GetByDigest", mock.Anything, mock.Anything, mock.Anything).Return(nil, errors.NotFoundError(nil))
|
||||
c.artMgr.On("Create", mock.Anything, mock.Anything).Return(int64(1), errors.ConflictError(nil))
|
||||
c.abstractor.On("AbstractMetadata").Return(nil)
|
||||
created, art, err = c.ctl.ensureArtifact(orm.NewContext(nil, &ormtesting.FakeOrmer{}), "library/hello-world", digest)
|
||||
c.Require().Error(err, errors.NotFoundError(nil))
|
||||
c.False(created)
|
||||
c.Require().Nil(art)
|
||||
}
|
||||
|
||||
func (c *controllerTestSuite) TestEnsure() {
|
||||
|
Loading…
Reference in New Issue
Block a user