mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-23 10:45:45 +01:00
update
This commit is contained in:
parent
ffb2f4201b
commit
599d94be0c
@ -19,8 +19,8 @@ import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// DupProjectErr is the error returned when creating a duplicate project
|
||||
var DupProjectErr = errors.New("duplicate project")
|
||||
// ErrDupProject is the error returned when creating a duplicate project
|
||||
var ErrDupProject = errors.New("duplicate project")
|
||||
|
||||
// HTTPError : if response is returned but the status code is not 200, an Error instance will be returned
|
||||
type HTTPError struct {
|
||||
|
@ -130,7 +130,7 @@ func (p *ProjectAPI) Post() {
|
||||
AutomaticallyScanImagesOnPush: pro.AutomaticallyScanImagesOnPush,
|
||||
})
|
||||
if err != nil {
|
||||
if err == errutil.DupProjectErr {
|
||||
if err == errutil.ErrDupProject {
|
||||
log.Debugf("conflict %s", pro.Name)
|
||||
p.RenderError(http.StatusConflict, "")
|
||||
} else {
|
||||
|
@ -118,7 +118,7 @@ func (p *ProjectManager) Create(project *models.Project) (int64, error) {
|
||||
}
|
||||
|
||||
if dup {
|
||||
err = errutil.DupProjectErr
|
||||
err = errutil.ErrDupProject
|
||||
}
|
||||
|
||||
return 0, err
|
||||
|
@ -22,6 +22,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/vmware/harbor/src/common/dao"
|
||||
"github.com/vmware/harbor/src/common/models"
|
||||
errutil "github.com/vmware/harbor/src/common/utils/error"
|
||||
"github.com/vmware/harbor/src/common/utils/log"
|
||||
)
|
||||
|
||||
@ -166,6 +167,19 @@ func TestCreateAndDelete(t *testing.T) {
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
assert.Nil(t, pm.Delete(id))
|
||||
|
||||
// duplicate project name
|
||||
id, err = pm.Create(&models.Project{
|
||||
Name: "test",
|
||||
OwnerName: "admin",
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
defer pm.Delete(id)
|
||||
_, err = pm.Create(&models.Project{
|
||||
Name: "test",
|
||||
OwnerName: "admin",
|
||||
})
|
||||
assert.Equal(t, errutil.ErrDupProject, err)
|
||||
}
|
||||
|
||||
func TestUpdate(t *testing.T) {
|
||||
|
@ -380,7 +380,7 @@ func (p *ProjectManager) Create(pro *models.Project) (int64, error) {
|
||||
}
|
||||
|
||||
if httpErr.StatusCode == http.StatusConflict {
|
||||
return 0, er.DupProjectErr
|
||||
return 0, er.ErrDupProject
|
||||
}
|
||||
|
||||
if httpErr.StatusCode != http.StatusInternalServerError {
|
||||
@ -393,7 +393,7 @@ func (p *ProjectManager) Create(pro *models.Project) (int64, error) {
|
||||
}
|
||||
|
||||
if match {
|
||||
err = er.DupProjectErr
|
||||
err = er.ErrDupProject
|
||||
}
|
||||
|
||||
return 0, err
|
||||
|
@ -22,6 +22,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/vmware/harbor/src/common/models"
|
||||
errutil "github.com/vmware/harbor/src/common/utils/error"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -344,6 +345,12 @@ func TestCreate(t *testing.T) {
|
||||
assert.True(t, project.PreventVulnerableImagesFromRunning)
|
||||
assert.Equal(t, "medium", project.PreventVulnerableImagesFromRunningSeverity)
|
||||
assert.True(t, project.AutomaticallyScanImagesOnPush)
|
||||
|
||||
// duplicate project name
|
||||
_, err = pm.Create(&models.Project{
|
||||
Name: name,
|
||||
})
|
||||
assert.Equal(t, errutil.ErrDupProject, err)
|
||||
}
|
||||
|
||||
func TestDelete(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user