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

fix: Add skip to test if branch do not exists, instead of failing #9204

Closed

Conversation

rishabh625
Copy link
Member

Signed-off-by: rishabh625 rishabhmishra625@gmail.com

Note on DCO:

If the DCO action in the integration test fails, one or more of your commits are not signed off. Please click on the Details link next to the DCO action for instructions on how to resolve this.

Checklist:

  • Either (a) I've created an enhancement proposal and discussed it with the community, (b) this is a bug fix, or (c) this does not need to be in the release notes.
  • The title of the PR states what changed and the related issues number (used for the release note).
  • I've included "Closes [ISSUE #]" or "Fixes [ISSUE #]" in the description to automatically close the associated issue.
  • I've updated both the CLI and UI to expose my feature, or I plan to submit a second PR with them.
  • Does this PR require documentation updates?
  • I've updated documentation as required by this PR.
  • Optional. My organization is added to USERS.md.
  • I have signed off all my commits as required by DCO
  • I have written unit and/or e2e tests for my change. PRs without these are unlikely to be merged.
  • My build is green (troubleshooting builds).

Fixes:- 9203

Signed-off-by: rishabh625 <rishabhmishra625@gmail.com>
@rishabh625 rishabh625 force-pushed the fix-git-test-if-branch-donotexist branch from 61ca0bd to fc2d87f Compare April 25, 2022 12:21
@codecov
Copy link

codecov bot commented Apr 25, 2022

Codecov Report

Merging #9204 (b7f8c2b) into master (fdcaa55) will increase coverage by 0.32%.
The diff coverage is 71.42%.

@@            Coverage Diff             @@
##           master    #9204      +/-   ##
==========================================
+ Coverage   45.49%   45.82%   +0.32%     
==========================================
  Files         219      219              
  Lines       25870    25869       -1     
==========================================
+ Hits        11770    11854      +84     
+ Misses      12462    12371      -91     
- Partials     1638     1644       +6     
Impacted Files Coverage Δ
applicationset/services/scm_provider/gitea.go 78.16% <66.66%> (+1.05%) ⬆️
applicationset/services/scm_provider/utils.go 85.14% <100.00%> (+1.24%) ⬆️
applicationset/services/scm_provider/github.go 75.29% <0.00%> (-5.89%) ⬇️
util/cert/cert.go 82.40% <0.00%> (-2.35%) ⬇️
...is/applicationset/v1alpha1/applicationset_types.go 47.22% <0.00%> (ø)
server/server.go 54.23% <0.00%> (+0.15%) ⬆️
util/gpg/gpg.go 68.20% <0.00%> (+0.20%) ⬆️
util/cmp/stream.go 52.14% <0.00%> (+1.09%) ⬆️
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fdcaa55...b7f8c2b. Read the comment docs.

@leoluz
Copy link
Collaborator

leoluz commented Apr 25, 2022

Hi @rishabh625,
I have a PR unrelated to applicationset failing during unit-test with:

--- FAIL: TestGiteaListRepos (11.79s)
    --- FAIL: TestGiteaListRepos/blank_protocol (11.79s)
        gitea_test.go:59: 
            	Error Trace:	gitea_test.go:59
            	Error:      	Expected nil, but got: &errors.errorString{s:"404 Not Found"}
            	Test:       	TestGiteaListRepos/blank_protocol
        gitea_test.go:69: 
            	Error Trace:	gitea_test.go:69
            	Error:      	Should NOT be empty, but was []
            	Test:       	TestGiteaListRepos/blank_protocol
panic: runtime error: index out of range [0] with length 0 [recovered]
	panic: runtime error: index out of range [0] with length 0

