(t *testing.T)
| 415 | } |
| 416 | |
| 417 | func TestGitService_UpdateRef(t *testing.T) { |
| 418 | t.Parallel() |
| 419 | client, mux, _ := setup(t) |
| 420 | |
| 421 | args := UpdateRef{ |
| 422 | SHA: "aa218f56b14c9653891f9e74264a383fa43fefbd", |
| 423 | Force: Ptr(true), |
| 424 | } |
| 425 | |
| 426 | mux.HandleFunc("/repos/o/r/git/refs/heads/b", func(w http.ResponseWriter, r *http.Request) { |
| 427 | testMethod(t, r, "PATCH") |
| 428 | testJSONBody(t, r, args) |
| 429 | fmt.Fprint(w, ` |
| 430 | { |
| 431 | "ref": "refs/heads/b", |
| 432 | "url": "https://api.github.com/repos/o/r/git/refs/heads/b", |
| 433 | "object": { |
| 434 | "type": "commit", |
| 435 | "sha": "aa218f56b14c9653891f9e74264a383fa43fefbd", |
| 436 | "url": "https://api.github.com/repos/o/r/git/commits/aa218f56b14c9653891f9e74264a383fa43fefbd" |
| 437 | } |
| 438 | }`) |
| 439 | }) |
| 440 | |
| 441 | ctx := t.Context() |
| 442 | ref, _, err := client.Git.UpdateRef(ctx, "o", "r", "refs/heads/b", UpdateRef{ |
| 443 | SHA: "aa218f56b14c9653891f9e74264a383fa43fefbd", |
| 444 | Force: Ptr(true), |
| 445 | }) |
| 446 | if err != nil { |
| 447 | t.Errorf("Git.UpdateRef returned error: %v", err) |
| 448 | } |
| 449 | |
| 450 | want := &Reference{ |
| 451 | Ref: Ptr("refs/heads/b"), |
| 452 | URL: Ptr("https://api.github.com/repos/o/r/git/refs/heads/b"), |
| 453 | Object: &GitObject{ |
| 454 | Type: Ptr("commit"), |
| 455 | SHA: Ptr("aa218f56b14c9653891f9e74264a383fa43fefbd"), |
| 456 | URL: Ptr("https://api.github.com/repos/o/r/git/commits/aa218f56b14c9653891f9e74264a383fa43fefbd"), |
| 457 | }, |
| 458 | } |
| 459 | if !cmp.Equal(ref, want) { |
| 460 | t.Errorf("Git.UpdateRef returned %+v, want %+v", ref, want) |
| 461 | } |
| 462 | |
| 463 | // without 'refs/' prefix |
| 464 | _, _, err = client.Git.UpdateRef(ctx, "o", "r", "heads/b", UpdateRef{ |
| 465 | SHA: "aa218f56b14c9653891f9e74264a383fa43fefbd", |
| 466 | Force: Ptr(true), |
| 467 | }) |
| 468 | if err != nil { |
| 469 | t.Errorf("Git.UpdateRef returned error: %v", err) |
| 470 | } |
| 471 | |
| 472 | const methodName = "UpdateRef" |
| 473 | testBadOptions(t, methodName, func() (err error) { |
| 474 | _, _, err = client.Git.UpdateRef(ctx, "o", "r", "", UpdateRef{SHA: "aa218f56b14c9653891f9e74264a383fa43fefbd"}) |
nothing calls this directly
no test coverage detected
searching dependent graphs…