From ec79354b0577828a54b795e3355e07625f8d745d Mon Sep 17 00:00:00 2001 From: Radovan Zvoncek Date: Tue, 29 Oct 2024 12:30:23 +0200 Subject: [PATCH] Reset FakeMedusaClient state between individual tests --- controllers/medusa/medusabackupjob_controller_test.go | 6 ++++++ controllers/medusa/medusatask_controller_test.go | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/controllers/medusa/medusabackupjob_controller_test.go b/controllers/medusa/medusabackupjob_controller_test.go index 1c3091387..e20ce82f8 100644 --- a/controllers/medusa/medusabackupjob_controller_test.go +++ b/controllers/medusa/medusabackupjob_controller_test.go @@ -357,6 +357,12 @@ type fakeMedusaClient struct { } func newFakeMedusaClient(dcName string) *fakeMedusaClient { + // the fake Medusa client keeps a bit of state in order to simulate different backup statuses + // more precisely, for some backups it will return not a success for some nodes + // we need to reset this state between tests + // doing it here is great since we make a new fake client for each test anyway + alreadyReportedFailingBackup = false + alreadyReportedMissingBackup = false return &fakeMedusaClient{RequestedBackups: make([]string, 0), DcName: dcName} } diff --git a/controllers/medusa/medusatask_controller_test.go b/controllers/medusa/medusatask_controller_test.go index fb87fc5d5..9ef9beadb 100644 --- a/controllers/medusa/medusatask_controller_test.go +++ b/controllers/medusa/medusatask_controller_test.go @@ -155,9 +155,9 @@ func testMedusaTasks(t *testing.T, ctx context.Context, f *framework.Framework, backup4Created := createAndVerifyMedusaBackup(dc2Key, dc2, f, ctx, require, t, namespace, backup4) require.True(backup4Created, "failed to create backup4") backup5Created := createAndVerifyMedusaBackup(dc2Key, dc2, f, ctx, require, t, namespace, backup5) - require.False(backup5Created, "failed to create backup4") + require.False(backup5Created, "failed to create backup5") backup6Created := createAndVerifyMedusaBackup(dc2Key, dc2, f, ctx, require, t, namespace, backup6) - require.False(backup6Created, "failed to create backup4") + require.False(backup6Created, "failed to create backup6") // Ensure that 6 backups jobs, but only 4 backups were created (two jobs did not succeed on some pods) checkBackupsAndJobs(require, ctx, 6, 4, namespace, f, []string{})