From 526ea5ef0091fdb0e29cd9eb49102e7c07dd2a1e Mon Sep 17 00:00:00 2001 From: R4mbo Date: Tue, 18 Aug 2026 09:55:36 +0530 Subject: [PATCH] assert expected errors from the test case rather than the returned error (#10312) * assert expected errors from the test case rather than the returned error Signed-off-by: samay43 * add changelog entry Signed-off-by: samay43 --------- Signed-off-by: samay43 --- changelogs/unreleased/10312-samay43 | 1 + pkg/util/csi/volume_snapshot_test.go | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 changelogs/unreleased/10312-samay43 diff --git a/changelogs/unreleased/10312-samay43 b/changelogs/unreleased/10312-samay43 new file mode 100644 index 000000000..6b6cb3704 --- /dev/null +++ b/changelogs/unreleased/10312-samay43 @@ -0,0 +1 @@ +Assert expected errors from the test case rather than the returned error in pkg/util/csi tests diff --git a/pkg/util/csi/volume_snapshot_test.go b/pkg/util/csi/volume_snapshot_test.go index d25de47b1..485dd8b37 100644 --- a/pkg/util/csi/volume_snapshot_test.go +++ b/pkg/util/csi/volume_snapshot_test.go @@ -202,7 +202,7 @@ func TestWaitVolumeSnapshotReady(t *testing.T) { fakeClient := snapshotFake.NewSimpleClientset(test.clientObj...) vs, err := WaitVolumeSnapshotReady(t.Context(), fakeClient.SnapshotV1(), test.vsName, test.namespace, time.Millisecond, velerotest.NewLogger()) - if err != nil { + if test.err != "" { require.EqualError(t, err, test.err) } else { require.NoError(t, err) @@ -288,7 +288,7 @@ func TestGetVolumeSnapshotContentForVolumeSnapshot(t *testing.T) { fakeClient := snapshotFake.NewSimpleClientset(test.clientObj...) vs, err := GetVolumeSnapshotContentForVolumeSnapshot(context.TODO(), test.snapshotObj, fakeClient.SnapshotV1()) - if err != nil { + if test.err != "" { require.EqualError(t, err, test.err) } else { require.NoError(t, err) @@ -417,7 +417,7 @@ func TestEnsureDeleteVS(t *testing.T) { } err := EnsureDeleteVS(t.Context(), fakeSnapshotClient.SnapshotV1(), test.vsName, test.namespace, time.Millisecond) - if err != nil { + if test.err != "" { assert.EqualError(t, err, test.err) } else { assert.NoError(t, err)