From 8402e6d9d0bcc94fa1831ea10cb3252765497b87 Mon Sep 17 00:00:00 2001 From: Chris McGehee Date: Mon, 26 Apr 2021 21:09:58 -0700 Subject: [PATCH] Fix lint issues: gofumpt linter --- checks/branch_protected_test.go | 564 +++++++++++++++++--------------- e2e/e2e_suite_test.go | 9 +- 2 files changed, 301 insertions(+), 272 deletions(-) diff --git a/checks/branch_protected_test.go b/checks/branch_protected_test.go index f0e4d3a3..f8d57cd5 100644 --- a/checks/branch_protected_test.go +++ b/checks/branch_protected_test.go @@ -46,40 +46,42 @@ func TestIsBranchProtected(t *testing.T) { }{ { name: "Nothing is enabled", - args: args{protection: &github.Protection{ - RequiredStatusChecks: &github.RequiredStatusChecks{ - Strict: false, - Contexts: nil, - }, - RequiredPullRequestReviews: &github.PullRequestReviewsEnforcement{ - DismissalRestrictions: &github.DismissalRestrictions{ + args: args{ + protection: &github.Protection{ + RequiredStatusChecks: &github.RequiredStatusChecks{ + Strict: false, + Contexts: nil, + }, + RequiredPullRequestReviews: &github.PullRequestReviewsEnforcement{ + DismissalRestrictions: &github.DismissalRestrictions{ + Users: nil, + Teams: nil, + }, + DismissStaleReviews: false, + RequireCodeOwnerReviews: false, + RequiredApprovingReviewCount: 0, + }, + EnforceAdmins: &github.AdminEnforcement{ + URL: nil, + Enabled: false, + }, + Restrictions: &github.BranchRestrictions{ Users: nil, Teams: nil, + Apps: nil, + }, + RequireLinearHistory: &github.RequireLinearHistory{ + Enabled: false, + }, + AllowForcePushes: &github.AllowForcePushes{ + Enabled: false, + }, + AllowDeletions: &github.AllowDeletions{ + Enabled: false, }, - DismissStaleReviews: false, - RequireCodeOwnerReviews: false, - RequiredApprovingReviewCount: 0, - }, - EnforceAdmins: &github.AdminEnforcement{ - URL: nil, - Enabled: false, - }, - Restrictions: &github.BranchRestrictions{ - Users: nil, - Teams: nil, - Apps: nil, - }, - RequireLinearHistory: &github.RequireLinearHistory{ - Enabled: false, - }, - AllowForcePushes: &github.AllowForcePushes{ - Enabled: false, - }, - AllowDeletions: &github.AllowDeletions{ - Enabled: false, }, + c: checker.CheckRequest{Logf: l.Logf}, }, - c: checker.CheckRequest{Logf: l.Logf}}, want: checker.CheckResult{ Name: branchProtectionStr, Pass: false, @@ -89,41 +91,44 @@ func TestIsBranchProtected(t *testing.T) { Error: nil, }, }, - {name: "Required status check enabled", - args: args{protection: &github.Protection{ - RequiredStatusChecks: &github.RequiredStatusChecks{ - Strict: true, - Contexts: []string{"foo"}, - }, - RequiredPullRequestReviews: &github.PullRequestReviewsEnforcement{ - DismissalRestrictions: &github.DismissalRestrictions{ + { + name: "Required status check enabled", + args: args{ + protection: &github.Protection{ + RequiredStatusChecks: &github.RequiredStatusChecks{ + Strict: true, + Contexts: []string{"foo"}, + }, + RequiredPullRequestReviews: &github.PullRequestReviewsEnforcement{ + DismissalRestrictions: &github.DismissalRestrictions{ + Users: nil, + Teams: nil, + }, + DismissStaleReviews: false, + RequireCodeOwnerReviews: false, + RequiredApprovingReviewCount: 0, + }, + EnforceAdmins: &github.AdminEnforcement{ + URL: nil, + Enabled: false, + }, + Restrictions: &github.BranchRestrictions{ Users: nil, Teams: nil, + Apps: nil, + }, + RequireLinearHistory: &github.RequireLinearHistory{ + Enabled: false, + }, + AllowForcePushes: &github.AllowForcePushes{ + Enabled: false, + }, + AllowDeletions: &github.AllowDeletions{ + Enabled: false, }, - DismissStaleReviews: false, - RequireCodeOwnerReviews: false, - RequiredApprovingReviewCount: 0, - }, - EnforceAdmins: &github.AdminEnforcement{ - URL: nil, - Enabled: false, - }, - Restrictions: &github.BranchRestrictions{ - Users: nil, - Teams: nil, - Apps: nil, - }, - RequireLinearHistory: &github.RequireLinearHistory{ - Enabled: false, - }, - AllowForcePushes: &github.AllowForcePushes{ - Enabled: false, - }, - AllowDeletions: &github.AllowDeletions{ - Enabled: false, }, + c: checker.CheckRequest{Logf: l.Logf}, }, - c: checker.CheckRequest{Logf: l.Logf}}, want: checker.CheckResult{ Name: branchProtectionStr, Pass: false, @@ -133,41 +138,44 @@ func TestIsBranchProtected(t *testing.T) { Error: nil, }, }, - {name: "Required status check enabled without checking for status string", - args: args{protection: &github.Protection{ - RequiredStatusChecks: &github.RequiredStatusChecks{ - Strict: true, - Contexts: nil, - }, - RequiredPullRequestReviews: &github.PullRequestReviewsEnforcement{ - DismissalRestrictions: &github.DismissalRestrictions{ + { + name: "Required status check enabled without checking for status string", + args: args{ + protection: &github.Protection{ + RequiredStatusChecks: &github.RequiredStatusChecks{ + Strict: true, + Contexts: nil, + }, + RequiredPullRequestReviews: &github.PullRequestReviewsEnforcement{ + DismissalRestrictions: &github.DismissalRestrictions{ + Users: nil, + Teams: nil, + }, + DismissStaleReviews: false, + RequireCodeOwnerReviews: false, + RequiredApprovingReviewCount: 0, + }, + EnforceAdmins: &github.AdminEnforcement{ + URL: nil, + Enabled: false, + }, + Restrictions: &github.BranchRestrictions{ Users: nil, Teams: nil, + Apps: nil, + }, + RequireLinearHistory: &github.RequireLinearHistory{ + Enabled: false, + }, + AllowForcePushes: &github.AllowForcePushes{ + Enabled: false, + }, + AllowDeletions: &github.AllowDeletions{ + Enabled: false, }, - DismissStaleReviews: false, - RequireCodeOwnerReviews: false, - RequiredApprovingReviewCount: 0, - }, - EnforceAdmins: &github.AdminEnforcement{ - URL: nil, - Enabled: false, - }, - Restrictions: &github.BranchRestrictions{ - Users: nil, - Teams: nil, - Apps: nil, - }, - RequireLinearHistory: &github.RequireLinearHistory{ - Enabled: false, - }, - AllowForcePushes: &github.AllowForcePushes{ - Enabled: false, - }, - AllowDeletions: &github.AllowDeletions{ - Enabled: false, }, + c: checker.CheckRequest{Logf: l.Logf}, }, - c: checker.CheckRequest{Logf: l.Logf}}, want: checker.CheckResult{ Name: branchProtectionStr, Pass: false, @@ -178,41 +186,44 @@ func TestIsBranchProtected(t *testing.T) { }, }, - {name: "Required pull request enabled", - args: args{protection: &github.Protection{ - RequiredStatusChecks: &github.RequiredStatusChecks{ - Strict: false, - Contexts: []string{"foo"}, - }, - RequiredPullRequestReviews: &github.PullRequestReviewsEnforcement{ - DismissalRestrictions: &github.DismissalRestrictions{ + { + name: "Required pull request enabled", + args: args{ + protection: &github.Protection{ + RequiredStatusChecks: &github.RequiredStatusChecks{ + Strict: false, + Contexts: []string{"foo"}, + }, + RequiredPullRequestReviews: &github.PullRequestReviewsEnforcement{ + DismissalRestrictions: &github.DismissalRestrictions{ + Users: nil, + Teams: nil, + }, + DismissStaleReviews: false, + RequireCodeOwnerReviews: false, + RequiredApprovingReviewCount: 1, + }, + EnforceAdmins: &github.AdminEnforcement{ + URL: nil, + Enabled: false, + }, + Restrictions: &github.BranchRestrictions{ Users: nil, Teams: nil, + Apps: nil, + }, + RequireLinearHistory: &github.RequireLinearHistory{ + Enabled: false, + }, + AllowForcePushes: &github.AllowForcePushes{ + Enabled: false, + }, + AllowDeletions: &github.AllowDeletions{ + Enabled: false, }, - DismissStaleReviews: false, - RequireCodeOwnerReviews: false, - RequiredApprovingReviewCount: 1, - }, - EnforceAdmins: &github.AdminEnforcement{ - URL: nil, - Enabled: false, - }, - Restrictions: &github.BranchRestrictions{ - Users: nil, - Teams: nil, - Apps: nil, - }, - RequireLinearHistory: &github.RequireLinearHistory{ - Enabled: false, - }, - AllowForcePushes: &github.AllowForcePushes{ - Enabled: false, - }, - AllowDeletions: &github.AllowDeletions{ - Enabled: false, }, + c: checker.CheckRequest{Logf: l.Logf}, }, - c: checker.CheckRequest{Logf: l.Logf}}, want: checker.CheckResult{ Name: branchProtectionStr, Pass: false, @@ -222,41 +233,44 @@ func TestIsBranchProtected(t *testing.T) { Error: nil, }, }, - {name: "Required admin enforcement enabled", - args: args{protection: &github.Protection{ - RequiredStatusChecks: &github.RequiredStatusChecks{ - Strict: false, - Contexts: []string{"foo"}, - }, - RequiredPullRequestReviews: &github.PullRequestReviewsEnforcement{ - DismissalRestrictions: &github.DismissalRestrictions{ + { + name: "Required admin enforcement enabled", + args: args{ + protection: &github.Protection{ + RequiredStatusChecks: &github.RequiredStatusChecks{ + Strict: false, + Contexts: []string{"foo"}, + }, + RequiredPullRequestReviews: &github.PullRequestReviewsEnforcement{ + DismissalRestrictions: &github.DismissalRestrictions{ + Users: nil, + Teams: nil, + }, + DismissStaleReviews: false, + RequireCodeOwnerReviews: false, + RequiredApprovingReviewCount: 0, + }, + EnforceAdmins: &github.AdminEnforcement{ + URL: nil, + Enabled: true, + }, + Restrictions: &github.BranchRestrictions{ Users: nil, Teams: nil, + Apps: nil, + }, + RequireLinearHistory: &github.RequireLinearHistory{ + Enabled: false, + }, + AllowForcePushes: &github.AllowForcePushes{ + Enabled: false, + }, + AllowDeletions: &github.AllowDeletions{ + Enabled: false, }, - DismissStaleReviews: false, - RequireCodeOwnerReviews: false, - RequiredApprovingReviewCount: 0, - }, - EnforceAdmins: &github.AdminEnforcement{ - URL: nil, - Enabled: true, - }, - Restrictions: &github.BranchRestrictions{ - Users: nil, - Teams: nil, - Apps: nil, - }, - RequireLinearHistory: &github.RequireLinearHistory{ - Enabled: false, - }, - AllowForcePushes: &github.AllowForcePushes{ - Enabled: false, - }, - AllowDeletions: &github.AllowDeletions{ - Enabled: false, }, + c: checker.CheckRequest{Logf: l.Logf}, }, - c: checker.CheckRequest{Logf: l.Logf}}, want: checker.CheckResult{ Name: branchProtectionStr, Pass: false, @@ -266,41 +280,44 @@ func TestIsBranchProtected(t *testing.T) { Error: nil, }, }, - {name: "Required linear history enabled", - args: args{protection: &github.Protection{ - RequiredStatusChecks: &github.RequiredStatusChecks{ - Strict: false, - Contexts: []string{"foo"}, - }, - RequiredPullRequestReviews: &github.PullRequestReviewsEnforcement{ - DismissalRestrictions: &github.DismissalRestrictions{ + { + name: "Required linear history enabled", + args: args{ + protection: &github.Protection{ + RequiredStatusChecks: &github.RequiredStatusChecks{ + Strict: false, + Contexts: []string{"foo"}, + }, + RequiredPullRequestReviews: &github.PullRequestReviewsEnforcement{ + DismissalRestrictions: &github.DismissalRestrictions{ + Users: nil, + Teams: nil, + }, + DismissStaleReviews: false, + RequireCodeOwnerReviews: false, + RequiredApprovingReviewCount: 0, + }, + EnforceAdmins: &github.AdminEnforcement{ + URL: nil, + Enabled: false, + }, + Restrictions: &github.BranchRestrictions{ Users: nil, Teams: nil, + Apps: nil, + }, + RequireLinearHistory: &github.RequireLinearHistory{ + Enabled: true, + }, + AllowForcePushes: &github.AllowForcePushes{ + Enabled: false, + }, + AllowDeletions: &github.AllowDeletions{ + Enabled: false, }, - DismissStaleReviews: false, - RequireCodeOwnerReviews: false, - RequiredApprovingReviewCount: 0, - }, - EnforceAdmins: &github.AdminEnforcement{ - URL: nil, - Enabled: false, - }, - Restrictions: &github.BranchRestrictions{ - Users: nil, - Teams: nil, - Apps: nil, - }, - RequireLinearHistory: &github.RequireLinearHistory{ - Enabled: true, - }, - AllowForcePushes: &github.AllowForcePushes{ - Enabled: false, - }, - AllowDeletions: &github.AllowDeletions{ - Enabled: false, }, + c: checker.CheckRequest{Logf: l.Logf}, }, - c: checker.CheckRequest{Logf: l.Logf}}, want: checker.CheckResult{ Name: branchProtectionStr, Pass: false, @@ -310,41 +327,44 @@ func TestIsBranchProtected(t *testing.T) { Error: nil, }, }, - {name: "Allow force push enabled", - args: args{protection: &github.Protection{ - RequiredStatusChecks: &github.RequiredStatusChecks{ - Strict: false, - Contexts: []string{"foo"}, - }, - RequiredPullRequestReviews: &github.PullRequestReviewsEnforcement{ - DismissalRestrictions: &github.DismissalRestrictions{ + { + name: "Allow force push enabled", + args: args{ + protection: &github.Protection{ + RequiredStatusChecks: &github.RequiredStatusChecks{ + Strict: false, + Contexts: []string{"foo"}, + }, + RequiredPullRequestReviews: &github.PullRequestReviewsEnforcement{ + DismissalRestrictions: &github.DismissalRestrictions{ + Users: nil, + Teams: nil, + }, + DismissStaleReviews: false, + RequireCodeOwnerReviews: false, + RequiredApprovingReviewCount: 0, + }, + EnforceAdmins: &github.AdminEnforcement{ + URL: nil, + Enabled: false, + }, + Restrictions: &github.BranchRestrictions{ Users: nil, Teams: nil, + Apps: nil, + }, + RequireLinearHistory: &github.RequireLinearHistory{ + Enabled: false, + }, + AllowForcePushes: &github.AllowForcePushes{ + Enabled: true, + }, + AllowDeletions: &github.AllowDeletions{ + Enabled: false, }, - DismissStaleReviews: false, - RequireCodeOwnerReviews: false, - RequiredApprovingReviewCount: 0, - }, - EnforceAdmins: &github.AdminEnforcement{ - URL: nil, - Enabled: false, - }, - Restrictions: &github.BranchRestrictions{ - Users: nil, - Teams: nil, - Apps: nil, - }, - RequireLinearHistory: &github.RequireLinearHistory{ - Enabled: false, - }, - AllowForcePushes: &github.AllowForcePushes{ - Enabled: true, - }, - AllowDeletions: &github.AllowDeletions{ - Enabled: false, }, + c: checker.CheckRequest{Logf: l.Logf}, }, - c: checker.CheckRequest{Logf: l.Logf}}, want: checker.CheckResult{ Name: branchProtectionStr, Pass: false, @@ -353,41 +373,45 @@ func TestIsBranchProtected(t *testing.T) { ShouldRetry: false, Error: nil, }, - }, {name: "Allow deletions enabled", - args: args{protection: &github.Protection{ - RequiredStatusChecks: &github.RequiredStatusChecks{ - Strict: false, - Contexts: []string{"foo"}, - }, - RequiredPullRequestReviews: &github.PullRequestReviewsEnforcement{ - DismissalRestrictions: &github.DismissalRestrictions{ + }, + { + name: "Allow deletions enabled", + args: args{ + protection: &github.Protection{ + RequiredStatusChecks: &github.RequiredStatusChecks{ + Strict: false, + Contexts: []string{"foo"}, + }, + RequiredPullRequestReviews: &github.PullRequestReviewsEnforcement{ + DismissalRestrictions: &github.DismissalRestrictions{ + Users: nil, + Teams: nil, + }, + DismissStaleReviews: false, + RequireCodeOwnerReviews: false, + RequiredApprovingReviewCount: 0, + }, + EnforceAdmins: &github.AdminEnforcement{ + URL: nil, + Enabled: false, + }, + Restrictions: &github.BranchRestrictions{ Users: nil, Teams: nil, + Apps: nil, + }, + RequireLinearHistory: &github.RequireLinearHistory{ + Enabled: false, + }, + AllowForcePushes: &github.AllowForcePushes{ + Enabled: false, + }, + AllowDeletions: &github.AllowDeletions{ + Enabled: true, }, - DismissStaleReviews: false, - RequireCodeOwnerReviews: false, - RequiredApprovingReviewCount: 0, - }, - EnforceAdmins: &github.AdminEnforcement{ - URL: nil, - Enabled: false, - }, - Restrictions: &github.BranchRestrictions{ - Users: nil, - Teams: nil, - Apps: nil, - }, - RequireLinearHistory: &github.RequireLinearHistory{ - Enabled: false, - }, - AllowForcePushes: &github.AllowForcePushes{ - Enabled: false, - }, - AllowDeletions: &github.AllowDeletions{ - Enabled: true, }, + c: checker.CheckRequest{Logf: l.Logf}, }, - c: checker.CheckRequest{Logf: l.Logf}}, want: checker.CheckResult{ Name: branchProtectionStr, Pass: false, @@ -396,40 +420,44 @@ func TestIsBranchProtected(t *testing.T) { ShouldRetry: false, Error: nil, }, - }, {name: "Branches are protected", - args: args{protection: &github.Protection{ - RequiredStatusChecks: &github.RequiredStatusChecks{ - Strict: true, - Contexts: []string{"foo"}, - }, - RequiredPullRequestReviews: &github.PullRequestReviewsEnforcement{ - DismissalRestrictions: &github.DismissalRestrictions{ + }, + { + name: "Branches are protected", + args: args{ + protection: &github.Protection{ + RequiredStatusChecks: &github.RequiredStatusChecks{ + Strict: true, + Contexts: []string{"foo"}, + }, + RequiredPullRequestReviews: &github.PullRequestReviewsEnforcement{ + DismissalRestrictions: &github.DismissalRestrictions{ + Users: nil, + Teams: nil, + }, + DismissStaleReviews: true, + RequireCodeOwnerReviews: true, + RequiredApprovingReviewCount: 1, + }, + EnforceAdmins: &github.AdminEnforcement{ + Enabled: true, + }, + Restrictions: &github.BranchRestrictions{ Users: nil, Teams: nil, + Apps: nil, + }, + RequireLinearHistory: &github.RequireLinearHistory{ + Enabled: true, + }, + AllowForcePushes: &github.AllowForcePushes{ + Enabled: false, + }, + AllowDeletions: &github.AllowDeletions{ + Enabled: false, }, - DismissStaleReviews: true, - RequireCodeOwnerReviews: true, - RequiredApprovingReviewCount: 1, - }, - EnforceAdmins: &github.AdminEnforcement{ - Enabled: true, - }, - Restrictions: &github.BranchRestrictions{ - Users: nil, - Teams: nil, - Apps: nil, - }, - RequireLinearHistory: &github.RequireLinearHistory{ - Enabled: true, - }, - AllowForcePushes: &github.AllowForcePushes{ - Enabled: false, - }, - AllowDeletions: &github.AllowDeletions{ - Enabled: false, }, + c: checker.CheckRequest{Logf: l.Logf}, }, - c: checker.CheckRequest{Logf: l.Logf}}, want: checker.CheckResult{ Name: branchProtectionStr, Pass: true, diff --git a/e2e/e2e_suite_test.go b/e2e/e2e_suite_test.go index 657092f1..17fd38e0 100644 --- a/e2e/e2e_suite_test.go +++ b/e2e/e2e_suite_test.go @@ -29,9 +29,11 @@ import ( "go.uber.org/zap" ) -var ghClient *github.Client -var graphClient *githubv4.Client -var client *http.Client +var ( + ghClient *github.Client + graphClient *githubv4.Client + client *http.Client +) type log struct { messages []string @@ -76,7 +78,6 @@ var _ = BeforeSuite(func() { ghClient = github.NewClient(client) graphClient = githubv4.NewClient(client) - }) var _ = AfterSuite(func() {