goroutine 183 [running]:
testing.tRunner.func1.2({0x3d8[31](https://github.com/argoproj/argo-cd/runs/6162315396?check_suite_focus=true#step:15:31)80, 0xc0007bae88})
	/opt/hostedtoolcache/go/1.18.1/x64/src/testing/testing.go:1389 +0x[36](https://github.com/argoproj/argo-cd/runs/6162315396?check_suite_focus=true#step:15:36)6
testing.tRunner.func1()
	/opt/hostedtoolcache/go/1.18.1/x64/src/testing/testing.go:1[39](https://github.com/argoproj/argo-cd/runs/6162315396?check_suite_focus=true#step:15:39)2 +0x5d2
panic({0x3d83180, 0xc0007bae88})
	/opt/hostedtoolcache/go/1.18.1/x64/src/runtime/panic.go:844 +0x258
github.com/argoproj/argo-cd/v2/applicationset/services/scm_provider.TestGiteaListRepos.func1(0x0?)
	/home/runner/work/argo-cd/argo-cd/applicationset/services/scm_provider/gitea_test.go:70 +0x925
testing.tRunner(0xc0001ebd[40](https://github.com/argoproj/argo-cd/runs/6162315396?check_suite_focus=true#step:15:40), 0xc0007b5100)
	/opt/hostedtoolcache/go/1.18.1/x64/src/testing/testing.go:1[43](https://github.com/argoproj/argo-cd/runs/6162315396?check_suite_focus=true#step:15:43)9 +0x214
created by testing.(*T).Run

Just wanted to confirm if this PR is addressing this issue??
Tks

@leoluz leoluz self-requested a review April 25, 2022 20:21
Signed-off-by: rishabh625 <rishabhmishra625@gmail.com>
@rishabh625
Copy link
Member Author

Hi @rishabh625, I have a PR unrelated to applicationset failing during unit-test with:

--- FAIL: TestGiteaListRepos (11.79s)
    --- FAIL: TestGiteaListRepos/blank_protocol (11.79s)
        gitea_test.go:59: 
            	Error Trace:	gitea_test.go:59
            	Error:      	Expected nil, but got: &errors.errorString{s:"404 Not Found"}
            	Test:       	TestGiteaListRepos/blank_protocol
        gitea_test.go:69: 
            	Error Trace:	gitea_test.go:69
            	Error:      	Should NOT be empty, but was []
            	Test:       	TestGiteaListRepos/blank_protocol
panic: runtime error: index out of range [0] with length 0 [recovered]
	panic: runtime error: index out of range [0] with length 0

goroutine 183 [running]:
testing.tRunner.func1.2({0x3d8[31](https://github.com/argoproj/argo-cd/runs/6162315396?check_suite_focus=true#step:15:31)80, 0xc0007bae88})
	/opt/hostedtoolcache/go/1.18.1/x64/src/testing/testing.go:1389 +0x[36](https://github.com/argoproj/argo-cd/runs/6162315396?check_suite_focus=true#step:15:36)6
testing.tRunner.func1()
	/opt/hostedtoolcache/go/1.18.1/x64/src/testing/testing.go:1[39](https://github.com/argoproj/argo-cd/runs/6162315396?check_suite_focus=true#step:15:39)2 +0x5d2
panic({0x3d83180, 0xc0007bae88})
	/opt/hostedtoolcache/go/1.18.1/x64/src/runtime/panic.go:844 +0x258
github.com/argoproj/argo-cd/v2/applicationset/services/scm_provider.TestGiteaListRepos.func1(0x0?)
	/home/runner/work/argo-cd/argo-cd/applicationset/services/scm_provider/gitea_test.go:70 +0x925
testing.tRunner(0xc0001ebd[40](https://github.com/argoproj/argo-cd/runs/6162315396?check_suite_focus=true#step:15:40), 0xc0007b5100)
	/opt/hostedtoolcache/go/1.18.1/x64/src/testing/testing.go:1[43](https://github.com/argoproj/argo-cd/runs/6162315396?check_suite_focus=true#step:15:43)9 +0x214
created by testing.(*T).Run

Just wanted to confirm if this PR is addressing this issue?? Tks

Hi @leoluz : yeah this is addressing issue that u mentioned above, wrt gitea failing to list default branch for test-ldap-repos

@rishabh625
Copy link
Member Author

@jannfis @leoluz @crenshaw-dev : can u please review?

Copy link
Member

@crenshaw-dev crenshaw-dev left a comment

Choose a reason for hiding this comment

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

I think adding a unit test for this would make sense.

@@ -126,6 +126,9 @@ func getBranches(ctx context.Context, provider SCMProviderService, repos []*Repo
for _, repo := range repos {
reposFilled, err := provider.GetBranches(ctx, repo)
if err != nil {
if checkBranchDoNotExist(err.Error()) {
Copy link
Member

Choose a reason for hiding this comment

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

Would this hide an error where the repo doesn't exist? Or will it only return true if a branch doesn't exist?

Copy link
Member Author

Choose a reason for hiding this comment

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

It will only skip errors if branch doesn't exist, i'll add a UT for this

Copy link
Member Author

@rishabh625 rishabh625 Apr 26, 2022

Choose a reason for hiding this comment

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

Added Test cases, added with gitea provider only

  1. branch doesn't exist
  2. repo doesn't exist

Signed-off-by: rishabh625 <rishabhmishra625@gmail.com>
Signed-off-by: rishabh625 <rishabhmishra625@gmail.com>
Signed-off-by: rishabh625 <rishabhmishra625@gmail.com>
Comment on lines +130 to +132
if checkBranchDoNotExist(err) {
continue
}
Copy link
Member

Choose a reason for hiding this comment

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

After reviewing the test, I don't think this is the correct fix. We're hitting an error because the gitea API is returning main as the default branch name for this repo. But that repo doesn't have a main branch. It looks like a bug in the gitea API.

In the case of a 404 we could fall back to listing all branches and then picking the 1st one if there's only one. I'll put up another PR based on this one.

@rishabh625
Copy link
Member Author

Closing as fixed in #9228

@rishabh625 rishabh625 closed this Apr 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants