Skip to content

Commit b57ff59

Browse files
committed
test: Replace &x variables with inline Ptr(value) calls
1 parent 946bd71 commit b57ff59

10 files changed

Lines changed: 37 additions & 76 deletions

github/copilot_test.go

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,13 +1332,11 @@ func TestCopilotService_GetEnterpriseMetrics(t *testing.T) {
13321332
t.Errorf("Copilot.GetEnterpriseMetrics returned error: %v", err)
13331333
}
13341334

1335-
totalActiveUsers := 24
1336-
totalEngagedUsers := 20
13371335
want := []*CopilotMetrics{
13381336
{
13391337
Date: "2024-06-24",
1340-
TotalActiveUsers: &totalActiveUsers,
1341-
TotalEngagedUsers: &totalEngagedUsers,
1338+
TotalActiveUsers: Ptr(24),
1339+
TotalEngagedUsers: Ptr(20),
13421340
CopilotIDECodeCompletions: &CopilotIDECodeCompletions{
13431341
TotalEngagedUsers: 20,
13441342
Languages: []*CopilotIDECodeCompletionsLanguage{
@@ -1675,13 +1673,11 @@ func TestCopilotService_GetEnterpriseTeamMetrics(t *testing.T) {
16751673
t.Errorf("Copilot.GetEnterpriseTeamMetrics returned error: %v", err)
16761674
}
16771675

1678-
totalActiveUsers := 24
1679-
totalEngagedUsers := 20
16801676
want := []*CopilotMetrics{
16811677
{
16821678
Date: "2024-06-24",
1683-
TotalActiveUsers: &totalActiveUsers,
1684-
TotalEngagedUsers: &totalEngagedUsers,
1679+
TotalActiveUsers: Ptr(24),
1680+
TotalEngagedUsers: Ptr(20),
16851681
CopilotIDECodeCompletions: &CopilotIDECodeCompletions{
16861682
TotalEngagedUsers: 20,
16871683
Languages: []*CopilotIDECodeCompletionsLanguage{
@@ -2018,13 +2014,11 @@ func TestCopilotService_GetOrganizationMetrics(t *testing.T) {
20182014
t.Errorf("Copilot.GetOrganizationMetrics returned error: %v", err)
20192015
}
20202016

2021-
totalActiveUsers := 24
2022-
totalEngagedUsers := 20
20232017
want := []*CopilotMetrics{
20242018
{
20252019
Date: "2024-06-24",
2026-
TotalActiveUsers: &totalActiveUsers,
2027-
TotalEngagedUsers: &totalEngagedUsers,
2020+
TotalActiveUsers: Ptr(24),
2021+
TotalEngagedUsers: Ptr(20),
20282022
CopilotIDECodeCompletions: &CopilotIDECodeCompletions{
20292023
TotalEngagedUsers: 20,
20302024
Languages: []*CopilotIDECodeCompletionsLanguage{
@@ -2361,13 +2355,11 @@ func TestCopilotService_GetOrganizationTeamMetrics(t *testing.T) {
23612355
t.Errorf("Copilot.GetOrganizationTeamMetrics returned error: %v", err)
23622356
}
23632357

2364-
totalActiveUsers := 24
2365-
totalEngagedUsers := 20
23662358
want := []*CopilotMetrics{
23672359
{
23682360
Date: "2024-06-24",
2369-
TotalActiveUsers: &totalActiveUsers,
2370-
TotalEngagedUsers: &totalEngagedUsers,
2361+
TotalActiveUsers: Ptr(24),
2362+
TotalEngagedUsers: Ptr(20),
23712363
CopilotIDECodeCompletions: &CopilotIDECodeCompletions{
23722364
TotalEngagedUsers: 20,
23732365
Languages: []*CopilotIDECodeCompletionsLanguage{

github/enterprise_licenses_test.go

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,36 +54,28 @@ func TestEnterpriseService_ListConsumedLicenses(t *testing.T) {
5454
t.Errorf("Enterprise.ListConsumedLicenses returned error: %v", err)
5555
}
5656

57-
userName := "User One"
58-
serverUser := false
59-
profile := "https://github.com/user1"
60-
samlNameID := "saml123"
61-
twoFactorAuth := true
62-
licenseStatus := "active"
63-
vsEmail := "user1@example.com"
64-
6557
want := &EnterpriseConsumedLicenses{
6658
TotalSeatsConsumed: 20,
6759
TotalSeatsPurchased: 25,
6860
Users: []*EnterpriseLicensedUsers{
6961
{
7062
GithubComLogin: "user1",
71-
GithubComName: &userName,
63+
GithubComName: Ptr("User One"),
7264
EnterpriseServerUserIDs: []string{"123", "456"},
7365
GithubComUser: true,
74-
EnterpriseServerUser: &serverUser,
66+
EnterpriseServerUser: Ptr(false),
7567
VisualStudioSubscriptionUser: false,
7668
LicenseType: "Enterprise",
77-
GithubComProfile: &profile,
69+
GithubComProfile: Ptr("https://github.com/user1"),
7870
GithubComMemberRoles: []string{"member"},
7971
GithubComEnterpriseRoles: []string{"member"},
8072
GithubComVerifiedDomainEmails: []string{"user1@example.com"},
81-
GithubComSamlNameID: &samlNameID,
73+
GithubComSamlNameID: Ptr("saml123"),
8274
GithubComOrgsWithPendingInvites: []string{},
83-
GithubComTwoFactorAuth: &twoFactorAuth,
75+
GithubComTwoFactorAuth: Ptr(true),
8476
EnterpriseServerEmails: []string{"user1@example.com"},
85-
VisualStudioLicenseStatus: &licenseStatus,
86-
VisualStudioSubscriptionEmail: &vsEmail,
77+
VisualStudioLicenseStatus: Ptr("active"),
78+
VisualStudioSubscriptionEmail: Ptr("user1@example.com"),
8779
TotalUserAccounts: 1,
8880
},
8981
},

github/event_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,15 @@ func TestPayload_Panic(t *testing.T) {
1818
}
1919
}()
2020

21-
name := "UserEvent"
2221
body := json.RawMessage("[") // bogus JSON
23-
e := &Event{Type: &name, RawPayload: &body}
22+
e := &Event{Type: Ptr("UserEvent"), RawPayload: &body}
2423
e.Payload()
2524
}
2625

2726
func TestPayload_NoPanic(t *testing.T) {
2827
t.Parallel()
29-
name := "UserEvent"
3028
body := json.RawMessage("{}")
31-
e := &Event{Type: &name, RawPayload: &body}
29+
e := &Event{Type: Ptr("UserEvent"), RawPayload: &body}
3230
e.Payload()
3331
}
3432

github/git_commits_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,12 @@ func TestGitService_CreateSignedCommit(t *testing.T) {
131131
t.Parallel()
132132
client, mux, _ := setup(t)
133133

134-
signature := "----- BEGIN PGP SIGNATURE -----\n\naaaa\naaaa\n----- END PGP SIGNATURE -----"
135-
136134
input := Commit{
137135
Message: Ptr("Commit Message."),
138136
Tree: &Tree{SHA: Ptr("t")},
139137
Parents: []*Commit{{SHA: Ptr("p")}},
140138
Verification: &SignatureVerification{
141-
Signature: &signature,
139+
Signature: Ptr("----- BEGIN PGP SIGNATURE -----\n\naaaa\naaaa\n----- END PGP SIGNATURE -----"),
142140
},
143141
}
144142

@@ -316,9 +314,8 @@ func TestGitService_createSignatureMessage_nilMessage(t *testing.T) {
316314
func TestGitService_createSignatureMessage_emptyMessage(t *testing.T) {
317315
t.Parallel()
318316
date, _ := time.Parse("Mon Jan 02 15:04:05 2006 -0700", "Thu May 04 00:03:43 2017 +0200")
319-
emptyString := ""
320317
_, err := createSignatureMessage(&createCommit{
321-
Message: &emptyString,
318+
Message: Ptr(""),
322319
Parents: []string{"p"},
323320
Author: &CommitAuthor{
324321
Name: Ptr("go-github"),

github/orgs_immutable_releases_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@ func TestOrganizationsService_GetImmutableReleasesSettings(t *testing.T) {
3131
t.Errorf("Organizations.GetImmutableReleasesSettings returned error: %v", err)
3232
}
3333

34-
wantURL := "https://api.github.com/orgs/o/r"
3534
want := &ImmutableReleaseSettings{
3635
EnforcedRepositories: Ptr("selected"),
37-
SelectedRepositoriesURL: &wantURL,
36+
SelectedRepositoriesURL: Ptr("https://api.github.com/orgs/o/r"),
3837
}
3938

4039
if !cmp.Equal(settings, want) {

github/projects_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -997,11 +997,10 @@ func TestProjectsService_UpdateUserProjectItem_error(t *testing.T) {
997997
testMethod(t, r, "PATCH")
998998
fmt.Fprint(w, `{"id":55}`)
999999
})
1000-
archived := false
10011000
ctx := t.Context()
10021001
const methodName = "UpdateUserProjectItem"
10031002
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
1004-
got, resp, err := client.Projects.UpdateUserProjectItem(ctx, "u", 2, 55, &UpdateProjectItemOptions{Archived: &archived})
1003+
got, resp, err := client.Projects.UpdateUserProjectItem(ctx, "u", 2, 55, &UpdateProjectItemOptions{Archived: Ptr(false)})
10051004
if got != nil {
10061005
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
10071006
}

github/pulls_reviews_test.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -413,19 +413,16 @@ func TestPullRequestsService_CreateReview_badReview(t *testing.T) {
413413

414414
path := "path/to/file.go"
415415
body := "this is a comment body"
416-
right := "RIGHT"
417-
pos1 := 1
418-
line1 := 11
419416
badReview := &PullRequestReviewRequest{
420417
Comments: []*DraftReviewComment{{
421418
Path: &path,
422419
Body: &body,
423-
Side: &right,
424-
Line: &line1,
420+
Side: Ptr("RIGHT"),
421+
Line: Ptr(11),
425422
}, {
426423
Path: &path,
427424
Body: &body,
428-
Position: &pos1,
425+
Position: Ptr(1),
429426
}},
430427
}
431428

github/repos_contents_test.go

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -806,11 +806,9 @@ func TestRepositoriesService_CreateFile(t *testing.T) {
806806
}
807807
}`)
808808
})
809-
message := "m"
810-
content := []byte("c")
811809
repositoryContentsOptions := &RepositoryContentFileOptions{
812-
Message: &message,
813-
Content: content,
810+
Message: Ptr("m"),
811+
Content: []byte("c"),
814812
Committer: &CommitAuthor{Name: Ptr("n"), Email: Ptr("e")},
815813
}
816814
ctx := t.Context()
@@ -860,13 +858,10 @@ func TestRepositoriesService_UpdateFile(t *testing.T) {
860858
}
861859
}`)
862860
})
863-
message := "m"
864-
content := []byte("c")
865-
sha := "f5f369044773ff9c6383c087466d12adb6fa0828"
866861
repositoryContentsOptions := &RepositoryContentFileOptions{
867-
Message: &message,
868-
Content: content,
869-
SHA: &sha,
862+
Message: Ptr("m"),
863+
Content: []byte("c"),
864+
SHA: Ptr("f5f369044773ff9c6383c087466d12adb6fa0828"),
870865
Committer: &CommitAuthor{Name: Ptr("n"), Email: Ptr("e")},
871866
}
872867
ctx := t.Context()
@@ -914,11 +909,9 @@ func TestRepositoriesService_DeleteFile(t *testing.T) {
914909
}
915910
}`)
916911
})
917-
message := "m"
918-
sha := "f5f369044773ff9c6383c087466d12adb6fa0828"
919912
repositoryContentsOptions := &RepositoryContentFileOptions{
920-
Message: &message,
921-
SHA: &sha,
913+
Message: Ptr("m"),
914+
SHA: Ptr("f5f369044773ff9c6383c087466d12adb6fa0828"),
922915
Committer: &CommitAuthor{Name: Ptr("n"), Email: Ptr("e")},
923916
}
924917
ctx := t.Context()

github/repos_releases_test.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -800,9 +800,8 @@ func TestRepositoriesService_UploadReleaseAssetFromRelease(t *testing.T) {
800800
size := int64(len(body))
801801

802802
// Provide a templated upload URL like GitHub returns.
803-
uploadURL := "/repos/o/r/releases/1/assets{?name,label}"
804803
release := &RepositoryRelease{
805-
UploadURL: &uploadURL,
804+
UploadURL: Ptr("/repos/o/r/releases/1/assets{?name,label}"),
806805
}
807806

808807
ctx := t.Context()
@@ -871,8 +870,7 @@ func TestRepositoriesService_UploadReleaseAssetFromRelease_NilReader(t *testing.
871870
t.Parallel()
872871
client, _, _ := setup(t)
873872

874-
uploadURL := "/repos/o/r/releases/1/assets{?name,label}"
875-
release := &RepositoryRelease{UploadURL: &uploadURL}
873+
release := &RepositoryRelease{UploadURL: Ptr("/repos/o/r/releases/1/assets{?name,label}")}
876874

877875
ctx := t.Context()
878876
_, _, err := client.Repositories.UploadReleaseAssetFromRelease(ctx, release, &UploadOptions{Name: "n.txt"}, nil, 12)
@@ -891,8 +889,7 @@ func TestRepositoriesService_UploadReleaseAssetFromRelease_NegativeSize(t *testi
891889
t.Parallel()
892890
client, _, _ := setup(t)
893891

894-
uploadURL := "/repos/o/r/releases/1/assets{?name,label}"
895-
release := &RepositoryRelease{UploadURL: &uploadURL}
892+
release := &RepositoryRelease{UploadURL: Ptr("/repos/o/r/releases/1/assets{?name,label}")}
896893

897894
body := []byte("Upload me !\n")
898895
reader := bytes.NewReader(body)
@@ -919,8 +916,7 @@ func TestRepositoriesService_UploadReleaseAssetFromRelease_NoOpts(t *testing.T)
919916
reader := bytes.NewReader(body)
920917
size := int64(len(body))
921918

922-
uploadURL := "/repos/o/r/releases/1/assets{?name,label}"
923-
release := &RepositoryRelease{UploadURL: &uploadURL}
919+
release := &RepositoryRelease{UploadURL: Ptr("/repos/o/r/releases/1/assets{?name,label}")}
924920

925921
ctx := t.Context()
926922
asset, _, err := client.Repositories.UploadReleaseAssetFromRelease(ctx, release, nil, reader, size)
@@ -957,8 +953,7 @@ func TestRepositoriesService_UploadReleaseAssetFromRelease_WithMediaType(t *test
957953
reader := bytes.NewReader(body)
958954
size := int64(len(body))
959955

960-
uploadURL := "/repos/o/r/releases/1/assets{?name,label}"
961-
release := &RepositoryRelease{UploadURL: &uploadURL}
956+
release := &RepositoryRelease{UploadURL: Ptr("/repos/o/r/releases/1/assets{?name,label}")}
962957

963958
opts := &UploadOptions{Name: "n.txt", MediaType: "image/png"}
964959

github/repos_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,7 @@ func TestRepositoriesService_Edit(t *testing.T) {
499499
t.Parallel()
500500
client, mux, _ := setup(t)
501501

502-
i := true
503-
input := &Repository{HasIssues: &i}
502+
input := &Repository{HasIssues: Ptr(true)}
504503

505504
wantAcceptHeaders := []string{mediaTypeRepositoryTemplatePreview, mediaTypeRepositoryVisibilityPreview}
506505
mux.HandleFunc("/repos/o/r", func(w http.ResponseWriter, r *http.Request) {

0 commit comments

Comments
 (0)