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

Function TestGitService_CreateCommit

github/git_commits_test.go:174–219  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

172}
173
174func TestGitService_CreateCommit(t *testing.T) {
175 t.Parallel()
176 client, mux, _ := setup(t)
177
178 input := Commit{
179 Message: Ptr("Commit Message."),
180 Tree: &Tree{SHA: Ptr("t")},
181 Parents: []*Commit{{SHA: Ptr("p")}},
182 }
183
184 mux.HandleFunc("/repos/o/r/git/commits", func(w http.ResponseWriter, r *http.Request) {
185 testMethod(t, r, "POST")
186 want := createCommit{
187 Message: input.Message,
188 Tree: input.Tree.SHA,
189 Parents: []string{*input.Parents[0].SHA},
190 }
191 testJSONBody(t, r, want)
192 fmt.Fprint(w, `{"sha":"s"}`)
193 })
194
195 ctx := t.Context()
196 commit, _, err := client.Git.CreateCommit(ctx, "o", "r", input, nil)
197 if err != nil {
198 t.Errorf("Git.CreateCommit returned error: %v", err)
199 }
200
201 want := &Commit{SHA: Ptr("s")}
202 if !cmp.Equal(commit, want) {
203 t.Errorf("Git.CreateCommit returned %+v, want %+v", commit, want)
204 }
205
206 const methodName = "CreateCommit"
207 testBadOptions(t, methodName, func() (err error) {
208 _, _, err = client.Git.CreateCommit(ctx, "\n", "\n", input, nil)
209 return err
210 })
211
212 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
213 got, resp, err := client.Git.CreateCommit(ctx, "o", "r", input, nil)
214 if got != nil {
215 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
216 }
217 return resp, err
218 })
219}
220
221func TestGitService_CreateSignedCommit(t *testing.T) {
222 t.Parallel()

Callers

nothing calls this directly

Calls 8

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