| 1 |
package github |
| 2 |
|
| 3 |
import ( |
| 4 |
"context" |
| 5 |
"fmt" |
| 6 |
"net/http" |
| 7 |
"testing" |
| 8 |
|
| 9 |
"github.com/google/go-cmp/cmp" |
| 10 |
) |
| 11 |
|
| 12 |
func TestAdminService_GetAdminStats(t *testing.T) { |
| 13 |
client, mux, _, teardown := setup() |
| 14 |
defer teardown() |
| 15 |
|
| 16 |
mux.HandleFunc("/enterprise/stats/all", func(w http.ResponseWriter, r *http.Request) { |
| 17 |
testMethod(t, r, "GET") |
| 18 |
|
| 19 |
fmt.Fprint(w, ` |
| 20 |
{ |
| 21 |
"repos": { |
| 22 |
"total_repos": 212, |
| 23 |
"root_repos": 194, |
| 24 |
"fork_repos": 18, |
| 25 |
"org_repos": 51, |
| 26 |
"total_pushes": 3082, |
| 27 |
"total_wikis": 15 |
| 28 |
}, |
| 29 |
"hooks": { |
| 30 |
"total_hooks": 27, |
| 31 |
"active_hooks": 23, |
| 32 |
"inactive_hooks": 4 |
| 33 |
}, |
| 34 |
"pages": { |
| 35 |
"total_pages": 36 |
| 36 |
}, |
| 37 |
"orgs": { |
| 38 |
"total_orgs": 33, |
| 39 |
"disabled_orgs": 0, |
| 40 |
"total_teams": 60, |
| 41 |
"total_team_members": 314 |
| 42 |
}, |
| 43 |
"users": { |
| 44 |
"total_users": 254, |
| 45 |
"admin_users": 45, |
| 46 |
"suspended_users": 21 |
| 47 |
}, |
| 48 |
"pulls": { |
| 49 |
"total_pulls": 86, |
| 50 |
"merged_pulls": 60, |
| 51 |
"mergeable_pulls": 21, |
| 52 |
"unmergeable_pulls": 3 |
| 53 |
}, |
| 54 |
"issues": { |
| 55 |
"total_issues": 179, |
| 56 |
"open_issues": 83, |
| 57 |
"closed_issues": 96 |
| 58 |
}, |
| 59 |
"milestones": { |
| 60 |
"total_milestones": 7, |
| 61 |
"open_milestones": 6, |
| 62 |
"closed_milestones": 1 |
| 63 |
}, |
| 64 |
"gists": { |
| 65 |
"total_gists": 178, |
| 66 |
"private_gists": 151, |
| 67 |
"public_gists": 25 |
| 68 |
}, |
| 69 |
"comments": { |
| 70 |
"total_commit_comments": 6, |
| 71 |
"total_gist_comments": 28, |
| 72 |
"total_issue_comments": 366, |
| 73 |
"total_pull_request_comments": 30 |
| 74 |
} |
| 75 |
} |
| 76 |
`) |
| 77 |
}) |
| 78 |
|
| 79 |
ctx := context.Background() |
| 80 |
stats, _, err := client.Admin.GetAdminStats(ctx) |
| 81 |
if err != nil { |
| 82 |
t.Errorf("AdminService.GetAdminStats returned error: %v", err) |
| 83 |
} |
| 84 |
|
| 85 |
if want := testAdminStats; !cmp.Equal(stats, want) { |
| 86 |
t.Errorf("AdminService.GetAdminStats returned %+v, want %+v", stats, want) |
| 87 |
} |
| 88 |
|
| 89 |
const methodName = "GetAdminStats" |
| 90 |
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { |
| 91 |
got, resp, err := client.Admin.GetAdminStats(ctx) |
| 92 |
if got != nil { |
| 93 |
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) |
| 94 |
} |
| 95 |
return resp, err |
| 96 |
}) |
| 97 |
} |
| 98 |
|
| 99 |
func TestAdminService_Stringify(t *testing.T) { |
| 100 |
want := "github.AdminStats{Issues:github.IssueStats{TotalIssues:179, OpenIssues:83, ClosedIssues:96}, Hooks:github.HookStats{TotalHooks:27, ActiveHooks:23, InactiveHooks:4}, Milestones:github.MilestoneStats{TotalMilestones:7, OpenMilestones:6, ClosedMilestones:1}, Orgs:github.OrgStats{TotalOrgs:33, DisabledOrgs:0, TotalTeams:60, TotalTeamMembers:314}, Comments:github.CommentStats{TotalCommitComments:6, TotalGistComments:28, TotalIssueComments:366, TotalPullRequestComments:30}, Pages:github.PageStats{TotalPages:36}, Users:github.UserStats{TotalUsers:254, AdminUsers:45, SuspendedUsers:21}, Gists:github.GistStats{TotalGists:178, PrivateGists:151, PublicGists:25}, Pulls:github.PullStats{TotalPulls:86, MergedPulls:60, MergablePulls:21, UnmergablePulls:3}, Repos:github.RepoStats{TotalRepos:212, RootRepos:194, ForkRepos:18, OrgRepos:51, TotalPushes:3082, TotalWikis:15}}" |
| 101 |
if got := testAdminStats.String(); got != want { |
| 102 |
t.Errorf("testAdminStats.String = %q, want %q", got, want) |
| 103 |
} |
| 104 |
|
| 105 |
want = "github.IssueStats{TotalIssues:179, OpenIssues:83, ClosedIssues:96}" |
| 106 |
if got := testAdminStats.Issues.String(); got != want { |
| 107 |
t.Errorf("testAdminStats.Issues.String = %q, want %q", got, want) |
| 108 |
} |
| 109 |
|
| 110 |
want = "github.HookStats{TotalHooks:27, ActiveHooks:23, InactiveHooks:4}" |
| 111 |
if got := testAdminStats.Hooks.String(); got != want { |
| 112 |
t.Errorf("testAdminStats.Hooks.String = %q, want %q", got, want) |
| 113 |
} |
| 114 |
|
| 115 |
want = "github.MilestoneStats{TotalMilestones:7, OpenMilestones:6, ClosedMilestones:1}" |
| 116 |
if got := testAdminStats.Milestones.String(); got != want { |
| 117 |
t.Errorf("testAdminStats.Milestones.String = %q, want %q", got, want) |
| 118 |
} |
| 119 |
|
| 120 |
want = "github.OrgStats{TotalOrgs:33, DisabledOrgs:0, TotalTeams:60, TotalTeamMembers:314}" |
| 121 |
if got := testAdminStats.Orgs.String(); got != want { |
| 122 |
t.Errorf("testAdminStats.Orgs.String = %q, want %q", got, want) |
| 123 |
} |
| 124 |
|
| 125 |
want = "github.CommentStats{TotalCommitComments:6, TotalGistComments:28, TotalIssueComments:366, TotalPullRequestComments:30}" |
| 126 |
if got := testAdminStats.Comments.String(); got != want { |
| 127 |
t.Errorf("testAdminStats.Comments.String = %q, want %q", got, want) |
| 128 |
} |
| 129 |
|
| 130 |
want = "github.PageStats{TotalPages:36}" |
| 131 |
if got := testAdminStats.Pages.String(); got != want { |
| 132 |
t.Errorf("testAdminStats.Pages.String = %q, want %q", got, want) |
| 133 |
} |
| 134 |
|
| 135 |
want = "github.UserStats{TotalUsers:254, AdminUsers:45, SuspendedUsers:21}" |
| 136 |
if got := testAdminStats.Users.String(); got != want { |
| 137 |
t.Errorf("testAdminStats.Users.String = %q, want %q", got, want) |
| 138 |
} |
| 139 |
|
| 140 |
want = "github.GistStats{TotalGists:178, PrivateGists:151, PublicGists:25}" |
| 141 |
if got := testAdminStats.Gists.String(); got != want { |
| 142 |
t.Errorf("testAdminStats.Gists.String = %q, want %q", got, want) |
| 143 |
} |
| 144 |
|
| 145 |
want = "github.PullStats{TotalPulls:86, MergedPulls:60, MergablePulls:21, UnmergablePulls:3}" |
| 146 |
if got := testAdminStats.Pulls.String(); got != want { |
| 147 |
t.Errorf("testAdminStats.Pulls.String = %q, want %q", got, want) |
| 148 |
} |
| 149 |
|
| 150 |
want = "github.RepoStats{TotalRepos:212, RootRepos:194, ForkRepos:18, OrgRepos:51, TotalPushes:3082, TotalWikis:15}" |
| 151 |
if got := testAdminStats.Repos.String(); got != want { |
| 152 |
t.Errorf("testAdminStats.Repos.String = %q, want %q", got, want) |
| 153 |
} |
| 154 |
} |
| 155 |
|
| 156 |
var testAdminStats = &AdminStats{ |
| 157 |
Repos: &RepoStats{ |
| 158 |
TotalRepos: Int(212), |
| 159 |
RootRepos: Int(194), |
| 160 |
ForkRepos: Int(18), |
| 161 |
OrgRepos: Int(51), |
| 162 |
TotalPushes: Int(3082), |
| 163 |
TotalWikis: Int(15), |
| 164 |
}, |
| 165 |
Hooks: &HookStats{ |
| 166 |
TotalHooks: Int(27), |
| 167 |
ActiveHooks: Int(23), |
| 168 |
InactiveHooks: Int(4), |
| 169 |
}, |
| 170 |
Pages: &PageStats{ |
| 171 |
TotalPages: Int(36), |
| 172 |
}, |
| 173 |
Orgs: &OrgStats{ |
| 174 |
TotalOrgs: Int(33), |
| 175 |
DisabledOrgs: Int(0), |
| 176 |
TotalTeams: Int(60), |
| 177 |
TotalTeamMembers: Int(314), |
| 178 |
}, |
| 179 |
Users: &UserStats{ |
| 180 |
TotalUsers: Int(254), |
| 181 |
AdminUsers: Int(45), |
| 182 |
SuspendedUsers: Int(21), |
| 183 |
}, |
| 184 |
Pulls: &PullStats{ |
| 185 |
TotalPulls: Int(86), |
| 186 |
MergedPulls: Int(60), |
| 187 |
MergablePulls: Int(21), |
| 188 |
UnmergablePulls: Int(3), |
| 189 |
}, |
| 190 |
Issues: &IssueStats{ |
| 191 |
TotalIssues: Int(179), |
| 192 |
OpenIssues: Int(83), |
| 193 |
ClosedIssues: Int(96), |
| 194 |
}, |
| 195 |
Milestones: &MilestoneStats{ |
| 196 |
TotalMilestones: Int(7), |
| 197 |
OpenMilestones: Int(6), |
| 198 |
ClosedMilestones: Int(1), |
| 199 |
}, |
| 200 |
Gists: &GistStats{ |
| 201 |
TotalGists: Int(178), |
| 202 |
PrivateGists: Int(151), |
| 203 |
PublicGists: Int(25), |
| 204 |
}, |
| 205 |
Comments: &CommentStats{ |
| 206 |
TotalCommitComments: Int(6), |
| 207 |
TotalGistComments: Int(28), |
| 208 |
TotalIssueComments: Int(366), |
| 209 |
TotalPullRequestComments: Int(30), |
| 210 |
}, |
| 211 |
} |
| 212 |
|
| 213 |
func TestIssueStats_Marshal(t *testing.T) { |
| 214 |
testJSONMarshal(t, &IssueStats{}, "{}") |
| 215 |
|
| 216 |
u := &IssueStats{ |
| 217 |
TotalIssues: Int(1), |
| 218 |
OpenIssues: Int(1), |
| 219 |
ClosedIssues: Int(1), |
| 220 |
} |
| 221 |
|
| 222 |
want := `{ |
| 223 |
"total_issues": 1, |
| 224 |
"open_issues": 1, |
| 225 |
"closed_issues": 1 |
| 226 |
}` |
| 227 |
|
| 228 |
testJSONMarshal(t, u, want) |
| 229 |
} |
| 230 |
|
| 231 |
func TestHookStats_Marshal(t *testing.T) { |
| 232 |
testJSONMarshal(t, &HookStats{}, "{}") |
| 233 |
|
| 234 |
u := &HookStats{ |
| 235 |
TotalHooks: Int(1), |
| 236 |
ActiveHooks: Int(1), |
| 237 |
InactiveHooks: Int(1), |
| 238 |
} |
| 239 |
|
| 240 |
want := `{ |
| 241 |
"total_hooks": 1, |
| 242 |
"active_hooks": 1, |
| 243 |
"inactive_hooks": 1 |
| 244 |
}` |
| 245 |
|
| 246 |
testJSONMarshal(t, u, want) |
| 247 |
} |
| 248 |
|
| 249 |
func TestMilestoneStats_Marshal(t *testing.T) { |
| 250 |
testJSONMarshal(t, &MilestoneStats{}, "{}") |
| 251 |
|
| 252 |
u := &MilestoneStats{ |
| 253 |
TotalMilestones: Int(1), |
| 254 |
OpenMilestones: Int(1), |
| 255 |
ClosedMilestones: Int(1), |
| 256 |
} |
| 257 |
|
| 258 |
want := `{ |
| 259 |
"total_milestones": 1, |
| 260 |
"open_milestones": 1, |
| 261 |
"closed_milestones": 1 |
| 262 |
}` |
| 263 |
|
| 264 |
testJSONMarshal(t, u, want) |
| 265 |
} |
| 266 |
|
| 267 |
func TestOrgStats_Marshal(t *testing.T) { |
| 268 |
testJSONMarshal(t, &OrgStats{}, "{}") |
| 269 |
|
| 270 |
u := &OrgStats{ |
| 271 |
TotalOrgs: Int(1), |
| 272 |
DisabledOrgs: Int(1), |
| 273 |
TotalTeams: Int(1), |
| 274 |
TotalTeamMembers: Int(1), |
| 275 |
} |
| 276 |
|
| 277 |
want := `{ |
| 278 |
"total_orgs": 1, |
| 279 |
"disabled_orgs": 1, |
| 280 |
"total_teams": 1, |
| 281 |
"total_team_members": 1 |
| 282 |
}` |
| 283 |
|
| 284 |
testJSONMarshal(t, u, want) |
| 285 |
} |
| 286 |
|
| 287 |
func TestCommentStats_Marshal(t *testing.T) { |
| 288 |
testJSONMarshal(t, &CommentStats{}, "{}") |
| 289 |
|
| 290 |
u := &CommentStats{ |
| 291 |
TotalCommitComments: Int(1), |
| 292 |
TotalGistComments: Int(1), |
| 293 |
TotalIssueComments: Int(1), |
| 294 |
TotalPullRequestComments: Int(1), |
| 295 |
} |
| 296 |
|
| 297 |
want := `{ |
| 298 |
"total_commit_comments": 1, |
| 299 |
"total_gist_comments": 1, |
| 300 |
"total_issue_comments": 1, |
| 301 |
"total_pull_request_comments": 1 |
| 302 |
}` |
| 303 |
|
| 304 |
testJSONMarshal(t, u, want) |
| 305 |
} |
| 306 |
|
| 307 |
func TestPageStats_Marshal(t *testing.T) { |
| 308 |
testJSONMarshal(t, &PageStats{}, "{}") |
| 309 |
|
| 310 |
u := &PageStats{ |
| 311 |
TotalPages: Int(1), |
| 312 |
} |
| 313 |
|
| 314 |
want := `{ |
| 315 |
"total_pages": 1 |
| 316 |
}` |
| 317 |
|
| 318 |
testJSONMarshal(t, u, want) |
| 319 |
} |
| 320 |
|
| 321 |
func TestUserStats_Marshal(t *testing.T) { |
| 322 |
testJSONMarshal(t, &UserStats{}, "{}") |
| 323 |
|
| 324 |
u := &UserStats{ |
| 325 |
TotalUsers: Int(1), |
| 326 |
AdminUsers: Int(1), |
| 327 |
SuspendedUsers: Int(1), |
| 328 |
} |
| 329 |
|
| 330 |
want := `{ |
| 331 |
"total_users": 1, |
| 332 |
"admin_users": 1, |
| 333 |
"suspended_users": 1 |
| 334 |
}` |
| 335 |
|
| 336 |
testJSONMarshal(t, u, want) |
| 337 |
} |
| 338 |
|
| 339 |
func TestGistStats_Marshal(t *testing.T) { |
| 340 |
testJSONMarshal(t, &GistStats{}, "{}") |
| 341 |
|
| 342 |
u := &GistStats{ |
| 343 |
TotalGists: Int(1), |
| 344 |
PrivateGists: Int(1), |
| 345 |
PublicGists: Int(1), |
| 346 |
} |
| 347 |
|
| 348 |
want := `{ |
| 349 |
"total_gists": 1, |
| 350 |
"private_gists": 1, |
| 351 |
"public_gists": 1 |
| 352 |
}` |
| 353 |
|
| 354 |
testJSONMarshal(t, u, want) |
| 355 |
} |
| 356 |
|
| 357 |
func TestPullStats_Marshal(t *testing.T) { |
| 358 |
testJSONMarshal(t, &PullStats{}, "{}") |
| 359 |
|
| 360 |
u := &PullStats{ |
| 361 |
TotalPulls: Int(1), |
| 362 |
MergedPulls: Int(1), |
| 363 |
MergablePulls: Int(1), |
| 364 |
UnmergablePulls: Int(1), |
| 365 |
} |
| 366 |
|
| 367 |
want := `{ |
| 368 |
"total_pulls": 1, |
| 369 |
"merged_pulls": 1, |
| 370 |
"mergeable_pulls": 1, |
| 371 |
"unmergeable_pulls": 1 |
| 372 |
}` |
| 373 |
|
| 374 |
testJSONMarshal(t, u, want) |
| 375 |
} |
| 376 |
|
| 377 |
func TestRepoStats_Marshal(t *testing.T) { |
| 378 |
testJSONMarshal(t, &RepoStats{}, "{}") |
| 379 |
|
| 380 |
u := &RepoStats{ |
| 381 |
TotalRepos: Int(1), |
| 382 |
RootRepos: Int(1), |
| 383 |
ForkRepos: Int(1), |
| 384 |
OrgRepos: Int(1), |
| 385 |
TotalPushes: Int(1), |
| 386 |
TotalWikis: Int(1), |
| 387 |
} |
| 388 |
|
| 389 |
want := `{ |
| 390 |
"total_repos": 1, |
| 391 |
"root_repos": 1, |
| 392 |
"fork_repos": 1, |
| 393 |
"org_repos": 1, |
| 394 |
"total_pushes": 1, |
| 395 |
"total_wikis": 1 |
| 396 |
}` |
| 397 |
|
| 398 |
testJSONMarshal(t, u, want) |
| 399 |
} |
| 400 |
|
| 401 |
func TestAdminStats_Marshal(t *testing.T) { |
| 402 |
testJSONMarshal(t, &AdminStats{}, "{}") |
| 403 |
|
| 404 |
u := &AdminStats{ |
| 405 |
Repos: &RepoStats{ |
| 406 |
TotalRepos: Int(212), |
| 407 |
RootRepos: Int(194), |
| 408 |
ForkRepos: Int(18), |
| 409 |
OrgRepos: Int(51), |
| 410 |
TotalPushes: Int(3082), |
| 411 |
TotalWikis: Int(15), |
| 412 |
}, |
| 413 |
Hooks: &HookStats{ |
| 414 |
TotalHooks: Int(27), |
| 415 |
ActiveHooks: Int(23), |
| 416 |
InactiveHooks: Int(4), |
| 417 |
}, |
| 418 |
Pages: &PageStats{ |
| 419 |
TotalPages: Int(36), |
| 420 |
}, |
| 421 |
Orgs: &OrgStats{ |
| 422 |
TotalOrgs: Int(33), |
| 423 |
DisabledOrgs: Int(0), |
| 424 |
TotalTeams: Int(60), |
| 425 |
TotalTeamMembers: Int(314), |
| 426 |
}, |
| 427 |
Users: &UserStats{ |
| 428 |
TotalUsers: Int(254), |
| 429 |
AdminUsers: Int(45), |
| 430 |
SuspendedUsers: Int(21), |
| 431 |
}, |
| 432 |
Pulls: &PullStats{ |
| 433 |
TotalPulls: Int(86), |
| 434 |
MergedPulls: Int(60), |
| 435 |
MergablePulls: Int(21), |
| 436 |
UnmergablePulls: Int(3), |
| 437 |
}, |
| 438 |
Issues: &IssueStats{ |
| 439 |
TotalIssues: Int(179), |
| 440 |
OpenIssues: Int(83), |
| 441 |
ClosedIssues: Int(96), |
| 442 |
}, |
| 443 |
Milestones: &MilestoneStats{ |
| 444 |
TotalMilestones: Int(7), |
| 445 |
OpenMilestones: Int(6), |
| 446 |
ClosedMilestones: Int(1), |
| 447 |
}, |
| 448 |
Gists: &GistStats{ |
| 449 |
TotalGists: Int(178), |
| 450 |
PrivateGists: Int(151), |
| 451 |
PublicGists: Int(25), |
| 452 |
}, |
| 453 |
Comments: &CommentStats{ |
| 454 |
TotalCommitComments: Int(6), |
| 455 |
TotalGistComments: Int(28), |
| 456 |
TotalIssueComments: Int(366), |
| 457 |
TotalPullRequestComments: Int(30), |
| 458 |
}, |
| 459 |
} |
| 460 |
|
| 461 |
want := `{ |
| 462 |
"repos": { |
| 463 |
"total_repos": 212, |
| 464 |
"root_repos": 194, |
| 465 |
"fork_repos": 18, |
| 466 |
"org_repos": 51, |
| 467 |
"total_pushes": 3082, |
| 468 |
"total_wikis": 15 |
| 469 |
}, |
| 470 |
"hooks": { |
| 471 |
"total_hooks": 27, |
| 472 |
"active_hooks": 23, |
| 473 |
"inactive_hooks": 4 |
| 474 |
}, |
| 475 |
"pages": { |
| 476 |
"total_pages": 36 |
| 477 |
}, |
| 478 |
"orgs": { |
| 479 |
"total_orgs": 33, |
| 480 |
"disabled_orgs": 0, |
| 481 |
"total_teams": 60, |
| 482 |
"total_team_members": 314 |
| 483 |
}, |
| 484 |
"users": { |
| 485 |
"total_users": 254, |
| 486 |
"admin_users": 45, |
| 487 |
"suspended_users": 21 |
| 488 |
}, |
| 489 |
"pulls": { |
| 490 |
"total_pulls": 86, |
| 491 |
"merged_pulls": 60, |
| 492 |
"mergeable_pulls": 21, |
| 493 |
"unmergeable_pulls": 3 |
| 494 |
}, |
| 495 |
"issues": { |
| 496 |
"total_issues": 179, |
| 497 |
"open_issues": 83, |
| 498 |
"closed_issues": 96 |
| 499 |
}, |
| 500 |
"milestones": { |
| 501 |
"total_milestones": 7, |
| 502 |
"open_milestones": 6, |
| 503 |
"closed_milestones": 1 |
| 504 |
}, |
| 505 |
"gists": { |
| 506 |
"total_gists": 178, |
| 507 |
"private_gists": 151, |
| 508 |
"public_gists": 25 |
| 509 |
}, |
| 510 |
"comments": { |
| 511 |
"total_commit_comments": 6, |
| 512 |
"total_gist_comments": 28, |
| 513 |
"total_issue_comments": 366, |
| 514 |
"total_pull_request_comments": 30 |
| 515 |
} |
| 516 |
}` |
| 517 |
|
| 518 |
testJSONMarshal(t, u, want) |
| 519 |
} |