(t *testing.T)
| 291 | } |
| 292 | |
| 293 | func 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 |
| 305 | parent p |
| 306 | author go-github <go-github@github.com> 1493849023 +0200 |
| 307 | committer go-github <go-github@github.com> 1493849023 +0200 |
| 308 | |
| 309 | Commit 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 | |
| 344 | func TestGitService_createSignature_nilSigner(t *testing.T) { |
| 345 | t.Parallel() |
nothing calls this directly
no test coverage detected
searching dependent graphs…