MCPcopy Index your code
hub / github.com/google/go-github / TestGitService_UpdateRef

Function TestGitService_UpdateRef

github/git_refs_test.go:417–499  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

415}
416
417func 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"})

Callers

nothing calls this directly

Calls 8

testMethodFunction · 0.85
testJSONBodyFunction · 0.85
testBadOptionsFunction · 0.85
UpdateRefMethod · 0.80
EqualMethod · 0.80
setupFunction · 0.70
PtrFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…