Skip to content

Commit

Permalink
tools/bumper: Refactor using DeferCleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Ram Lavi <[email protected]>
  • Loading branch information
RamLavi committed Jan 12, 2025
1 parent c442a5d commit c57f313
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 27 deletions.
24 changes: 6 additions & 18 deletions tools/bumper/cnao_repo_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down
12 changes: 3 additions & 9 deletions tools/bumper/component_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c57f313

Please sign in to comment.