Skip to content

Commit

Permalink
fix simple response possible NPE
Browse files Browse the repository at this point in the history
Signed-off-by: wayblink <[email protected]>
  • Loading branch information
wayblink committed Jul 22, 2024
1 parent 26dcae4 commit 04006f5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
6 changes: 6 additions & 0 deletions core/backup_meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@ func SimpleListBackupsResponse(input *backuppb.ListBackupsResponse) *backuppb.Li

func SimpleBackupResponse(input *backuppb.BackupInfoResponse) *backuppb.BackupInfoResponse {
backup := input.GetData()
if backup == nil {
return input
}

collections := make([]*backuppb.CollectionBackupInfo, 0)
for _, coll := range backup.GetCollectionBackups() {
Expand All @@ -301,6 +304,9 @@ func SimpleBackupResponse(input *backuppb.BackupInfoResponse) *backuppb.BackupIn

func SimpleRestoreResponse(input *backuppb.RestoreBackupResponse) *backuppb.RestoreBackupResponse {
restore := input.GetData()
if restore == nil {
return input
}

simpleRestore := proto.Clone(restore).(*backuppb.RestoreBackupTask)

Expand Down
28 changes: 28 additions & 0 deletions core/backup_meta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,31 @@ func TestReadBackupFile(t *testing.T) {
fmt.Sprintf(segmentMetaStr)
//log.Info("segment meta", zap.String("value", string(output.SegmentMetaBytes)))
}

func TestSimpleBackupResponse(t *testing.T) {
info := &backuppb.BackupInfoResponse{
RequestId: "abc",
Code: backuppb.ResponseCode_Success,
Msg: "not found",
Data: nil,
}
simpleInfo := SimpleBackupResponse(info)
assert.Nil(t, simpleInfo.Data)
assert.Equal(t, info.Code, simpleInfo.Code)
assert.Equal(t, info.Msg, simpleInfo.Msg)
assert.Equal(t, info.RequestId, simpleInfo.RequestId)
}

func TestSimpleRestoreResponse(t *testing.T) {
info := &backuppb.RestoreBackupResponse{
RequestId: "abc",
Code: backuppb.ResponseCode_Success,
Msg: "not found",
Data: nil,
}
simpleInfo := SimpleRestoreResponse(info)
assert.Nil(t, simpleInfo.Data)
assert.Equal(t, info.Code, simpleInfo.Code)
assert.Equal(t, info.Msg, simpleInfo.Msg)
assert.Equal(t, info.RequestId, simpleInfo.RequestId)
}

0 comments on commit 04006f5

Please sign in to comment.