mirror of
https://github.com/goharbor/harbor.git
synced 2024-06-25 22:35:11 +02:00
Merge pull request #11106 from qinshaoxuan/fix_11051
Fix bug when scanner is unhealthy
This commit is contained in:
commit
69fe9e9bf7
|
@ -250,7 +250,7 @@ func (bc *basicController) GetRegistrationByProject(projectID int64, options ...
|
|||
}
|
||||
}
|
||||
|
||||
return registration, err
|
||||
return registration, nil
|
||||
}
|
||||
|
||||
// Ping ...
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
package scanner
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/goharbor/harbor/src/common/models"
|
||||
|
@ -46,8 +47,8 @@ func TestController(t *testing.T) {
|
|||
suite.Run(t, new(ControllerTestSuite))
|
||||
}
|
||||
|
||||
// SetupSuite prepares env for the controller test suite
|
||||
func (suite *ControllerTestSuite) SetupSuite() {
|
||||
// SetupTest prepares env for the controller test suite
|
||||
func (suite *ControllerTestSuite) SetupTest() {
|
||||
suite.mMgr = &scannertesting.Manager{}
|
||||
suite.mMeta = new(MockProMetaManager)
|
||||
|
||||
|
@ -227,6 +228,31 @@ func (suite *ControllerTestSuite) TestGetRegistrationByProject() {
|
|||
assert.Equal(suite.T(), "forUT", r.Name)
|
||||
}
|
||||
|
||||
// TestGetRegistrationByProjectWhenPingError tests GetRegistrationByProject
|
||||
func (suite *ControllerTestSuite) TestGetRegistrationByProjectWhenPingError() {
|
||||
m := make(map[string]string, 1)
|
||||
m[proScannerMetaKey] = "uuid"
|
||||
|
||||
// Configured at project level
|
||||
var pid int64 = 1
|
||||
suite.sample.UUID = "uuid"
|
||||
|
||||
suite.mMeta.On("Get", pid, []string{proScannerMetaKey}).Return(m, nil)
|
||||
suite.mMgr.On("Get", "uuid").Return(suite.sample, nil)
|
||||
|
||||
// Ping error
|
||||
mc := &v1testing.Client{}
|
||||
mc.On("GetMetadata").Return(nil, fmt.Errorf("getMetadata error"))
|
||||
|
||||
mcp := &v1testing.ClientPool{}
|
||||
mocktesting.OnAnything(mcp, "Get").Return(mc, nil)
|
||||
suite.c.clientPool = mcp
|
||||
|
||||
r, err := suite.c.GetRegistrationByProject(pid)
|
||||
require.NoError(suite.T(), err)
|
||||
assert.Equal(suite.T(), "unhealthy", r.Health)
|
||||
}
|
||||
|
||||
// TestPing ...
|
||||
func (suite *ControllerTestSuite) TestPing() {
|
||||
meta, err := suite.c.Ping(suite.sample)
|
||||
|
|
Loading…
Reference in New Issue
Block a user