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

Function TestGitService_GetRef_singleRef

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

Source from the content-addressed store, hash-verified

15)
16
17func TestGitService_GetRef_singleRef(t *testing.T) {
18 t.Parallel()
19 client, mux, _ := setup(t)
20
21 mux.HandleFunc("/repos/o/r/git/ref/heads/b", func(w http.ResponseWriter, r *http.Request) {
22 testMethod(t, r, "GET")
23 fmt.Fprint(w, `
24 {
25 "ref": "refs/heads/b",
26 "url": "https://api.github.com/repos/o/r/git/refs/heads/b",
27 "object": {
28 "type": "commit",
29 "sha": "aa218f56b14c9653891f9e74264a383fa43fefbd",
30 "url": "https://api.github.com/repos/o/r/git/commits/aa218f56b14c9653891f9e74264a383fa43fefbd"
31 }
32 }`)
33 })
34
35 ctx := t.Context()
36 ref, _, err := client.Git.GetRef(ctx, "o", "r", "refs/heads/b")
37 if err != nil {
38 t.Fatalf("Git.GetRef returned error: %v", err)
39 }
40
41 want := &Reference{
42 Ref: Ptr("refs/heads/b"),
43 URL: Ptr("https://api.github.com/repos/o/r/git/refs/heads/b"),
44 Object: &GitObject{
45 Type: Ptr("commit"),
46 SHA: Ptr("aa218f56b14c9653891f9e74264a383fa43fefbd"),
47 URL: Ptr("https://api.github.com/repos/o/r/git/commits/aa218f56b14c9653891f9e74264a383fa43fefbd"),
48 },
49 }
50 if !cmp.Equal(ref, want) {
51 t.Errorf("Git.GetRef returned %+v, want %+v", ref, want)
52 }
53
54 // without 'refs/' prefix
55 if _, _, err := client.Git.GetRef(ctx, "o", "r", "heads/b"); err != nil {
56 t.Errorf("Git.GetRef returned error: %v", err)
57 }
58
59 const methodName = "GetRef"
60 testBadOptions(t, methodName, func() (err error) {
61 _, _, err = client.Git.GetRef(ctx, "\n", "\n", "\n")
62 return err
63 })
64
65 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
66 got, resp, err := client.Git.GetRef(ctx, "o", "r", "refs/heads/b")
67 if got != nil {
68 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
69 }
70 return resp, err
71 })
72}
73
74func TestGitService_GetRef_noRefs(t *testing.T) {

Callers

nothing calls this directly

Calls 7

testMethodFunction · 0.85
testBadOptionsFunction · 0.85
EqualMethod · 0.80
setupFunction · 0.70
PtrFunction · 0.70
GetRefMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…