From c57f313a8dcbc862314264d3a87cb1c147b36d0d Mon Sep 17 00:00:00 2001 From: Ram Lavi Date: Sun, 12 Jan 2025 13:22:11 +0200 Subject: [PATCH] tools/bumper: Refactor using DeferCleanup Signed-off-by: Ram Lavi --- tools/bumper/cnao_repo_commands_test.go | 24 ++++++------------------ tools/bumper/component_commands_test.go | 12 +++--------- 2 files changed, 9 insertions(+), 27 deletions(-) diff --git a/tools/bumper/cnao_repo_commands_test.go b/tools/bumper/cnao_repo_commands_test.go index 5de473f1b..08217108b 100644 --- a/tools/bumper/cnao_repo_commands_test.go +++ b/tools/bumper/cnao_repo_commands_test.go @@ -55,9 +55,7 @@ var _ = Describe("Testing internal git CNAO Repo", func() { DescribeTable("and checking isPrAlreadyOpened function", func(r isPrAlreadyOpenedParams) { - defer func(path string) { - Expect(os.RemoveAll(path)).To(Succeed()) - }(gitCnaoRepo.gitRepo.localDir) + DeferCleanup(os.RemoveAll, gitCnaoRepo.gitRepo.localDir) gitCnaoRepo.configParams.Url = repoDir gitCnaoRepo.configParams.Branch = r.branch @@ -114,9 +112,7 @@ var _ = Describe("Testing internal git CNAO Repo", func() { } DescribeTable("canonicalizeVersion function", func(v canonicalizeVersionParams) { - defer func(path string) { - Expect(os.RemoveAll(path)).To(Succeed()) - }(gitCnaoRepo.gitRepo.localDir) + DeferCleanup(os.RemoveAll, gitCnaoRepo.gitRepo.localDir) By("Parsing the version string") formattedVersion, err := canonicalizeVersion(v.version) @@ -217,9 +213,7 @@ var _ = Describe("Testing internal git CNAO Repo", func() { dummyPRTitle := "dummy new PR title" DescribeTable("isComponentBumpNeeded function", func(b isComponentBumpNeededParams) { - defer func(path string) { - Expect(os.RemoveAll(path)).To(Succeed()) - }(gitCnaoRepo.gitRepo.localDir) + DeferCleanup(os.RemoveAll, gitCnaoRepo.gitRepo.localDir) gitCnaoRepo.configParams.Url = repoDir By("Checking if bump is needed") @@ -324,9 +318,7 @@ var _ = Describe("Testing internal git CNAO Repo", func() { DescribeTable("resetInAllowedList function", func(r resetInAllowedListParams) { - defer func(path string) { - Expect(os.RemoveAll(path)).To(Succeed()) - }(gitCnaoRepo.gitRepo.localDir) + DeferCleanup(os.RemoveAll, gitCnaoRepo.gitRepo.localDir) worktree, err := gitCnaoRepo.gitRepo.repo.Worktree() By("Modifying files in the Repo") @@ -389,9 +381,7 @@ var _ = Describe("Testing internal git CNAO Repo", func() { DescribeTable("fileInGlobList function", func(r fileInGlobListParams) { - defer func(path string) { - Expect(os.RemoveAll(path)).To(Succeed()) - }(gitCnaoRepo.gitRepo.localDir) + DeferCleanup(os.RemoveAll, gitCnaoRepo.gitRepo.localDir) By("Running fileInGlobList on given input") result := fileInGlobList(r.fileName, r.globList) @@ -431,9 +421,7 @@ var _ = Describe("Testing internal git CNAO Repo", func() { DescribeTable("collectModifiedToTreeList function", func(r collectModifiedToTreeListParams) { - defer func(path string) { - Expect(os.RemoveAll(path)).To(Succeed()) - }(gitCnaoRepo.gitRepo.localDir) + DeferCleanup(os.RemoveAll, gitCnaoRepo.gitRepo.localDir) if len(r.files) != 0 { By("Modifying files in the Repo") diff --git a/tools/bumper/component_commands_test.go b/tools/bumper/component_commands_test.go index 66c0e162a..749926637 100644 --- a/tools/bumper/component_commands_test.go +++ b/tools/bumper/component_commands_test.go @@ -32,9 +32,7 @@ var _ = Describe("Testing internal git component", func() { } DescribeTable("getVirtualTag function", func(r getVirtualTagParams) { - defer func(path string) { - Expect(os.RemoveAll(path)).To(Succeed()) - }(gitComponent.gitRepo.localDir) + DeferCleanup(os.RemoveAll, gitComponent.gitRepo.localDir) By("Running api to get the current virtual tag") commitTested := expectedTagCommitMap[r.TagKey] @@ -72,9 +70,7 @@ var _ = Describe("Testing internal git component", func() { } DescribeTable("getCurrentReleaseTag function", func(r currentReleaseParams) { - defer func(path string) { - Expect(os.RemoveAll(path)).To(Succeed()) - }(gitComponent.gitRepo.localDir) + DeferCleanup(os.RemoveAll, gitComponent.gitRepo.localDir) // update test params since you cant do it in the Entry context gitComponent.configParams.Url = repoDir @@ -132,9 +128,7 @@ var _ = Describe("Testing internal git component", func() { } DescribeTable("getUpdatedReleaseInfo function", func(r updatedReleaseParams) { - defer func(path string) { - Expect(os.RemoveAll(path)).To(Succeed()) - }(gitComponent.gitRepo.localDir) + DeferCleanup(os.RemoveAll, gitComponent.gitRepo.localDir) // update test params since you cant do it in the Entry context gitComponent.configParams = r.comp