fix(preheat):fix ctl ut failure case

Signed-off-by: Steven Zou <szou@vmware.com>
This commit is contained in:
Steven Zou 2020-07-20 16:08:58 +08:00
parent 6b9e0e66c4
commit 144edcc0c4
2 changed files with 6 additions and 2 deletions

View File

@ -7,6 +7,8 @@ import (
"net/http/httptest"
"testing"
"github.com/goharbor/harbor/src/lib/q"
"github.com/goharbor/harbor/src/pkg/p2p/preheat/provider/auth"
"github.com/goharbor/harbor/src/core/config"
@ -66,7 +68,9 @@ func (s *preheatSuite) SetupSuite() {
},
}, nil)
s.fakeInstanceMgr.On("Save", mock.Anything, mock.Anything).Return(int64(1), nil)
s.fakeInstanceMgr.On("Count", mock.Anything, &providerModel.Instance{Endpoint: "http://localhost"}).Return(int64(1), nil)
s.fakeInstanceMgr.On("Count", mock.Anything, &q.Query{Keywords: map[string]interface{}{
"endpoint": "http://localhost",
}}).Return(int64(1), nil)
s.fakeInstanceMgr.On("Count", mock.Anything, mock.Anything).Return(int64(0), nil)
s.fakeInstanceMgr.On("Delete", mock.Anything, int64(1)).Return(nil)
s.fakeInstanceMgr.On("Delete", mock.Anything, int64(0)).Return(errors.New("not found"))

View File

@ -603,7 +603,7 @@ func overrideSecuritySettings(p *pol.Schema, pro *models.Project) [][]interface{
case pol.FilterTypeVulnerability:
if v, ok := pro.Metadata[proMetaKeyVulnerability]; ok && v == "true" {
if se, ok := pro.Metadata[proMetaKeySeverity]; ok && len(se) > 0 {
se = strings.ToTitle(strings.ToLower(se))
se = strings.Title(strings.ToLower(se))
code := vuln.Severity(se).Code()
if sev, ok := fl.Value.(int); !ok || (ok && sev < code) {