mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-20 07:37:38 +01:00
fix a sql bug
This commit is contained in:
parent
91ef155da5
commit
973ee40fdf
@ -624,6 +624,19 @@ func TestGetAllProjects(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetPublicProjects(t *testing.T) {
|
||||||
|
projects, err := GetPublicProjects("")
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Error occurred in getProjects: %v", err)
|
||||||
|
}
|
||||||
|
if len(projects) != 1 {
|
||||||
|
t.Errorf("Expected length of projects is 1, but actual: %d, the projects: %+v", len(projects), projects)
|
||||||
|
}
|
||||||
|
if projects[0].Name != "library" {
|
||||||
|
t.Errorf("Expected project name in the list: %s, actual: %s", "library", projects[0].Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestAddProjectMember(t *testing.T) {
|
func TestAddProjectMember(t *testing.T) {
|
||||||
err := AddProjectMember(currentProject.ProjectID, 1, models.DEVELOPER)
|
err := AddProjectMember(currentProject.ProjectID, 1, models.DEVELOPER)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -221,7 +221,6 @@ func GetPublicProjects(projectName string) ([]models.Project, error) {
|
|||||||
publicProjects, err := getProjects(1, projectName)
|
publicProjects, err := getProjects(1, projectName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
||||||
}
|
}
|
||||||
return publicProjects, nil
|
return publicProjects, nil
|
||||||
}
|
}
|
||||||
@ -242,7 +241,7 @@ func getProjects(public int, projectName string) ([]models.Project, error) {
|
|||||||
where deleted = 0`
|
where deleted = 0`
|
||||||
queryParam := make([]interface{}, 1)
|
queryParam := make([]interface{}, 1)
|
||||||
if public == 1 {
|
if public == 1 {
|
||||||
sql += "and public = ?"
|
sql += " and public = ? "
|
||||||
queryParam = append(queryParam, public)
|
queryParam = append(queryParam, public)
|
||||||
}
|
}
|
||||||
if len(projectName) > 0 {
|
if len(projectName) > 0 {
|
||||||
@ -251,6 +250,7 @@ func getProjects(public int, projectName string) ([]models.Project, error) {
|
|||||||
}
|
}
|
||||||
sql += " order by name "
|
sql += " order by name "
|
||||||
var projects []models.Project
|
var projects []models.Project
|
||||||
|
log.Debugf("sql xxx", sql)
|
||||||
if _, err := o.Raw(sql, queryParam).QueryRows(&projects); err != nil {
|
if _, err := o.Raw(sql, queryParam).QueryRows(&projects); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user