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: gitlab client failing test #3653

Merged
merged 4 commits into from
Aug 9, 2023
Merged

Conversation

ghaiszaher
Copy link
Contributor

@ghaiszaher ghaiszaher commented Aug 6, 2023

@ghaiszaher ghaiszaher marked this pull request as ready for review August 6, 2023 10:55
@ghaiszaher ghaiszaher requested a review from a team as a code owner August 6, 2023 10:55
@github-actions github-actions bot added go Pull requests that update Go code provider/gitlab labels Aug 6, 2023
@ghaiszaher
Copy link
Contributor Author

I think the github workflows need to be revisited, gotest was skipped on the last commit in the mentioned PR:
https://github.com/runatlantis/atlantis/actions/runs/5762924587/job/15623661330
https://github.com/runatlantis/atlantis/actions/runs/5762924585

Comment on lines -326 to +327
defaultMR = 1
noHeadPipelineMR = 2
defaultMr := 1
noHeadPipelineMR := 2
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@marceloboeira apparently that wasn't enough, tests are still failing:

=== RUN   TestGitlabClient_PullIsMergeable/atlantis-test/plan#02
    gitlab_client_test.go:423: got unexpected request at "/api/v4/projects/4580910/repository/commits/sha/statuses"
    gitlab_client_test.go:451: unexpected error: GET http://127.0.0.1:52736/api/v4/projects/4580910/repository/commits/sha/statuses: 404 failed to parse unknown error format: not found
        
    --- FAIL: TestGitlabClient_PullIsMergeable/atlantis-test/plan#02 (1.09s)

Is a case missing in

switch r.RequestURI {
case "/api/v4/":
// Rate limiter requests.
w.WriteHeader(http.StatusOK)
case "/api/v4/projects/runatlantis%2Fatlantis/merge_requests/1":
w.WriteHeader(http.StatusOK)
w.Write([]byte(pipelineSuccess)) // nolint: errcheck
case "/api/v4/projects/runatlantis%2Fatlantis/merge_requests/2":
w.WriteHeader(http.StatusOK)
w.Write([]byte(headPipelineNotAvailable)) // nolint: errcheck
case "/api/v4/projects/4580910":
w.WriteHeader(http.StatusOK)
w.Write([]byte(projectSuccess)) // nolint: errcheck
case "/api/v4/projects/4580910/repository/commits/67cb91d3f6198189f433c045154a885784ba6977/statuses":
w.WriteHeader(http.StatusOK)
response := fmt.Sprintf(`[{"id":133702594,"sha":"67cb91d3f6198189f433c045154a885784ba6977","ref":"patch-1","status":"%s","name":"%s","target_url":null,"description":"ApplySuccess","created_at":"2018-12-12T18:31:57.957Z","started_at":null,"finished_at":"2018-12-12T18:31:58.480Z","allow_failure":false,"coverage":null,"author":{"id":1755902,"username":"lkysow","name":"LukeKysow","state":"active","avatar_url":"https://secure.gravatar.com/avatar/25fd57e71590fe28736624ff24d41c5f?s=80&d=identicon","web_url":"https://gitlab.com/lkysow"}}]`, c.status, c.statusName)
w.Write([]byte(response)) // nolint: errcheck
case "/api/v4/version":
w.WriteHeader(http.StatusOK)
w.Header().Set("Content-Type", "application/json")
type version struct {
Version string
}
v := version{Version: serverVersion}
json.NewEncoder(w).Encode(v)
default:
t.Errorf("got unexpected request at %q", r.RequestURI)
http.Error(w, "not found", http.StatusNotFound)
}
?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ohh 😮‍💨

thanks for bringing this up.

I'm curious how the tests passed din the MR build... let me take a look

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They were skipped 😕 #3653 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you try changing like 448 from "sha" to "67cb91d3f6198189f433c045154a885784ba6977"?

https://github.com/runatlantis/atlantis/pull/3653/files#diff-0cf0d1deb8569e72ff771612d80c7f49b7c947e8d2bf62b50562cf6cae54b493R448

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that's what's causing the problem since the mock is expecting a commit hash instead of "sha" in the URL. Alternatively we could create a mock for "sha" for isolation but I don't see an additional value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@marceloboeira that solves most of the failures, but still some test cases fail with:

    gitlab_client_test.go:452: [true != false]

This test case:

{
fmt.Sprintf("%s/plan", vcsStatusName),
models.SuccessCommitStatus,
gitlabServerVersions,
noHeadPipelineMR,
true,
},

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if we have to revert the MR so we fix the build, I won't have time to look into it, it might be the default to isPipelineSkipped := true is the problem but I will have to open another MR with the fix (and figure out if we can have the CI running the tests or get them working properly locally)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@marceloboeira that is indeed the case. I don't have much experience with Gitlab API so I can't tell what should be the correct behavior here.

Unless you think that the broken test might mean an incorrect behavior, how about removing this test case for now and then later you could look into it?

Copy link
Contributor

Choose a reason for hiding this comment

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

The code definitely fixes the nil pointer (which caused panic) but by fixing it it might have exposed a logic issue. In any case, it is very niche. If you want to remove/comment the test I will open another MR soon to fix it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, if you manage to merge your pull request first, I will close this one.

@ghaiszaher
Copy link
Contributor Author

@GenPage @jamengual could you take a look at this pull request to resolve failing gotest checks in other PRs?

@chenrui333
Copy link
Member

Looks good, thanks @ghaiszaher!

