Skip to content

Commit

Permalink
Address review feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com>
  • Loading branch information
gmlewis committed Oct 4, 2024
1 parent d69e822 commit 25b8aa3
Show file tree
Hide file tree
Showing 26 changed files with 155 additions and 22 deletions.
6 changes: 6 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ linters:
- gosec
- misspell
- nakedret
- paralleltest
- stylecheck
- tparallel
- unconvert
- unparam
- whitespace
Expand Down Expand Up @@ -50,3 +52,7 @@ issues:
- linters: [ gosec ]
text: 'G304: Potential file inclusion via variable'
path: '^(example|tools)\/'

# We don't run parallel integration tests
- linters: [ paralleltest, tparallel ]
path: '^test/integration'
1 change: 1 addition & 0 deletions github/actions_secrets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func TestPublicKey_UnmarshalJSON(t *testing.T) {
for name, tt := range testCases {
tt := tt
t.Run(name, func(t *testing.T) {
t.Parallel()
pk := PublicKey{}
err := json.Unmarshal(tt.data, &pk)
if err == nil && tt.wantErr {
Expand Down
18 changes: 18 additions & 0 deletions github/codespaces_secrets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ func TestCodespacesService_ListSecrets(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)

tt.handleFunc(mux)
Expand Down Expand Up @@ -175,7 +177,9 @@ func TestCodespacesService_GetSecret(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)

tt.handleFunc(mux)
Expand Down Expand Up @@ -273,7 +277,9 @@ func TestCodespacesService_CreateOrUpdateSecret(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)

tt.handleFunc(mux)
Expand Down Expand Up @@ -358,7 +364,9 @@ func TestCodespacesService_DeleteSecret(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)

tt.handleFunc(mux)
Expand Down Expand Up @@ -442,7 +450,9 @@ func TestCodespacesService_GetPublicKey(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)

tt.handleFunc(mux)
Expand Down Expand Up @@ -519,7 +529,9 @@ func TestCodespacesService_ListSelectedReposForSecret(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)

tt.handleFunc(mux)
Expand Down Expand Up @@ -604,7 +616,9 @@ func TestCodespacesService_SetSelectedReposForSecret(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)

tt.handleFunc(mux)
Expand Down Expand Up @@ -670,7 +684,9 @@ func TestCodespacesService_AddSelectedReposForSecret(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)

tt.handleFunc(mux)
Expand Down Expand Up @@ -736,7 +752,9 @@ func TestCodespacesService_RemoveSelectedReposFromSecret(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)

tt.handleFunc(mux)
Expand Down
2 changes: 2 additions & 0 deletions github/copilot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,11 @@ func TestCopilotSeatDetails_UnmarshalJSON(t *testing.T) {
}

for _, tc := range tests {
tc := tc
seatDetails := &CopilotSeatDetails{}

t.Run(tc.name, func(t *testing.T) {
t.Parallel()
err := json.Unmarshal([]byte(tc.data), seatDetails)
if err == nil && tc.wantErr {
t.Errorf("CopilotSeatDetails.UnmarshalJSON returned nil instead of an error")
Expand Down
15 changes: 15 additions & 0 deletions github/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,13 @@ func TestWithAuthToken(t *testing.T) {
}

t.Run("zero-value Client", func(t *testing.T) {
t.Parallel()
c := new(Client).WithAuthToken(token)
validate(t, c.Client(), token)
})

t.Run("NewClient", func(t *testing.T) {
t.Parallel()
httpClient := &http.Client{}
client := NewClient(httpClient).WithAuthToken(token)
validate(t, client.Client(), token)
Expand All @@ -365,6 +367,7 @@ func TestWithAuthToken(t *testing.T) {
})

t.Run("NewTokenClient", func(t *testing.T) {
t.Parallel()
validate(t, NewTokenClient(context.Background(), token).Client(), token)
})
}
Expand Down Expand Up @@ -462,7 +465,9 @@ func TestWithEnterpriseURLs(t *testing.T) {
wantUploadURL: "https://cloud-api.custom-upload-url/api/uploads/",
},
} {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()
validate := func(c *Client, err error) {
t.Helper()
if test.wantErr != "" {
Expand Down Expand Up @@ -1902,7 +1907,9 @@ func TestCompareHttpResponse(t *testing.T) {
}

for name, tc := range testcases {
tc := tc
t.Run(name, func(t *testing.T) {
t.Parallel()
v := compareHTTPResponse(tc.h1, tc.h2)
if tc.expected != v {
t.Errorf("Expected %t, got %t for (%#v, %#v)", tc.expected, v, tc.h1, tc.h2)
Expand Down Expand Up @@ -2059,7 +2066,9 @@ func TestErrorResponse_Is(t *testing.T) {
}

for name, tc := range testcases {
tc := tc
t.Run(name, func(t *testing.T) {
t.Parallel()
if tc.wantSame != err.Is(tc.otherError) {
t.Errorf("Error = %#v, want %#v", err, tc.otherError)
}
Expand Down Expand Up @@ -2127,7 +2136,9 @@ func TestRateLimitError_Is(t *testing.T) {
}

for name, tc := range testcases {
tc := tc
t.Run(name, func(t *testing.T) {
t.Parallel()
if tc.wantSame != tc.err.Is(tc.otherError) {
t.Errorf("Error = %#v, want %#v", tc.err, tc.otherError)
}
Expand Down Expand Up @@ -2212,7 +2223,9 @@ func TestAbuseRateLimitError_Is(t *testing.T) {
}

for name, tc := range testcases {
tc := tc
t.Run(name, func(t *testing.T) {
t.Parallel()
if tc.wantSame != tc.err.Is(tc.otherError) {
t.Errorf("Error = %#v, want %#v", tc.err, tc.otherError)
}
Expand Down Expand Up @@ -2242,7 +2255,9 @@ func TestAcceptedError_Is(t *testing.T) {
}

for name, tc := range testcases {
tc := tc
t.Run(name, func(t *testing.T) {
t.Parallel()
if tc.wantSame != err.Is(tc.otherError) {
t.Errorf("Error = %#v, want %#v", err, tc.otherError)
}
Expand Down
2 changes: 2 additions & 0 deletions github/messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ func TestValidatePayload_BadRequestBody(t *testing.T) {
}

for i, tt := range tests {
tt := tt
t.Run(fmt.Sprintf("test #%v", i), func(t *testing.T) {
t.Parallel()
req := &http.Request{
Header: http.Header{"Content-Type": []string{tt.contentType}},
Body: &badReader{},
Expand Down
2 changes: 2 additions & 0 deletions github/orgs_properties_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,9 @@ func TestCustomPropertyValue_UnmarshalJSON(t *testing.T) {
}

for name, tc := range tests {
tc := tc
t.Run(name, func(t *testing.T) {
t.Parallel()
cpv := &CustomPropertyValue{}
err := cpv.UnmarshalJSON([]byte(tc.data))
if (err != nil) != tc.wantErr {
Expand Down
2 changes: 2 additions & 0 deletions github/pulls_reviews_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,9 @@ func TestPullRequestReviewRequest_isComfortFadePreview(t *testing.T) {
}}

for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
gotBool, gotErr := tc.review.isComfortFadePreview()
if tc.wantErr != nil {
if gotErr != tc.wantErr {
Expand Down
8 changes: 8 additions & 0 deletions github/repos_commits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,9 @@ func TestRepositoriesService_CompareCommits(t *testing.T) {
}

for i, sample := range testCases {
sample := sample
t.Run(fmt.Sprintf("case #%v", i+1), func(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)

base := sample.base
Expand Down Expand Up @@ -520,7 +522,9 @@ func TestRepositoriesService_CompareCommitsRaw_diff(t *testing.T) {
}

for i, sample := range testCases {
sample := sample
t.Run(fmt.Sprintf("case #%v", i+1), func(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)

base := sample.base
Expand Down Expand Up @@ -573,7 +577,9 @@ func TestRepositoriesService_CompareCommitsRaw_patch(t *testing.T) {
}

for i, sample := range testCases {
sample := sample
t.Run(fmt.Sprintf("case #%v", i+1), func(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)

base := sample.base
Expand Down Expand Up @@ -614,7 +620,9 @@ func TestRepositoriesService_CompareCommitsRaw_invalid(t *testing.T) {
}

for i, sample := range testCases {
sample := sample
t.Run(fmt.Sprintf("case #%v", i+1), func(t *testing.T) {
t.Parallel()
client, _, _ := setup(t)
_, _, err := client.Repositories.CompareCommitsRaw(ctx, "o", "r", sample.base, sample.head, RawOptions{100})
if err == nil {
Expand Down
2 changes: 2 additions & 0 deletions github/repos_environments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ func TestRequiredReviewer_UnmarshalJSON(t *testing.T) {
}

for name, test := range testCases {
test := test
t.Run(name, func(t *testing.T) {
t.Parallel()
rule := []*RequiredReviewer{}
err := json.Unmarshal(test.data, &rule)
if err != nil && !test.wantError {
Expand Down
2 changes: 2 additions & 0 deletions github/repos_hooks_deliveries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ var hookDeliveryPayloadTypeToStruct = map[string]interface{}{
func TestHookDelivery_ParsePayload(t *testing.T) {
t.Parallel()
for evt, obj := range hookDeliveryPayloadTypeToStruct {
evt, obj := evt, obj
t.Run(evt, func(t *testing.T) {
t.Parallel()
bs, err := json.Marshal(obj)
if err != nil {
t.Fatal(err)
Expand Down
2 changes: 2 additions & 0 deletions github/repos_rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,11 @@ func TestRepositoryRule_UnmarshalJSON(t *testing.T) {
}

for name, tc := range tests {
tc := tc
rule := &RepositoryRule{}

t.Run(name, func(t *testing.T) {
t.Parallel()
err := rule.UnmarshalJSON([]byte(tc.data))
if err == nil && tc.wantErr {
t.Errorf("RepositoryRule.UnmarshalJSON returned nil instead of an error")
Expand Down
Loading

0 comments on commit 25b8aa3

Please sign in to comment.