(t *testing.T)
| 219 | } |
| 220 | |
| 221 | func TestGitService_CreateSignedCommit(t *testing.T) { |
| 222 | t.Parallel() |
| 223 | client, mux, _ := setup(t) |
| 224 | |
| 225 | signature := "----- BEGIN PGP SIGNATURE -----\n\naaaa\naaaa\n----- END PGP SIGNATURE -----" |
| 226 | |
| 227 | input := Commit{ |
| 228 | Message: Ptr("Commit Message."), |
| 229 | Tree: &Tree{SHA: Ptr("t")}, |
| 230 | Parents: []*Commit{{SHA: Ptr("p")}}, |
| 231 | Verification: &SignatureVerification{ |
| 232 | Signature: &signature, |
| 233 | }, |
| 234 | } |
| 235 | |
| 236 | mux.HandleFunc("/repos/o/r/git/commits", func(w http.ResponseWriter, r *http.Request) { |
| 237 | testMethod(t, r, "POST") |
| 238 | want := struct { |
| 239 | Message *string `json:"message,omitempty"` |
| 240 | Tree *string `json:"tree,omitempty"` |
| 241 | Parents []string `json:"parents,omitempty"` |
| 242 | Signature *string `json:"signature,omitempty"` |
| 243 | }{ |
| 244 | Message: input.Message, |
| 245 | Tree: input.Tree.SHA, |
| 246 | Parents: []string{*input.Parents[0].SHA}, |
| 247 | Signature: input.Verification.Signature, |
| 248 | } |
| 249 | testJSONBody(t, r, want) |
| 250 | fmt.Fprint(w, `{"sha":"commitSha"}`) |
| 251 | }) |
| 252 | |
| 253 | ctx := t.Context() |
| 254 | commit, _, err := client.Git.CreateCommit(ctx, "o", "r", input, nil) |
| 255 | if err != nil { |
| 256 | t.Errorf("Git.CreateCommit returned error: %v", err) |
| 257 | } |
| 258 | |
| 259 | want := &Commit{SHA: Ptr("commitSha")} |
| 260 | if !cmp.Equal(commit, want) { |
| 261 | t.Errorf("Git.CreateCommit returned %+v, want %+v", commit, want) |
| 262 | } |
| 263 | |
| 264 | const methodName = "CreateCommit" |
| 265 | testBadOptions(t, methodName, func() (err error) { |
| 266 | _, _, err = client.Git.CreateCommit(ctx, "\n", "\n", input, nil) |
| 267 | return err |
| 268 | }) |
| 269 | |
| 270 | testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { |
| 271 | got, resp, err := client.Git.CreateCommit(ctx, "o", "r", input, nil) |
| 272 | if got != nil { |
| 273 | t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) |
| 274 | } |
| 275 | return resp, err |
| 276 | }) |
| 277 | } |
| 278 |
nothing calls this directly
no test coverage detected
searching dependent graphs…