From 8012fd37aac5fa6d3760cc3cda85880e440c894b Mon Sep 17 00:00:00 2001 From: Ram Lavi Date: Tue, 7 Jan 2025 14:41:24 +0200 Subject: [PATCH] tools/bumper: assert unhandled errors Signed-off-by: Ram Lavi --- tools/bumper/cnao_repo_commands_test.go | 27 ++++++++++++++++++------- tools/bumper/component_commands_test.go | 14 +++++++++---- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/tools/bumper/cnao_repo_commands_test.go b/tools/bumper/cnao_repo_commands_test.go index 066bcb642..5de473f1b 100644 --- a/tools/bumper/cnao_repo_commands_test.go +++ b/tools/bumper/cnao_repo_commands_test.go @@ -24,7 +24,7 @@ var _ = Describe("Testing internal git CNAO Repo", func() { Expect(err).ToNot(HaveOccurred(), "Should create temp dir for CNAO repo") repoDir = filepath.Join(tempDir, "testOwner", "testRepo") - os.MkdirAll(repoDir, 0777) + Expect(os.MkdirAll(repoDir, 0777)).To(Succeed()) githubApi = newFakeGithubApi(repoDir) gitCnaoRepo = newFakeGitCnaoRepo(githubApi, repoDir, &component{}, expectedTagCommitMap) @@ -55,7 +55,10 @@ var _ = Describe("Testing internal git CNAO Repo", func() { DescribeTable("and checking isPrAlreadyOpened function", func(r isPrAlreadyOpenedParams) { - defer os.RemoveAll(gitCnaoRepo.gitRepo.localDir) + defer func(path string) { + Expect(os.RemoveAll(path)).To(Succeed()) + }(gitCnaoRepo.gitRepo.localDir) + gitCnaoRepo.configParams.Url = repoDir gitCnaoRepo.configParams.Branch = r.branch @@ -111,7 +114,9 @@ var _ = Describe("Testing internal git CNAO Repo", func() { } DescribeTable("canonicalizeVersion function", func(v canonicalizeVersionParams) { - defer os.RemoveAll(gitCnaoRepo.gitRepo.localDir) + defer func(path string) { + Expect(os.RemoveAll(path)).To(Succeed()) + }(gitCnaoRepo.gitRepo.localDir) By("Parsing the version string") formattedVersion, err := canonicalizeVersion(v.version) @@ -212,7 +217,9 @@ var _ = Describe("Testing internal git CNAO Repo", func() { dummyPRTitle := "dummy new PR title" DescribeTable("isComponentBumpNeeded function", func(b isComponentBumpNeededParams) { - defer os.RemoveAll(gitCnaoRepo.gitRepo.localDir) + defer func(path string) { + Expect(os.RemoveAll(path)).To(Succeed()) + }(gitCnaoRepo.gitRepo.localDir) gitCnaoRepo.configParams.Url = repoDir By("Checking if bump is needed") @@ -317,7 +324,9 @@ var _ = Describe("Testing internal git CNAO Repo", func() { DescribeTable("resetInAllowedList function", func(r resetInAllowedListParams) { - defer os.RemoveAll(gitCnaoRepo.gitRepo.localDir) + defer func(path string) { + Expect(os.RemoveAll(path)).To(Succeed()) + }(gitCnaoRepo.gitRepo.localDir) worktree, err := gitCnaoRepo.gitRepo.repo.Worktree() By("Modifying files in the Repo") @@ -380,7 +389,9 @@ var _ = Describe("Testing internal git CNAO Repo", func() { DescribeTable("fileInGlobList function", func(r fileInGlobListParams) { - defer os.RemoveAll(gitCnaoRepo.gitRepo.localDir) + defer func(path string) { + Expect(os.RemoveAll(path)).To(Succeed()) + }(gitCnaoRepo.gitRepo.localDir) By("Running fileInGlobList on given input") result := fileInGlobList(r.fileName, r.globList) @@ -420,7 +431,9 @@ var _ = Describe("Testing internal git CNAO Repo", func() { DescribeTable("collectModifiedToTreeList function", func(r collectModifiedToTreeListParams) { - defer os.RemoveAll(gitCnaoRepo.gitRepo.localDir) + defer func(path string) { + Expect(os.RemoveAll(path)).To(Succeed()) + }(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 63b211a60..66c0e162a 100644 --- a/tools/bumper/component_commands_test.go +++ b/tools/bumper/component_commands_test.go @@ -21,7 +21,7 @@ var _ = Describe("Testing internal git component", func() { Expect(err).ToNot(HaveOccurred(), "Should create temp dir for component") repoDir = filepath.Join(tempDir, "testOwner", "testRepo") - os.MkdirAll(repoDir, 0777) + Expect(os.MkdirAll(repoDir, 0777)).To(Succeed()) githubApi = newFakeGithubApi(repoDir) gitComponent = newFakeGitComponent(githubApi, repoDir, &component{}, expectedTagCommitMap) @@ -32,7 +32,9 @@ var _ = Describe("Testing internal git component", func() { } DescribeTable("getVirtualTag function", func(r getVirtualTagParams) { - defer os.RemoveAll(gitComponent.gitRepo.localDir) + defer func(path string) { + Expect(os.RemoveAll(path)).To(Succeed()) + }(gitComponent.gitRepo.localDir) By("Running api to get the current virtual tag") commitTested := expectedTagCommitMap[r.TagKey] @@ -70,7 +72,9 @@ var _ = Describe("Testing internal git component", func() { } DescribeTable("getCurrentReleaseTag function", func(r currentReleaseParams) { - defer os.RemoveAll(gitComponent.gitRepo.localDir) + defer func(path string) { + Expect(os.RemoveAll(path)).To(Succeed()) + }(gitComponent.gitRepo.localDir) // update test params since you cant do it in the Entry context gitComponent.configParams.Url = repoDir @@ -128,7 +132,9 @@ var _ = Describe("Testing internal git component", func() { } DescribeTable("getUpdatedReleaseInfo function", func(r updatedReleaseParams) { - defer os.RemoveAll(gitComponent.gitRepo.localDir) + defer func(path string) { + Expect(os.RemoveAll(path)).To(Succeed()) + }(gitComponent.gitRepo.localDir) // update test params since you cant do it in the Entry context gitComponent.configParams = r.comp