@chenrui333 chenrui333 merged commit 25c6b43 into runatlantis:main Aug 9, 2023
12 checks passed
@ghaiszaher ghaiszaher deleted the fix/vcs-test branch August 9, 2023 17:45
ghaiszaher added a commit to ghaiszaher/atlantis that referenced this pull request Aug 9, 2023
marceloboeira added a commit to marceloboeira/atlantis that referenced this pull request Aug 22, 2023
By fixing nil pointer reference in 3428 we unveiled yet another bug now that the code is able to run further:

When an MR with no HeadPipeline exists its commits are set to skipped by default and thus create some mess when running "PullMergeable" (rendering the MR useless)

The bug was caught by the tests, however, in an attempt to make the build pass and unblock we create a patch to ignore that test.

In order to prevent further problems, this MR:

* Updates the test stack to run all plan/apply commands in the context
  of "HeadLess" Pipelines
* Fixes the default of skipped pipeline to false (as it is better to
  assume it is NOT skipped since that prevents the merge in most cases)
* Make all integratiion tests pass

References:

* Original MR: runatlantis#3428
* Tests Patch MR : runatlantis#3653
marceloboeira added a commit to marceloboeira/atlantis that referenced this pull request Aug 22, 2023
By fixing nil pointer reference in 3428 we unveiled yet another bug now that the code is able to run further:

When an MR with no HeadPipeline exists its commits are set to skipped by default and thus create some mess when running "PullMergeable" (rendering the MR useless)

The bug was caught by the tests, however, in an attempt to make the build pass and unblock we create a patch to ignore that test.

In order to prevent further problems, this MR:

* Updates the test stack to run all plan/apply commands in the context
  of "HeadLess" Pipelines
* Fixes the default of skipped pipeline to false (as it is better to
  assume it is NOT skipped since that prevents the merge in most cases)
* Make all integratiion tests pass

References:

* Original MR: runatlantis#3428
* Tests Patch MR : runatlantis#3653
marceloboeira added a commit to marceloboeira/atlantis that referenced this pull request Aug 23, 2023
By fixing nil pointer reference in 3428 we unveiled yet another bug now that the code is able to run further:

When an MR with no HeadPipeline exists its commits are set to skipped by default and thus create some mess when running "PullMergeable" (rendering the MR useless)

The bug was caught by the tests, however, in an attempt to make the build pass and unblock we create a patch to ignore that test.

In order to prevent further problems, this MR:

* Updates the test stack to run all plan/apply commands in the context
  of "HeadLess" Pipelines
* Fixes the default of skipped pipeline to false (as it is better to
  assume it is NOT skipped since that prevents the merge in most cases)
* Make all integratiion tests pass

References:

* Original MR: runatlantis#3428
* Tests Patch MR : runatlantis#3653
GenPage pushed a commit that referenced this pull request Aug 23, 2023
#3695)

By fixing nil pointer reference in 3428 we unveiled yet another bug now that the code is able to run further:

When an MR with no HeadPipeline exists its commits are set to skipped by default and thus create some mess when running "PullMergeable" (rendering the MR useless)

The bug was caught by the tests, however, in an attempt to make the build pass and unblock we create a patch to ignore that test.

In order to prevent further problems, this MR:

* Updates the test stack to run all plan/apply commands in the context
  of "HeadLess" Pipelines
* Fixes the default of skipped pipeline to false (as it is better to
  assume it is NOT skipped since that prevents the merge in most cases)
* Make all integratiion tests pass

References:

* Original MR: #3428
* Tests Patch MR : #3653
ijames-gc pushed a commit to gocardless/atlantis that referenced this pull request Feb 13, 2024
* fix: gitlab client failing test

* change HeadCommit to `67cb91d3f6198189f433c045154a885784ba6977`

* remove test case for now
ijames-gc pushed a commit to gocardless/atlantis that referenced this pull request Feb 13, 2024
runatlantis#3695)

By fixing nil pointer reference in 3428 we unveiled yet another bug now that the code is able to run further:

When an MR with no HeadPipeline exists its commits are set to skipped by default and thus create some mess when running "PullMergeable" (rendering the MR useless)

The bug was caught by the tests, however, in an attempt to make the build pass and unblock we create a patch to ignore that test.

In order to prevent further problems, this MR:

* Updates the test stack to run all plan/apply commands in the context
  of "HeadLess" Pipelines
* Fixes the default of skipped pipeline to false (as it is better to
  assume it is NOT skipped since that prevents the merge in most cases)
* Make all integratiion tests pass

References:

* Original MR: runatlantis#3428
* Tests Patch MR : runatlantis#3653
ijames-gc pushed a commit to gocardless/atlantis that referenced this pull request Feb 13, 2024
* fix: gitlab client failing test

* change HeadCommit to `67cb91d3f6198189f433c045154a885784ba6977`

* remove test case for now
ijames-gc pushed a commit to gocardless/atlantis that referenced this pull request Feb 13, 2024
runatlantis#3695)

By fixing nil pointer reference in 3428 we unveiled yet another bug now that the code is able to run further:

When an MR with no HeadPipeline exists its commits are set to skipped by default and thus create some mess when running "PullMergeable" (rendering the MR useless)

The bug was caught by the tests, however, in an attempt to make the build pass and unblock we create a patch to ignore that test.

In order to prevent further problems, this MR:

* Updates the test stack to run all plan/apply commands in the context
  of "HeadLess" Pipelines
* Fixes the default of skipped pipeline to false (as it is better to
  assume it is NOT skipped since that prevents the merge in most cases)
* Make all integratiion tests pass

References:

* Original MR: runatlantis#3428
* Tests Patch MR : runatlantis#3653
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go Pull requests that update Go code provider/gitlab
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants