-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Update integration tests for new branch protection API. #509
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -114,30 +114,43 @@ func TestRepositories_EditBranches(t *testing.T) { | |
| t.Fatalf("Repositories.GetBranch() returned error: %v", err) | ||
| } | ||
|
|
||
| if *branch.Protection.Enabled { | ||
| if *branch.Protected { | ||
| t.Fatalf("Branch %v of repo %v is already protected", "master", *repo.Name) | ||
| } | ||
|
|
||
| branch.Protection.Enabled = github.Bool(true) | ||
| branch.Protection.RequiredStatusChecks = &github.RequiredStatusChecks{ | ||
| EnforcementLevel: github.String("everyone"), | ||
| Contexts: &[]string{"continous-integration"}, | ||
| protectionRequest := &github.ProtectionRequest{ | ||
| RequiredStatusChecks: &github.RequiredStatusChecks{ | ||
| IncludeAdmins: true, | ||
| Strict: true, | ||
| Contexts: []string{"continuous-integration"}, | ||
| }, | ||
| RequiredPullRequestReviews: &github.RequiredPullRequestReviews{ | ||
| IncludeAdmins: true, | ||
| }, | ||
| // TODO: Only organization repositories can have users and team restrictions. | ||
| // In order to be able to test these Restrictions, need to add support | ||
| // for creating temporary organization repositories. | ||
| Restrictions: nil, | ||
| } | ||
| branch, _, err = client.Repositories.EditBranch(*repo.Owner.Login, *repo.Name, "master", branch) | ||
|
|
||
| protection, _, err := client.Repositories.UpdateBranchProtection(*repo.Owner.Login, *repo.Name, "master", protectionRequest) | ||
| if err != nil { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the blank line between the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @shurcooL I have removed the line too. |
||
| t.Fatalf("Repositories.EditBranch() returned error: %v", err) | ||
| t.Fatalf("Repositories.UpdateBranchProtection() returned error: %v", err) | ||
| } | ||
|
|
||
| if !*branch.Protection.Enabled { | ||
| t.Fatalf("Branch %v of repo %v should be protected, but is not!", "master", *repo.Name) | ||
| } | ||
| if *branch.Protection.RequiredStatusChecks.EnforcementLevel != "everyone" { | ||
| t.Fatalf("RequiredStatusChecks should be enabled for everyone, set for: %v", *branch.Protection.RequiredStatusChecks.EnforcementLevel) | ||
| want := &github.Protection{ | ||
| RequiredStatusChecks: &github.RequiredStatusChecks{ | ||
| IncludeAdmins: true, | ||
| Strict: true, | ||
| Contexts: []string{"continuous-integration"}, | ||
| }, | ||
| RequiredPullRequestReviews: &github.RequiredPullRequestReviews{ | ||
| IncludeAdmins: true, | ||
| }, | ||
| Restrictions: nil, | ||
| } | ||
|
|
||
| wantedContexts := []string{"continous-integration"} | ||
| if !reflect.DeepEqual(*branch.Protection.RequiredStatusChecks.Contexts, wantedContexts) { | ||
| t.Fatalf("RequiredStatusChecks.Contexts should be: %v but is: %v", wantedContexts, *branch.Protection.RequiredStatusChecks.Contexts) | ||
| if !reflect.DeepEqual(protection, want) { | ||
| t.Errorf("Repositories.UpdateBranchProtection() returned %+v, want %+v", protection, want) | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this actually passing? Just want to confirm.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @shurcooL : The API is failing, Is there a way to check messages within an err? This is the message when I run the code also. Is there something I am missing. The report_test.go file in GitHub folder passes.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can i track this as an issue and work on it?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to https://developer.github.com/v3/#client-errors:
Add some printf statements to see what the errors are in the response. You might want to rebase your changes on top of the latest
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added few printfs and found that the request used by repos_test.go in GitHub folder and one in integration have the same request details. So local calls went fine, but remote call failed. This is the one request from repos_test inside GitHub folder {"required_status_checks":{"include_admins":true,"strict":true,"contexts":["continuous-integration"]},"required_pull_request_reviews":{"include_admins":true},"restrictions":{"users":["u"],"teams":["t"]}} This is the request from repos_test inside integration folder {"required_status_checks":{"include_admins":true,"strict":true,"contexts":["continuous-integration"]},"required_pull_request_reviews":{"include_admins":true},"restrictions":{"users":["nrsingh"],"teams":["nrsinghtest"]}}
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok I think I got it, this is the response I get
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes this is the issue, if the repository is chosen from the organisation, this works. I will make changes and submit. |
||
|
|
||
| _, err = client.Repositories.Delete(*repo.Owner.Login, *repo.Name) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a typo here. It wascontinous-integrationpreviously, but you've changed it tocontinuous-integration(extra u). I don't think that's right.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see this is actually a typo fix. Never mind, keep this as is. Sorry about my mistake.