From f2ca5b4866c9f830b24afec73f9459efe0a53b64 Mon Sep 17 00:00:00 2001 From: Varadarajan Aravamudhan Date: Sun, 8 Jan 2017 14:58:34 +0530 Subject: [PATCH] tests/integration: Update for new branch protection API. This change fixes the build errors due to changes in branch protection API, and allows TestRepositories_EditBranches to pass. Resolves #507. Updates #310. --- tests/integration/repos_test.go | 45 +++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/tests/integration/repos_test.go b/tests/integration/repos_test.go index 628cccf7ada..d12802f304e 100644 --- a/tests/integration/repos_test.go +++ b/tests/integration/repos_test.go @@ -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 { - 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) } _, err = client.Repositories.Delete(*repo.Owner.Login, *repo.Name)