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

Function TestGitService_CreateCommit_WithSigner

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

Source from the content-addressed store, hash-verified

291}
292
293func TestGitService_CreateCommit_WithSigner(t *testing.T) {
294 t.Parallel()
295 client, mux, _ := setup(t)
296
297 signature := "my voice is my password"
298 date := time.Date(2017, time.May, 4, 0, 3, 43, 0, time.FixedZone("CEST", 2*3600))
299 author := CommitAuthor{
300 Name: Ptr("go-github"),
301 Email: Ptr("go-github@github.com"),
302 Date: &Timestamp{date},
303 }
304 wantMessage := `tree t
305parent p
306author go-github <go-github@github.com> 1493849023 +0200
307committer go-github <go-github@github.com> 1493849023 +0200
308
309Commit Message.`
310 sha := "commitSha"
311 input := Commit{
312 SHA: &sha,
313 Message: Ptr("Commit Message."),
314 Tree: &Tree{SHA: Ptr("t")},
315 Parents: []*Commit{{SHA: Ptr("p")}},
316 Author: &author,
317 }
318 wantBody := createCommit{
319 Message: input.Message,
320 Tree: Ptr("t"),
321 Parents: []string{"p"},
322 Author: &author,
323 Signature: &signature,
324 }
325 var gotBody createCommit
326 mux.HandleFunc("/repos/o/r/git/commits", func(w http.ResponseWriter, r *http.Request) {
327 assertNilError(t, json.NewDecoder(r.Body).Decode(&gotBody))
328 testMethod(t, r, "POST")
329 fmt.Fprintf(w, `{"sha":"%v"}`, sha)
330 })
331 ctx := t.Context()
332 wantCommit := &Commit{SHA: &sha}
333 opts := CreateCommitOptions{Signer: mockSigner(t, signature, nil, wantMessage)}
334 commit, _, err := client.Git.CreateCommit(ctx, "o", "r", input, &opts)
335 assertNilError(t, err)
336 if cmp.Diff(gotBody, wantBody) != "" {
337 t.Errorf("Request body = %+v, want %+v\n%v", gotBody, wantBody, cmp.Diff(gotBody, wantBody))
338 }
339 if cmp.Diff(commit, wantCommit) != "" {
340 t.Errorf("Git.CreateCommit returned %+v, want %+v\n%v", commit, wantCommit, cmp.Diff(commit, wantCommit))
341 }
342}
343
344func TestGitService_createSignature_nilSigner(t *testing.T) {
345 t.Parallel()

Callers

nothing calls this directly

Calls 6

testMethodFunction · 0.85
mockSignerFunction · 0.85
CreateCommitMethod · 0.80
setupFunction · 0.70
PtrFunction · 0.70
assertNilErrorFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…