github.com/google/go-github/v74@v74.0.0/github/reactions_test.go (about) 1 // Copyright 2016 The go-github AUTHORS. All rights reserved. 2 // 3 // Use of this source code is governed by a BSD-style 4 // license that can be found in the LICENSE file. 5 6 package github 7 8 import ( 9 "context" 10 "fmt" 11 "net/http" 12 "testing" 13 14 "github.com/google/go-cmp/cmp" 15 ) 16 17 func TestReaction_Marshal(t *testing.T) { 18 t.Parallel() 19 testJSONMarshal(t, &Reaction{}, "{}") 20 21 r := &Reaction{ 22 ID: Ptr(int64(1)), 23 User: nil, 24 NodeID: Ptr("n"), 25 Content: Ptr("+1"), 26 } 27 28 want := `{ 29 "id": 1, 30 "node_id": "n", 31 "content": "+1" 32 }` 33 34 testJSONMarshal(t, r, want) 35 } 36 37 func TestReactions_Marshal(t *testing.T) { 38 t.Parallel() 39 testJSONMarshal(t, &Reactions{}, "{}") 40 41 r := &Reactions{ 42 TotalCount: Ptr(1), 43 PlusOne: Ptr(1), 44 MinusOne: Ptr(1), 45 Laugh: Ptr(1), 46 Confused: Ptr(1), 47 Heart: Ptr(1), 48 Hooray: Ptr(1), 49 Rocket: Ptr(1), 50 Eyes: Ptr(1), 51 URL: Ptr("u"), 52 } 53 54 want := `{ 55 "total_count": 1, 56 "+1": 1, 57 "-1": 1, 58 "laugh": 1, 59 "confused": 1, 60 "heart": 1, 61 "hooray": 1, 62 "rocket": 1, 63 "eyes": 1, 64 "url": "u" 65 }` 66 67 testJSONMarshal(t, r, want) 68 } 69 70 func TestReactionsService_ListCommentReactions(t *testing.T) { 71 t.Parallel() 72 client, mux, _ := setup(t) 73 74 mux.HandleFunc("/repos/o/r/comments/1/reactions", func(w http.ResponseWriter, r *http.Request) { 75 testMethod(t, r, "GET") 76 testHeader(t, r, "Accept", mediaTypeReactionsPreview) 77 78 testFormValues(t, r, values{"content": "+1"}) 79 fmt.Fprint(w, `[{"id":1,"user":{"login":"l","id":2},"content":"+1"}]`) 80 }) 81 82 opt := &ListReactionOptions{Content: "+1"} 83 ctx := context.Background() 84 reactions, _, err := client.Reactions.ListCommentReactions(ctx, "o", "r", 1, opt) 85 if err != nil { 86 t.Errorf("ListCommentReactions returned error: %v", err) 87 } 88 want := []*Reaction{{ID: Ptr(int64(1)), User: &User{Login: Ptr("l"), ID: Ptr(int64(2))}, Content: Ptr("+1")}} 89 if !cmp.Equal(reactions, want) { 90 t.Errorf("ListCommentReactions = %+v, want %+v", reactions, want) 91 } 92 93 const methodName = "ListCommentReactions" 94 testBadOptions(t, methodName, func() (err error) { 95 _, _, err = client.Reactions.ListCommentReactions(ctx, "\n", "\n", -1, opt) 96 return err 97 }) 98 99 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 100 got, resp, err := client.Reactions.ListCommentReactions(ctx, "o", "r", 1, opt) 101 if got != nil { 102 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) 103 } 104 return resp, err 105 }) 106 } 107 108 func TestReactionsService_CreateCommentReaction(t *testing.T) { 109 t.Parallel() 110 client, mux, _ := setup(t) 111 112 mux.HandleFunc("/repos/o/r/comments/1/reactions", func(w http.ResponseWriter, r *http.Request) { 113 testMethod(t, r, "POST") 114 testHeader(t, r, "Accept", mediaTypeReactionsPreview) 115 116 w.WriteHeader(http.StatusCreated) 117 assertWrite(t, w, []byte(`{"id":1,"user":{"login":"l","id":2},"content":"+1"}`)) 118 }) 119 120 ctx := context.Background() 121 got, _, err := client.Reactions.CreateCommentReaction(ctx, "o", "r", 1, "+1") 122 if err != nil { 123 t.Errorf("CreateCommentReaction returned error: %v", err) 124 } 125 want := &Reaction{ID: Ptr(int64(1)), User: &User{Login: Ptr("l"), ID: Ptr(int64(2))}, Content: Ptr("+1")} 126 if !cmp.Equal(got, want) { 127 t.Errorf("CreateCommentReaction = %+v, want %+v", got, want) 128 } 129 130 const methodName = "CreateCommentReaction" 131 testBadOptions(t, methodName, func() (err error) { 132 _, _, err = client.Reactions.CreateCommentReaction(ctx, "\n", "\n", -1, "\n") 133 return err 134 }) 135 136 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 137 got, resp, err := client.Reactions.CreateCommentReaction(ctx, "o", "r", 1, "+1") 138 if got != nil { 139 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) 140 } 141 return resp, err 142 }) 143 } 144 145 func TestReactionsService_ListIssueReactions(t *testing.T) { 146 t.Parallel() 147 client, mux, _ := setup(t) 148 149 mux.HandleFunc("/repos/o/r/issues/1/reactions", func(w http.ResponseWriter, r *http.Request) { 150 testMethod(t, r, "GET") 151 testHeader(t, r, "Accept", mediaTypeReactionsPreview) 152 testFormValues(t, r, values{"content": "+1"}) 153 154 w.WriteHeader(http.StatusOK) 155 assertWrite(t, w, []byte(`[{"id":1,"user":{"login":"l","id":2},"content":"+1"}]`)) 156 }) 157 158 opt := &ListReactionOptions{Content: "+1"} 159 ctx := context.Background() 160 got, _, err := client.Reactions.ListIssueReactions(ctx, "o", "r", 1, opt) 161 if err != nil { 162 t.Errorf("ListIssueReactions returned error: %v", err) 163 } 164 want := []*Reaction{{ID: Ptr(int64(1)), User: &User{Login: Ptr("l"), ID: Ptr(int64(2))}, Content: Ptr("+1")}} 165 if !cmp.Equal(got, want) { 166 t.Errorf("ListIssueReactions = %+v, want %+v", got, want) 167 } 168 } 169 170 func TestReactionsService_ListIssueReactions_coverage(t *testing.T) { 171 t.Parallel() 172 client, _, _ := setup(t) 173 174 ctx := context.Background() 175 176 const methodName = "ListIssueReactions" 177 testBadOptions(t, methodName, func() (err error) { 178 _, _, err = client.Reactions.ListIssueReactions(ctx, "\n", "\n", -1, &ListReactionOptions{}) 179 return err 180 }) 181 182 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 183 got, resp, err := client.Reactions.ListIssueReactions(ctx, "o", "r", 1, nil) 184 if got != nil { 185 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) 186 } 187 return resp, err 188 }) 189 } 190 191 func TestReactionsService_CreateIssueReaction(t *testing.T) { 192 t.Parallel() 193 client, mux, _ := setup(t) 194 195 mux.HandleFunc("/repos/o/r/issues/1/reactions", func(w http.ResponseWriter, r *http.Request) { 196 testMethod(t, r, "POST") 197 testHeader(t, r, "Accept", mediaTypeReactionsPreview) 198 199 w.WriteHeader(http.StatusCreated) 200 assertWrite(t, w, []byte(`{"id":1,"user":{"login":"l","id":2},"content":"+1"}`)) 201 }) 202 203 ctx := context.Background() 204 got, _, err := client.Reactions.CreateIssueReaction(ctx, "o", "r", 1, "+1") 205 if err != nil { 206 t.Errorf("CreateIssueReaction returned error: %v", err) 207 } 208 want := &Reaction{ID: Ptr(int64(1)), User: &User{Login: Ptr("l"), ID: Ptr(int64(2))}, Content: Ptr("+1")} 209 if !cmp.Equal(got, want) { 210 t.Errorf("CreateIssueReaction = %+v, want %+v", got, want) 211 } 212 213 const methodName = "CreateIssueReaction" 214 testBadOptions(t, methodName, func() (err error) { 215 _, _, err = client.Reactions.CreateIssueReaction(ctx, "\n", "\n", -1, "\n") 216 return err 217 }) 218 219 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 220 got, resp, err := client.Reactions.CreateIssueReaction(ctx, "o", "r", 1, "+1") 221 if got != nil { 222 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) 223 } 224 return resp, err 225 }) 226 } 227 228 func TestReactionsService_ListIssueCommentReactions(t *testing.T) { 229 t.Parallel() 230 client, mux, _ := setup(t) 231 232 mux.HandleFunc("/repos/o/r/issues/comments/1/reactions", func(w http.ResponseWriter, r *http.Request) { 233 testMethod(t, r, "GET") 234 testHeader(t, r, "Accept", mediaTypeReactionsPreview) 235 testFormValues(t, r, values{"content": "+1"}) 236 237 w.WriteHeader(http.StatusOK) 238 assertWrite(t, w, []byte(`[{"id":1,"user":{"login":"l","id":2},"content":"+1"}]`)) 239 }) 240 241 opt := &ListReactionOptions{Content: "+1"} 242 ctx := context.Background() 243 got, _, err := client.Reactions.ListIssueCommentReactions(ctx, "o", "r", 1, opt) 244 if err != nil { 245 t.Errorf("ListIssueCommentReactions returned error: %v", err) 246 } 247 want := []*Reaction{{ID: Ptr(int64(1)), User: &User{Login: Ptr("l"), ID: Ptr(int64(2))}, Content: Ptr("+1")}} 248 if !cmp.Equal(got, want) { 249 t.Errorf("ListIssueCommentReactions = %+v, want %+v", got, want) 250 } 251 } 252 253 func TestReactionsService_ListIssueCommentReactions_coverage(t *testing.T) { 254 t.Parallel() 255 client, _, _ := setup(t) 256 257 ctx := context.Background() 258 259 const methodName = "ListIssueCommentReactions" 260 testBadOptions(t, methodName, func() (err error) { 261 _, _, err = client.Reactions.ListIssueCommentReactions(ctx, "\n", "\n", -1, &ListReactionOptions{}) 262 return err 263 }) 264 265 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 266 got, resp, err := client.Reactions.ListIssueCommentReactions(ctx, "o", "r", 1, nil) 267 if got != nil { 268 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) 269 } 270 return resp, err 271 }) 272 } 273 274 func TestReactionsService_CreateIssueCommentReaction(t *testing.T) { 275 t.Parallel() 276 client, mux, _ := setup(t) 277 278 mux.HandleFunc("/repos/o/r/issues/comments/1/reactions", func(w http.ResponseWriter, r *http.Request) { 279 testMethod(t, r, "POST") 280 testHeader(t, r, "Accept", mediaTypeReactionsPreview) 281 282 w.WriteHeader(http.StatusCreated) 283 assertWrite(t, w, []byte(`{"id":1,"user":{"login":"l","id":2},"content":"+1"}`)) 284 }) 285 286 ctx := context.Background() 287 got, _, err := client.Reactions.CreateIssueCommentReaction(ctx, "o", "r", 1, "+1") 288 if err != nil { 289 t.Errorf("CreateIssueCommentReaction returned error: %v", err) 290 } 291 want := &Reaction{ID: Ptr(int64(1)), User: &User{Login: Ptr("l"), ID: Ptr(int64(2))}, Content: Ptr("+1")} 292 if !cmp.Equal(got, want) { 293 t.Errorf("CreateIssueCommentReaction = %+v, want %+v", got, want) 294 } 295 296 const methodName = "CreateIssueCommentReaction" 297 testBadOptions(t, methodName, func() (err error) { 298 _, _, err = client.Reactions.CreateIssueCommentReaction(ctx, "\n", "\n", -1, "\n") 299 return err 300 }) 301 302 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 303 got, resp, err := client.Reactions.CreateIssueCommentReaction(ctx, "o", "r", 1, "+1") 304 if got != nil { 305 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) 306 } 307 return resp, err 308 }) 309 } 310 311 func TestReactionsService_ListPullRequestCommentReactions(t *testing.T) { 312 t.Parallel() 313 client, mux, _ := setup(t) 314 315 mux.HandleFunc("/repos/o/r/pulls/comments/1/reactions", func(w http.ResponseWriter, r *http.Request) { 316 testMethod(t, r, "GET") 317 testHeader(t, r, "Accept", mediaTypeReactionsPreview) 318 testFormValues(t, r, values{"content": "+1"}) 319 320 w.WriteHeader(http.StatusOK) 321 assertWrite(t, w, []byte(`[{"id":1,"user":{"login":"l","id":2},"content":"+1"}]`)) 322 }) 323 324 opt := &ListReactionOptions{Content: "+1"} 325 ctx := context.Background() 326 got, _, err := client.Reactions.ListPullRequestCommentReactions(ctx, "o", "r", 1, opt) 327 if err != nil { 328 t.Errorf("ListPullRequestCommentReactions returned error: %v", err) 329 } 330 want := []*Reaction{{ID: Ptr(int64(1)), User: &User{Login: Ptr("l"), ID: Ptr(int64(2))}, Content: Ptr("+1")}} 331 if !cmp.Equal(got, want) { 332 t.Errorf("ListPullRequestCommentReactions = %+v, want %+v", got, want) 333 } 334 } 335 336 func TestReactionsService_ListPullRequestCommentReactions_coverage(t *testing.T) { 337 t.Parallel() 338 client, _, _ := setup(t) 339 340 ctx := context.Background() 341 342 const methodName = "ListPullRequestCommentReactions" 343 testBadOptions(t, methodName, func() (err error) { 344 _, _, err = client.Reactions.ListPullRequestCommentReactions(ctx, "\n", "\n", -1, &ListReactionOptions{}) 345 return err 346 }) 347 348 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 349 got, resp, err := client.Reactions.ListPullRequestCommentReactions(ctx, "o", "r", 1, nil) 350 if got != nil { 351 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) 352 } 353 return resp, err 354 }) 355 } 356 357 func TestReactionsService_CreatePullRequestCommentReaction(t *testing.T) { 358 t.Parallel() 359 client, mux, _ := setup(t) 360 361 mux.HandleFunc("/repos/o/r/pulls/comments/1/reactions", func(w http.ResponseWriter, r *http.Request) { 362 testMethod(t, r, "POST") 363 testHeader(t, r, "Accept", mediaTypeReactionsPreview) 364 365 w.WriteHeader(http.StatusCreated) 366 assertWrite(t, w, []byte(`{"id":1,"user":{"login":"l","id":2},"content":"+1"}`)) 367 }) 368 369 ctx := context.Background() 370 got, _, err := client.Reactions.CreatePullRequestCommentReaction(ctx, "o", "r", 1, "+1") 371 if err != nil { 372 t.Errorf("CreatePullRequestCommentReaction returned error: %v", err) 373 } 374 want := &Reaction{ID: Ptr(int64(1)), User: &User{Login: Ptr("l"), ID: Ptr(int64(2))}, Content: Ptr("+1")} 375 if !cmp.Equal(got, want) { 376 t.Errorf("CreatePullRequestCommentReaction = %+v, want %+v", got, want) 377 } 378 379 const methodName = "CreatePullRequestCommentReaction" 380 testBadOptions(t, methodName, func() (err error) { 381 _, _, err = client.Reactions.CreatePullRequestCommentReaction(ctx, "\n", "\n", -1, "\n") 382 return err 383 }) 384 385 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 386 got, resp, err := client.Reactions.CreatePullRequestCommentReaction(ctx, "o", "r", 1, "+1") 387 if got != nil { 388 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) 389 } 390 return resp, err 391 }) 392 } 393 394 func TestReactionsService_ListTeamDiscussionReactions(t *testing.T) { 395 t.Parallel() 396 client, mux, _ := setup(t) 397 398 mux.HandleFunc("/teams/1/discussions/2/reactions", func(w http.ResponseWriter, r *http.Request) { 399 testMethod(t, r, "GET") 400 testHeader(t, r, "Accept", mediaTypeReactionsPreview) 401 testFormValues(t, r, values{"content": "+1"}) 402 403 w.WriteHeader(http.StatusOK) 404 assertWrite(t, w, []byte(`[{"id":1,"user":{"login":"l","id":2},"content":"+1"}]`)) 405 }) 406 407 opt := &ListReactionOptions{Content: "+1"} 408 ctx := context.Background() 409 got, _, err := client.Reactions.ListTeamDiscussionReactions(ctx, 1, 2, opt) 410 if err != nil { 411 t.Errorf("ListTeamDiscussionReactions returned error: %v", err) 412 } 413 want := []*Reaction{{ID: Ptr(int64(1)), User: &User{Login: Ptr("l"), ID: Ptr(int64(2))}, Content: Ptr("+1")}} 414 if !cmp.Equal(got, want) { 415 t.Errorf("ListTeamDiscussionReactions = %+v, want %+v", got, want) 416 } 417 } 418 419 func TestReactionsService_ListTeamDiscussionReactions_coverage(t *testing.T) { 420 t.Parallel() 421 client, _, _ := setup(t) 422 423 ctx := context.Background() 424 425 const methodName = "ListTeamDiscussionReactions" 426 testBadOptions(t, methodName, func() (err error) { 427 _, _, err = client.Reactions.ListTeamDiscussionReactions(ctx, -1, -2, &ListReactionOptions{}) 428 return err 429 }) 430 431 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 432 got, resp, err := client.Reactions.ListTeamDiscussionReactions(ctx, 1, 2, nil) 433 if got != nil { 434 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) 435 } 436 return resp, err 437 }) 438 } 439 440 func TestReactionsService_CreateTeamDiscussionReaction(t *testing.T) { 441 t.Parallel() 442 client, mux, _ := setup(t) 443 444 mux.HandleFunc("/teams/1/discussions/2/reactions", func(w http.ResponseWriter, r *http.Request) { 445 testMethod(t, r, "POST") 446 testHeader(t, r, "Accept", mediaTypeReactionsPreview) 447 448 w.WriteHeader(http.StatusCreated) 449 assertWrite(t, w, []byte(`{"id":1,"user":{"login":"l","id":2},"content":"+1"}`)) 450 }) 451 452 ctx := context.Background() 453 got, _, err := client.Reactions.CreateTeamDiscussionReaction(ctx, 1, 2, "+1") 454 if err != nil { 455 t.Errorf("CreateTeamDiscussionReaction returned error: %v", err) 456 } 457 want := &Reaction{ID: Ptr(int64(1)), User: &User{Login: Ptr("l"), ID: Ptr(int64(2))}, Content: Ptr("+1")} 458 if !cmp.Equal(got, want) { 459 t.Errorf("CreateTeamDiscussionReaction = %+v, want %+v", got, want) 460 } 461 462 const methodName = "CreateTeamDiscussionReaction" 463 testBadOptions(t, methodName, func() (err error) { 464 _, _, err = client.Reactions.CreateTeamDiscussionReaction(ctx, -1, -2, "\n") 465 return err 466 }) 467 468 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 469 got, resp, err := client.Reactions.CreateTeamDiscussionReaction(ctx, 1, 2, "+1") 470 if got != nil { 471 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) 472 } 473 return resp, err 474 }) 475 } 476 477 func TestReactionService_ListTeamDiscussionCommentReactions(t *testing.T) { 478 t.Parallel() 479 client, mux, _ := setup(t) 480 481 mux.HandleFunc("/teams/1/discussions/2/comments/3/reactions", func(w http.ResponseWriter, r *http.Request) { 482 testMethod(t, r, "GET") 483 testHeader(t, r, "Accept", mediaTypeReactionsPreview) 484 testFormValues(t, r, values{"content": "+1"}) 485 486 w.WriteHeader(http.StatusOK) 487 assertWrite(t, w, []byte(`[{"id":1,"user":{"login":"l","id":2},"content":"+1"}]`)) 488 }) 489 490 opt := &ListReactionOptions{Content: "+1"} 491 ctx := context.Background() 492 got, _, err := client.Reactions.ListTeamDiscussionCommentReactions(ctx, 1, 2, 3, opt) 493 if err != nil { 494 t.Errorf("ListTeamDiscussionCommentReactions returned error: %v", err) 495 } 496 want := []*Reaction{{ID: Ptr(int64(1)), User: &User{Login: Ptr("l"), ID: Ptr(int64(2))}, Content: Ptr("+1")}} 497 if !cmp.Equal(got, want) { 498 t.Errorf("ListTeamDiscussionCommentReactions = %+v, want %+v", got, want) 499 } 500 } 501 502 func TestReactionService_ListTeamDiscussionCommentReactions_coverage(t *testing.T) { 503 t.Parallel() 504 client, _, _ := setup(t) 505 506 ctx := context.Background() 507 508 const methodName = "ListTeamDiscussionCommentReactions" 509 testBadOptions(t, methodName, func() (err error) { 510 _, _, err = client.Reactions.ListTeamDiscussionCommentReactions(ctx, -1, -2, -3, &ListReactionOptions{}) 511 return err 512 }) 513 514 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 515 got, resp, err := client.Reactions.ListTeamDiscussionCommentReactions(ctx, 1, 2, 3, nil) 516 if got != nil { 517 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) 518 } 519 return resp, err 520 }) 521 } 522 523 func TestReactionService_CreateTeamDiscussionCommentReaction(t *testing.T) { 524 t.Parallel() 525 client, mux, _ := setup(t) 526 527 mux.HandleFunc("/teams/1/discussions/2/comments/3/reactions", func(w http.ResponseWriter, r *http.Request) { 528 testMethod(t, r, "POST") 529 testHeader(t, r, "Accept", mediaTypeReactionsPreview) 530 531 w.WriteHeader(http.StatusCreated) 532 assertWrite(t, w, []byte(`{"id":1,"user":{"login":"l","id":2},"content":"+1"}`)) 533 }) 534 535 ctx := context.Background() 536 got, _, err := client.Reactions.CreateTeamDiscussionCommentReaction(ctx, 1, 2, 3, "+1") 537 if err != nil { 538 t.Errorf("CreateTeamDiscussionCommentReaction returned error: %v", err) 539 } 540 want := &Reaction{ID: Ptr(int64(1)), User: &User{Login: Ptr("l"), ID: Ptr(int64(2))}, Content: Ptr("+1")} 541 if !cmp.Equal(got, want) { 542 t.Errorf("CreateTeamDiscussionCommentReaction = %+v, want %+v", got, want) 543 } 544 545 const methodName = "CreateTeamDiscussionCommentReaction" 546 testBadOptions(t, methodName, func() (err error) { 547 _, _, err = client.Reactions.CreateTeamDiscussionCommentReaction(ctx, -1, -2, -3, "\n") 548 return err 549 }) 550 551 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 552 got, resp, err := client.Reactions.CreateTeamDiscussionCommentReaction(ctx, 1, 2, 3, "+1") 553 if got != nil { 554 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) 555 } 556 return resp, err 557 }) 558 } 559 560 func TestReactionsService_DeleteCommitCommentReaction(t *testing.T) { 561 t.Parallel() 562 client, mux, _ := setup(t) 563 564 mux.HandleFunc("/repos/o/r/comments/1/reactions/2", func(w http.ResponseWriter, r *http.Request) { 565 testMethod(t, r, "DELETE") 566 testHeader(t, r, "Accept", mediaTypeReactionsPreview) 567 568 w.WriteHeader(http.StatusNoContent) 569 }) 570 571 ctx := context.Background() 572 if _, err := client.Reactions.DeleteCommentReaction(ctx, "o", "r", 1, 2); err != nil { 573 t.Errorf("DeleteCommentReaction returned error: %v", err) 574 } 575 576 const methodName = "DeleteCommentReaction" 577 testBadOptions(t, methodName, func() (err error) { 578 _, err = client.Reactions.DeleteCommentReaction(ctx, "\n", "\n", -1, -2) 579 return err 580 }) 581 582 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 583 return client.Reactions.DeleteCommentReaction(ctx, "o", "r", 1, 2) 584 }) 585 } 586 587 func TestReactionsService_DeleteCommitCommentReactionByRepoID(t *testing.T) { 588 t.Parallel() 589 client, mux, _ := setup(t) 590 591 mux.HandleFunc("/repositories/1/comments/2/reactions/3", func(w http.ResponseWriter, r *http.Request) { 592 testMethod(t, r, "DELETE") 593 testHeader(t, r, "Accept", mediaTypeReactionsPreview) 594 595 w.WriteHeader(http.StatusNoContent) 596 }) 597 598 ctx := context.Background() 599 if _, err := client.Reactions.DeleteCommentReactionByID(ctx, 1, 2, 3); err != nil { 600 t.Errorf("DeleteCommentReactionByRepoID returned error: %v", err) 601 } 602 603 const methodName = "DeleteCommentReactionByID" 604 testBadOptions(t, methodName, func() (err error) { 605 _, err = client.Reactions.DeleteCommentReactionByID(ctx, -1, -2, -3) 606 return err 607 }) 608 609 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 610 return client.Reactions.DeleteCommentReactionByID(ctx, 1, 2, 3) 611 }) 612 } 613 614 func TestReactionsService_DeleteIssueReaction(t *testing.T) { 615 t.Parallel() 616 client, mux, _ := setup(t) 617 618 mux.HandleFunc("/repos/o/r/issues/1/reactions/2", func(w http.ResponseWriter, r *http.Request) { 619 testMethod(t, r, "DELETE") 620 testHeader(t, r, "Accept", mediaTypeReactionsPreview) 621 622 w.WriteHeader(http.StatusNoContent) 623 }) 624 625 ctx := context.Background() 626 if _, err := client.Reactions.DeleteIssueReaction(ctx, "o", "r", 1, 2); err != nil { 627 t.Errorf("DeleteIssueReaction returned error: %v", err) 628 } 629 630 const methodName = "DeleteIssueReaction" 631 testBadOptions(t, methodName, func() (err error) { 632 _, err = client.Reactions.DeleteIssueReaction(ctx, "\n", "\n", -1, -2) 633 return err 634 }) 635 636 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 637 return client.Reactions.DeleteIssueReaction(ctx, "o", "r", 1, 2) 638 }) 639 } 640 641 func TestReactionsService_DeleteIssueReactionByRepoID(t *testing.T) { 642 t.Parallel() 643 client, mux, _ := setup(t) 644 645 mux.HandleFunc("/repositories/1/issues/2/reactions/3", func(w http.ResponseWriter, r *http.Request) { 646 testMethod(t, r, "DELETE") 647 testHeader(t, r, "Accept", mediaTypeReactionsPreview) 648 649 w.WriteHeader(http.StatusNoContent) 650 }) 651 652 ctx := context.Background() 653 if _, err := client.Reactions.DeleteIssueReactionByID(ctx, 1, 2, 3); err != nil { 654 t.Errorf("DeleteIssueReactionByRepoID returned error: %v", err) 655 } 656 657 const methodName = "DeleteIssueReactionByID" 658 testBadOptions(t, methodName, func() (err error) { 659 _, err = client.Reactions.DeleteIssueReactionByID(ctx, -1, -2, -3) 660 return err 661 }) 662 663 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 664 return client.Reactions.DeleteIssueReactionByID(ctx, 1, 2, 3) 665 }) 666 } 667 668 func TestReactionsService_DeleteIssueCommentReaction(t *testing.T) { 669 t.Parallel() 670 client, mux, _ := setup(t) 671 672 mux.HandleFunc("/repos/o/r/issues/comments/1/reactions/2", func(w http.ResponseWriter, r *http.Request) { 673 testMethod(t, r, "DELETE") 674 testHeader(t, r, "Accept", mediaTypeReactionsPreview) 675 676 w.WriteHeader(http.StatusNoContent) 677 }) 678 679 ctx := context.Background() 680 if _, err := client.Reactions.DeleteIssueCommentReaction(ctx, "o", "r", 1, 2); err != nil { 681 t.Errorf("DeleteIssueCommentReaction returned error: %v", err) 682 } 683 684 const methodName = "DeleteIssueCommentReaction" 685 testBadOptions(t, methodName, func() (err error) { 686 _, err = client.Reactions.DeleteIssueCommentReaction(ctx, "\n", "\n", -1, -2) 687 return err 688 }) 689 690 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 691 return client.Reactions.DeleteIssueCommentReaction(ctx, "o", "r", 1, 2) 692 }) 693 } 694 695 func TestReactionsService_DeleteIssueCommentReactionByRepoID(t *testing.T) { 696 t.Parallel() 697 client, mux, _ := setup(t) 698 699 mux.HandleFunc("/repositories/1/issues/comments/2/reactions/3", func(w http.ResponseWriter, r *http.Request) { 700 testMethod(t, r, "DELETE") 701 testHeader(t, r, "Accept", mediaTypeReactionsPreview) 702 703 w.WriteHeader(http.StatusNoContent) 704 }) 705 706 ctx := context.Background() 707 if _, err := client.Reactions.DeleteIssueCommentReactionByID(ctx, 1, 2, 3); err != nil { 708 t.Errorf("DeleteIssueCommentReactionByRepoID returned error: %v", err) 709 } 710 711 const methodName = "DeleteIssueCommentReactionByID" 712 testBadOptions(t, methodName, func() (err error) { 713 _, err = client.Reactions.DeleteIssueCommentReactionByID(ctx, -1, -2, -3) 714 return err 715 }) 716 717 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 718 return client.Reactions.DeleteIssueCommentReactionByID(ctx, 1, 2, 3) 719 }) 720 } 721 722 func TestReactionsService_DeletePullRequestCommentReaction(t *testing.T) { 723 t.Parallel() 724 client, mux, _ := setup(t) 725 726 mux.HandleFunc("/repos/o/r/pulls/comments/1/reactions/2", func(w http.ResponseWriter, r *http.Request) { 727 testMethod(t, r, "DELETE") 728 testHeader(t, r, "Accept", mediaTypeReactionsPreview) 729 730 w.WriteHeader(http.StatusNoContent) 731 }) 732 733 ctx := context.Background() 734 if _, err := client.Reactions.DeletePullRequestCommentReaction(ctx, "o", "r", 1, 2); err != nil { 735 t.Errorf("DeletePullRequestCommentReaction returned error: %v", err) 736 } 737 738 const methodName = "DeletePullRequestCommentReaction" 739 testBadOptions(t, methodName, func() (err error) { 740 _, err = client.Reactions.DeletePullRequestCommentReaction(ctx, "\n", "\n", -1, -2) 741 return err 742 }) 743 744 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 745 return client.Reactions.DeletePullRequestCommentReaction(ctx, "o", "r", 1, 2) 746 }) 747 } 748 749 func TestReactionsService_DeletePullRequestCommentReactionByRepoID(t *testing.T) { 750 t.Parallel() 751 client, mux, _ := setup(t) 752 753 mux.HandleFunc("/repositories/1/pulls/comments/2/reactions/3", func(w http.ResponseWriter, r *http.Request) { 754 testMethod(t, r, "DELETE") 755 testHeader(t, r, "Accept", mediaTypeReactionsPreview) 756 757 w.WriteHeader(http.StatusNoContent) 758 }) 759 760 ctx := context.Background() 761 if _, err := client.Reactions.DeletePullRequestCommentReactionByID(ctx, 1, 2, 3); err != nil { 762 t.Errorf("DeletePullRequestCommentReactionByRepoID returned error: %v", err) 763 } 764 765 const methodName = "DeletePullRequestCommentReactionByID" 766 testBadOptions(t, methodName, func() (err error) { 767 _, err = client.Reactions.DeletePullRequestCommentReactionByID(ctx, -1, -2, -3) 768 return err 769 }) 770 771 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 772 return client.Reactions.DeletePullRequestCommentReactionByID(ctx, 1, 2, 3) 773 }) 774 } 775 776 func TestReactionsService_DeleteTeamDiscussionReaction(t *testing.T) { 777 t.Parallel() 778 client, mux, _ := setup(t) 779 780 mux.HandleFunc("/orgs/o/teams/s/discussions/1/reactions/2", func(w http.ResponseWriter, r *http.Request) { 781 testMethod(t, r, "DELETE") 782 testHeader(t, r, "Accept", mediaTypeReactionsPreview) 783 784 w.WriteHeader(http.StatusNoContent) 785 }) 786 787 ctx := context.Background() 788 if _, err := client.Reactions.DeleteTeamDiscussionReaction(ctx, "o", "s", 1, 2); err != nil { 789 t.Errorf("DeleteTeamDiscussionReaction returned error: %v", err) 790 } 791 792 const methodName = "DeleteTeamDiscussionReaction" 793 testBadOptions(t, methodName, func() (err error) { 794 _, err = client.Reactions.DeleteTeamDiscussionReaction(ctx, "\n", "\n", -1, -2) 795 return err 796 }) 797 798 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 799 return client.Reactions.DeleteTeamDiscussionReaction(ctx, "o", "s", 1, 2) 800 }) 801 } 802 803 func TestReactionsService_DeleteTeamDiscussionReactionByTeamIDAndOrgID(t *testing.T) { 804 t.Parallel() 805 client, mux, _ := setup(t) 806 807 mux.HandleFunc("/organizations/1/team/2/discussions/3/reactions/4", func(w http.ResponseWriter, r *http.Request) { 808 testMethod(t, r, "DELETE") 809 testHeader(t, r, "Accept", mediaTypeReactionsPreview) 810 811 w.WriteHeader(http.StatusNoContent) 812 }) 813 814 ctx := context.Background() 815 if _, err := client.Reactions.DeleteTeamDiscussionReactionByOrgIDAndTeamID(ctx, 1, 2, 3, 4); err != nil { 816 t.Errorf("DeleteTeamDiscussionReactionByTeamIDAndOrgID returned error: %v", err) 817 } 818 819 const methodName = "DeleteTeamDiscussionReactionByOrgIDAndTeamID" 820 testBadOptions(t, methodName, func() (err error) { 821 _, err = client.Reactions.DeleteTeamDiscussionReactionByOrgIDAndTeamID(ctx, -1, -2, -3, -4) 822 return err 823 }) 824 825 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 826 return client.Reactions.DeleteTeamDiscussionReactionByOrgIDAndTeamID(ctx, 1, 2, 3, 4) 827 }) 828 } 829 830 func TestReactionsService_DeleteTeamDiscussionCommentReaction(t *testing.T) { 831 t.Parallel() 832 client, mux, _ := setup(t) 833 834 mux.HandleFunc("/orgs/o/teams/s/discussions/1/comments/2/reactions/3", func(w http.ResponseWriter, r *http.Request) { 835 testMethod(t, r, "DELETE") 836 testHeader(t, r, "Accept", mediaTypeReactionsPreview) 837 838 w.WriteHeader(http.StatusNoContent) 839 }) 840 841 ctx := context.Background() 842 if _, err := client.Reactions.DeleteTeamDiscussionCommentReaction(ctx, "o", "s", 1, 2, 3); err != nil { 843 t.Errorf("DeleteTeamDiscussionCommentReaction returned error: %v", err) 844 } 845 846 const methodName = "DeleteTeamDiscussionCommentReaction" 847 testBadOptions(t, methodName, func() (err error) { 848 _, err = client.Reactions.DeleteTeamDiscussionCommentReaction(ctx, "\n", "\n", -1, -2, -3) 849 return err 850 }) 851 852 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 853 return client.Reactions.DeleteTeamDiscussionCommentReaction(ctx, "o", "s", 1, 2, 3) 854 }) 855 } 856 857 func TestReactionsService_DeleteTeamDiscussionCommentReactionByTeamIDAndOrgID(t *testing.T) { 858 t.Parallel() 859 client, mux, _ := setup(t) 860 861 mux.HandleFunc("/organizations/1/team/2/discussions/3/comments/4/reactions/5", func(w http.ResponseWriter, r *http.Request) { 862 testMethod(t, r, "DELETE") 863 testHeader(t, r, "Accept", mediaTypeReactionsPreview) 864 865 w.WriteHeader(http.StatusNoContent) 866 }) 867 868 ctx := context.Background() 869 if _, err := client.Reactions.DeleteTeamDiscussionCommentReactionByOrgIDAndTeamID(ctx, 1, 2, 3, 4, 5); err != nil { 870 t.Errorf("DeleteTeamDiscussionCommentReactionByTeamIDAndOrgID returned error: %v", err) 871 } 872 873 const methodName = "DeleteTeamDiscussionCommentReactionByOrgIDAndTeamID" 874 testBadOptions(t, methodName, func() (err error) { 875 _, err = client.Reactions.DeleteTeamDiscussionCommentReactionByOrgIDAndTeamID(ctx, -1, -2, -3, -4, -5) 876 return err 877 }) 878 879 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 880 return client.Reactions.DeleteTeamDiscussionCommentReactionByOrgIDAndTeamID(ctx, 1, 2, 3, 4, 5) 881 }) 882 } 883 884 func TestReactionService_CreateReleaseReaction(t *testing.T) { 885 t.Parallel() 886 client, mux, _ := setup(t) 887 888 mux.HandleFunc("/repos/o/r/releases/1/reactions", func(w http.ResponseWriter, r *http.Request) { 889 testMethod(t, r, "POST") 890 testHeader(t, r, "Accept", mediaTypeReactionsPreview) 891 892 w.WriteHeader(http.StatusCreated) 893 assertWrite(t, w, []byte(`{"id":1,"user":{"login":"l","id":2},"content":"rocket"}`)) 894 }) 895 896 const methodName = "CreateReleaseReaction" 897 ctx := context.Background() 898 got, _, err := client.Reactions.CreateReleaseReaction(ctx, "o", "r", 1, "rocket") 899 if err != nil { 900 t.Errorf("%v returned error: %v", methodName, err) 901 } 902 903 want := &Reaction{ID: Ptr(int64(1)), User: &User{Login: Ptr("l"), ID: Ptr(int64(2))}, Content: Ptr("rocket")} 904 if !cmp.Equal(got, want) { 905 t.Errorf("%v = %+v, want %+v", methodName, got, want) 906 } 907 908 testBadOptions(t, methodName, func() (err error) { 909 _, _, err = client.Reactions.CreateReleaseReaction(ctx, "\n", "\n", -1, "\n") 910 return err 911 }) 912 913 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 914 got, resp, err := client.Reactions.CreateReleaseReaction(ctx, "o", "r", 1, "rocket") 915 if got != nil { 916 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) 917 } 918 return resp, err 919 }) 920 } 921 922 func TestReactionsService_ListReleaseReactions(t *testing.T) { 923 t.Parallel() 924 client, mux, _ := setup(t) 925 926 mux.HandleFunc("/repos/o/r/releases/1/reactions", func(w http.ResponseWriter, r *http.Request) { 927 testMethod(t, r, "GET") 928 testHeader(t, r, "Accept", mediaTypeReactionsPreview) 929 testFormValues(t, r, values{"content": "+1"}) 930 931 w.WriteHeader(http.StatusOK) 932 assertWrite(t, w, []byte(`[{"id":1,"user":{"login":"l","id":2},"content":"+1"}]`)) 933 }) 934 935 opt := &ListReactionOptions{Content: "+1"} 936 ctx := context.Background() 937 got, _, err := client.Reactions.ListReleaseReactions(ctx, "o", "r", 1, opt) 938 if err != nil { 939 t.Errorf("ListReleaseReactions returned error: %v", err) 940 } 941 want := []*Reaction{{ID: Ptr(int64(1)), User: &User{Login: Ptr("l"), ID: Ptr(int64(2))}, Content: Ptr("+1")}} 942 if !cmp.Equal(got, want) { 943 t.Errorf("ListReleaseReactions = %+v, want %+v", got, want) 944 } 945 } 946 947 func TestReactionsService_ListReleaseReactions_coverage(t *testing.T) { 948 t.Parallel() 949 client, _, _ := setup(t) 950 951 ctx := context.Background() 952 953 const methodName = "ListReleaseReactions" 954 testBadOptions(t, methodName, func() (err error) { 955 _, _, err = client.Reactions.ListReleaseReactions(ctx, "\n", "\n", -1, &ListReactionOptions{}) 956 return err 957 }) 958 959 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 960 got, resp, err := client.Reactions.ListReleaseReactions(ctx, "o", "r", 1, nil) 961 if got != nil { 962 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) 963 } 964 return resp, err 965 }) 966 } 967 968 func TestReactionsService_DeleteReleaseReaction(t *testing.T) { 969 t.Parallel() 970 client, mux, _ := setup(t) 971 972 mux.HandleFunc("/repos/o/r/releases/1/reactions/2", func(w http.ResponseWriter, r *http.Request) { 973 testMethod(t, r, "DELETE") 974 testHeader(t, r, "Accept", mediaTypeReactionsPreview) 975 976 w.WriteHeader(http.StatusNoContent) 977 }) 978 979 ctx := context.Background() 980 if _, err := client.Reactions.DeleteReleaseReaction(ctx, "o", "r", 1, 2); err != nil { 981 t.Errorf("DeleteReleaseReaction returned error: %v", err) 982 } 983 984 const methodName = "DeleteReleaseReaction" 985 testBadOptions(t, methodName, func() (err error) { 986 _, err = client.Reactions.DeleteReleaseReaction(ctx, "\n", "\n", -1, -2) 987 return err 988 }) 989 990 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 991 return client.Reactions.DeleteReleaseReaction(ctx, "o", "r", 1, 2) 992 }) 993 } 994 995 func TestReactionsService_DeleteReleaseReactionByRepoID(t *testing.T) { 996 t.Parallel() 997 client, mux, _ := setup(t) 998 999 mux.HandleFunc("/repositories/1/releases/2/reactions/3", func(w http.ResponseWriter, r *http.Request) { 1000 testMethod(t, r, "DELETE") 1001 testHeader(t, r, "Accept", mediaTypeReactionsPreview) 1002 1003 w.WriteHeader(http.StatusNoContent) 1004 }) 1005 1006 ctx := context.Background() 1007 if _, err := client.Reactions.DeleteReleaseReactionByID(ctx, 1, 2, 3); err != nil { 1008 t.Errorf("DeleteReleaseReactionByRepoID returned error: %v", err) 1009 } 1010 1011 const methodName = "DeleteReleaseReactionByID" 1012 testBadOptions(t, methodName, func() (err error) { 1013 _, err = client.Reactions.DeleteIssueReactionByID(ctx, -1, -2, -3) 1014 return err 1015 }) 1016 1017 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 1018 return client.Reactions.DeleteIssueReactionByID(ctx, 1, 2, 3) 1019 }) 1020 }