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

Function TestRepositoriesService_CreateFile

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

Source from the content-addressed store, hash-verified

791}
792
793func TestRepositoriesService_CreateFile(t *testing.T) {
794 t.Parallel()
795 client, mux, _ := setup(t)
796
797 mux.HandleFunc("/repos/o/r/contents/p", func(w http.ResponseWriter, r *http.Request) {
798 testMethod(t, r, "PUT")
799 fmt.Fprint(w, `{
800 "content":{
801 "name":"p"
802 },
803 "commit":{
804 "message":"m",
805 "sha":"f5f369044773ff9c6383c087466d12adb6fa0828"
806 }
807 }`)
808 })
809 message := "m"
810 content := []byte("c")
811 repositoryContentsOptions := &RepositoryContentFileOptions{
812 Message: &message,
813 Content: content,
814 Committer: &CommitAuthor{Name: Ptr("n"), Email: Ptr("e")},
815 }
816 ctx := t.Context()
817 createResponse, _, err := client.Repositories.CreateFile(ctx, "o", "r", "p", repositoryContentsOptions)
818 if err != nil {
819 t.Errorf("Repositories.CreateFile returned error: %v", err)
820 }
821 want := &RepositoryContentResponse{
822 Content: &RepositoryContent{Name: Ptr("p")},
823 Commit: Commit{
824 Message: Ptr("m"),
825 SHA: Ptr("f5f369044773ff9c6383c087466d12adb6fa0828"),
826 },
827 }
828 if !cmp.Equal(createResponse, want) {
829 t.Errorf("Repositories.CreateFile returned %+v, want %+v", createResponse, want)
830 }
831
832 const methodName = "CreateFile"
833 testBadOptions(t, methodName, func() (err error) {
834 _, _, err = client.Repositories.CreateFile(ctx, "\n", "\n", "\n", repositoryContentsOptions)
835 return err
836 })
837
838 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
839 got, resp, err := client.Repositories.CreateFile(ctx, "o", "r", "p", repositoryContentsOptions)
840 if got != nil {
841 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
842 }
843 return resp, err
844 })
845}
846
847func TestRepositoriesService_UpdateFile(t *testing.T) {
848 t.Parallel()

Callers

nothing calls this directly

Calls 7

testMethodFunction · 0.85
testBadOptionsFunction · 0.85
CreateFileMethod · 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…