Add UT for webhook when replicating with docker registry

Signed-off-by: guanxiatao <guanxiatao@corp.netease.com>
This commit is contained in:
guanxiatao 2020-05-11 14:11:15 +08:00 committed by Ziming
parent bcbab31fe1
commit 0aefd8f2e2

View File

@ -92,7 +92,15 @@ func (f *fakedReplicationMgr) GetExecution(int64) (*daoModels.Execution, error)
func (f *fakedReplicationMgr) ListTasks(...*daoModels.TaskQuery) (int64, []*daoModels.Task, error) {
return 0, nil, nil
}
func (f *fakedReplicationMgr) GetTask(int64) (*daoModels.Task, error) {
func (f *fakedReplicationMgr) GetTask(id int64) (*daoModels.Task, error) {
if id == 1 {
return &daoModels.Task{
ExecutionID: 1,
// project info not included when replicating with docker registry
SrcResource: "alpine:[v1]",
DstResource: "gxt/alpine:[v1] ",
}, nil
}
return &daoModels.Task{
ExecutionID: 1,
SrcResource: "library/alpine:[v1]",
@ -254,14 +262,14 @@ func TestReplicationHandler_Handle(t *testing.T) {
wantErr bool
}{
{
name: "ImagePreprocessHandler Want Error 1",
name: "ReplicationHandler Want Error 1",
args: args{
data: "",
},
wantErr: true,
},
{
name: "ImagePreprocessHandler 1",
name: "ReplicationHandler 1",
args: args{
data: &event.ReplicationEvent{
OccurAt: time.Now(),
@ -269,6 +277,16 @@ func TestReplicationHandler_Handle(t *testing.T) {
},
wantErr: false,
},
{
name: "ReplicationHandler with docker registry",
args: args{
data: &event.ReplicationEvent{
OccurAt: time.Now(),
ReplicationTaskID: 1,
},
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {