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

Function TestRepositoriesService_GetContents_File

github/repos_contents_test.go:662–699  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

660}
661
662func TestRepositoriesService_GetContents_File(t *testing.T) {
663 t.Parallel()
664 client, mux, _ := setup(t)
665
666 mux.HandleFunc("/repos/o/r/contents/p", func(w http.ResponseWriter, r *http.Request) {
667 testMethod(t, r, "GET")
668 fmt.Fprint(w, `{
669 "type": "file",
670 "encoding": "base64",
671 "size": 20678,
672 "name": "LICENSE",
673 "path": "LICENSE"
674 }`)
675 })
676 ctx := t.Context()
677 fileContents, _, _, err := client.Repositories.GetContents(ctx, "o", "r", "p", &RepositoryContentGetOptions{})
678 if err != nil {
679 t.Errorf("Repositories.GetContents returned error: %v", err)
680 }
681 want := &RepositoryContent{Type: Ptr("file"), Name: Ptr("LICENSE"), Size: Ptr(20678), Encoding: Ptr("base64"), Path: Ptr("LICENSE")}
682 if !cmp.Equal(fileContents, want) {
683 t.Errorf("Repositories.GetContents returned %+v, want %+v", fileContents, want)
684 }
685
686 const methodName = "GetContents"
687 testBadOptions(t, methodName, func() (err error) {
688 _, _, _, err = client.Repositories.GetContents(ctx, "\n", "\n", "\n", &RepositoryContentGetOptions{})
689 return err
690 })
691
692 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
693 got, _, resp, err := client.Repositories.GetContents(ctx, "o", "r", "p", &RepositoryContentGetOptions{})
694 if got != nil {
695 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
696 }
697 return resp, err
698 })
699}
700
701func TestRepositoriesService_GetContents_FilenameNeedsEscape(t *testing.T) {
702 t.Parallel()

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…