Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools/bumper: Refactor using DeferCleanup #1978

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 5 additions & 24 deletions tools/bumper/cnao_repo_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ var _ = Describe("Testing internal git CNAO Repo", func() {
githubApi = newFakeGithubApi(repoDir)

gitCnaoRepo = newFakeGitCnaoRepo(githubApi, repoDir, &component{}, expectedTagCommitMap)

DeferCleanup(func() {
Expect(os.RemoveAll(gitCnaoRepo.gitRepo.localDir)).To(Succeed())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need both of them? Isn't the first dir under the 2nd?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I though about keeping them both but maybe it's an overkill.

Expect(os.RemoveAll(tempDir)).To(Succeed())
})
})

Context("Creating fake PRs", func() {
Expand Down Expand Up @@ -55,10 +60,6 @@ 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)

gitCnaoRepo.configParams.Url = repoDir
gitCnaoRepo.configParams.Branch = r.branch

Expand Down Expand Up @@ -114,10 +115,6 @@ 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)

By("Parsing the version string")
formattedVersion, err := canonicalizeVersion(v.version)

Expand Down Expand Up @@ -164,8 +161,6 @@ var _ = Describe("Testing internal git CNAO Repo", func() {
}
DescribeTable("isVtagFormat function",
func(p isVtagFormatParams) {
defer os.RemoveAll(gitCnaoRepo.gitRepo.localDir)

By("Checking if the version string of vtag format")
isVtag := isVtagFormat(p.version)

Expand Down Expand Up @@ -217,9 +212,6 @@ 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)
gitCnaoRepo.configParams.Url = repoDir

By("Checking if bump is needed")
Expand Down Expand Up @@ -324,9 +316,6 @@ 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)
worktree, err := gitCnaoRepo.gitRepo.repo.Worktree()

By("Modifying files in the Repo")
Expand Down Expand Up @@ -389,10 +378,6 @@ 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)

By("Running fileInGlobList on given input")
result := fileInGlobList(r.fileName, r.globList)

Expand Down Expand Up @@ -431,10 +416,6 @@ 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)

if len(r.files) != 0 {
By("Modifying files in the Repo")
modifyFiles(gitCnaoRepo.gitRepo.localDir, r.files)
Expand Down
17 changes: 5 additions & 12 deletions tools/bumper/component_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,18 @@ var _ = Describe("Testing internal git component", func() {
githubApi = newFakeGithubApi(repoDir)

gitComponent = newFakeGitComponent(githubApi, repoDir, &component{}, expectedTagCommitMap)

DeferCleanup(func() {
Expect(os.RemoveAll(gitComponent.gitRepo.localDir)).To(Succeed())
Expect(os.RemoveAll(tempDir)).To(Succeed())
})
})

type getVirtualTagParams struct {
TagKey string
}
DescribeTable("getVirtualTag function",
func(r getVirtualTagParams) {
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]
currentReleaseTag, err := gitComponent.getVirtualTag(commitTested)
Expand Down Expand Up @@ -72,10 +73,6 @@ 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)

// update test params since you cant do it in the Entry context
gitComponent.configParams.Url = repoDir
gitComponent.configParams.Commit = expectedTagCommitMap[r.TagKey]
Expand Down Expand Up @@ -132,10 +129,6 @@ 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)

// update test params since you cant do it in the Entry context
gitComponent.configParams = r.comp
gitComponent.configParams.Url = repoDir
Expand Down
Loading