add UT for progress message

Signed-off-by: Lyndon-Li <lyonghui@vmware.com>
This commit is contained in:
Lyndon-Li
2026-09-04 16:04:38 +08:00
parent 1048f26c20
commit 5146992b5b
7 changed files with 109 additions and 33 deletions
@@ -787,6 +787,15 @@ func TestOnDataDownloadProgress(t *testing.T) {
BytesDone: bytesDone,
},
},
{
name: "patch in progress phase with negative progress values and message",
dd: dataDownloadBuilder().Result(),
progress: uploader.Progress{
TotalBytes: -1,
BytesDone: -1,
Message: "some warning message",
},
},
{
name: "failed to get datadownload",
dd: dataDownloadBuilder().Result(),
@@ -815,20 +824,28 @@ func TestOnDataDownloadProgress(t *testing.T) {
require.NoError(t, r.client.Create(t.Context(), dd))
// Create a Progress object
progress := &uploader.Progress{
TotalBytes: totalBytes,
BytesDone: bytesDone,
}
progress := &test.progress
// Call the OnDataDownloadProgress function
r.OnDataDownloadProgress(ctx, namespace, duName, progress)
if len(test.needErrs) != 0 && !test.needErrs[0] {
// Get the updated DataDownload object from the fake client
updatedDu := &velerov2alpha1api.DataDownload{}
require.NoError(t, r.client.Get(ctx, types.NamespacedName{Name: duName, Namespace: namespace}, updatedDu))
updatedDd := &velerov2alpha1api.DataDownload{}
require.NoError(t, r.client.Get(ctx, types.NamespacedName{Name: duName, Namespace: namespace}, updatedDd))
// Assert that the DataDownload object has been updated with the progress
assert.Equal(t, test.progress.TotalBytes, updatedDu.Status.Progress.TotalBytes)
assert.Equal(t, test.progress.BytesDone, updatedDu.Status.Progress.BytesDone)
if progress.TotalBytes != -1 {
assert.Equal(t, test.progress.TotalBytes, updatedDd.Status.Progress.TotalBytes)
} else {
assert.Equal(t, int64(0), updatedDd.Status.Progress.TotalBytes) // assuming default or original value
}
if progress.BytesDone != -1 {
assert.Equal(t, test.progress.BytesDone, updatedDd.Status.Progress.BytesDone)
} else {
assert.Equal(t, int64(0), updatedDd.Status.Progress.BytesDone) // assuming default or original value
}
if progress.Message != "" {
assert.Contains(t, updatedDd.Status.Message, progress.Message)
}
}
})
}
+23 -6
View File
@@ -809,6 +809,15 @@ func TestOnDataUploadProgress(t *testing.T) {
BytesDone: bytesDone,
},
},
{
name: "patch in progress phase with negative progress values and message",
du: dataUploadBuilder().Result(),
progress: uploader.Progress{
TotalBytes: -1,
BytesDone: -1,
Message: "some warning message",
},
},
{
name: "failed to get dataupload",
du: dataUploadBuilder().Result(),
@@ -837,10 +846,7 @@ func TestOnDataUploadProgress(t *testing.T) {
require.NoError(t, r.client.Create(t.Context(), du))
// Create a Progress object
progress := &uploader.Progress{
TotalBytes: totalBytes,
BytesDone: bytesDone,
}
progress := &test.progress
// Call the OnDataUploadProgress function
r.OnDataUploadProgress(ctx, namespace, duName, progress)
@@ -849,8 +855,19 @@ func TestOnDataUploadProgress(t *testing.T) {
updatedDu := &velerov2alpha1api.DataUpload{}
require.NoError(t, r.client.Get(ctx, types.NamespacedName{Name: duName, Namespace: namespace}, updatedDu))
// Assert that the DataUpload object has been updated with the progress
assert.Equal(t, test.progress.TotalBytes, updatedDu.Status.Progress.TotalBytes)
assert.Equal(t, test.progress.BytesDone, updatedDu.Status.Progress.BytesDone)
if progress.TotalBytes != -1 {
assert.Equal(t, test.progress.TotalBytes, updatedDu.Status.Progress.TotalBytes)
} else {
assert.Equal(t, int64(0), updatedDu.Status.Progress.TotalBytes) // assuming default or original value
}
if progress.BytesDone != -1 {
assert.Equal(t, test.progress.BytesDone, updatedDu.Status.Progress.BytesDone)
} else {
assert.Equal(t, int64(0), updatedDu.Status.Progress.BytesDone) // assuming default or original value
}
if progress.Message != "" {
assert.Contains(t, updatedDu.Status.Message, progress.Message)
}
}
})
}
@@ -625,6 +625,15 @@ func TestOnPVBProgress(t *testing.T) {
BytesDone: bytesDone,
},
},
{
name: "patch in progress phase with negative progress values and message",
pvb: pvbBuilder().Result(),
progress: uploader.Progress{
TotalBytes: -1,
BytesDone: -1,
Message: "some warning message",
},
},
{
name: "failed to get pvb",
pvb: pvbBuilder().Result(),
@@ -653,17 +662,25 @@ func TestOnPVBProgress(t *testing.T) {
require.NoError(t, r.client.Create(t.Context(), pvb))
// Create a Progress object
progress := &uploader.Progress{
TotalBytes: totalBytes,
BytesDone: bytesDone,
}
progress := &test.progress
r.OnDataPathProgress(ctx, namespace, pvbName, progress)
if len(test.needErrs) != 0 && !test.needErrs[0] {
updatedPvb := &velerov1api.PodVolumeBackup{}
require.NoError(t, r.client.Get(ctx, types.NamespacedName{Name: pvbName, Namespace: namespace}, updatedPvb))
assert.Equal(t, test.progress.TotalBytes, updatedPvb.Status.Progress.TotalBytes)
assert.Equal(t, test.progress.BytesDone, updatedPvb.Status.Progress.BytesDone)
if progress.TotalBytes != -1 {
assert.Equal(t, test.progress.TotalBytes, updatedPvb.Status.Progress.TotalBytes)
} else {
assert.Equal(t, int64(0), updatedPvb.Status.Progress.TotalBytes) // assuming default or original value
}
if progress.BytesDone != -1 {
assert.Equal(t, test.progress.BytesDone, updatedPvb.Status.Progress.BytesDone)
} else {
assert.Equal(t, int64(0), updatedPvb.Status.Progress.BytesDone) // assuming default or original value
}
if progress.Message != "" {
assert.Contains(t, updatedPvb.Status.Message, progress.Message)
}
}
})
}
@@ -1470,6 +1470,15 @@ func TestOnPodVolumeRestoreProgress(t *testing.T) {
BytesDone: bytesDone,
},
},
{
name: "patch in progress phase with negative progress values and message",
pvr: pvrBuilder().Result(),
progress: uploader.Progress{
TotalBytes: -1,
BytesDone: -1,
Message: "some warning message",
},
},
{
name: "failed to get pvr",
pvr: pvrBuilder().Result(),
@@ -1498,17 +1507,25 @@ func TestOnPodVolumeRestoreProgress(t *testing.T) {
require.NoError(t, r.client.Create(t.Context(), pvr))
// Create a Progress object
progress := &uploader.Progress{
TotalBytes: totalBytes,
BytesDone: bytesDone,
}
progress := &test.progress
r.OnDataPathProgress(ctx, namespace, pvrName, progress)
if len(test.needErrs) != 0 && !test.needErrs[0] {
updatedPVR := &velerov1api.PodVolumeRestore{}
require.NoError(t, r.client.Get(ctx, types.NamespacedName{Name: pvrName, Namespace: namespace}, updatedPVR))
assert.Equal(t, test.progress.TotalBytes, updatedPVR.Status.Progress.TotalBytes)
assert.Equal(t, test.progress.BytesDone, updatedPVR.Status.Progress.BytesDone)
if progress.TotalBytes != -1 {
assert.Equal(t, test.progress.TotalBytes, updatedPVR.Status.Progress.TotalBytes)
} else {
assert.Equal(t, int64(0), updatedPVR.Status.Progress.TotalBytes) // assuming default or original value
}
if progress.BytesDone != -1 {
assert.Equal(t, test.progress.BytesDone, updatedPVR.Status.Progress.BytesDone)
} else {
assert.Equal(t, int64(0), updatedPVR.Status.Progress.BytesDone) // assuming default or original value
}
if progress.Message != "" {
assert.Contains(t, updatedPVR.Status.Message, progress.Message)
}
}
})
}