(t *testing.T)
| 335 | } |
| 336 | |
| 337 | func TestGitService_CreateRef(t *testing.T) { |
| 338 | t.Parallel() |
| 339 | client, mux, _ := setup(t) |
| 340 | |
| 341 | args := CreateRef{ |
| 342 | Ref: "refs/heads/b", |
| 343 | SHA: "aa218f56b14c9653891f9e74264a383fa43fefbd", |
| 344 | } |
| 345 | |
| 346 | mux.HandleFunc("/repos/o/r/git/refs", func(w http.ResponseWriter, r *http.Request) { |
| 347 | testMethod(t, r, "POST") |
| 348 | testJSONBody(t, r, args) |
| 349 | fmt.Fprint(w, ` |
| 350 | { |
| 351 | "ref": "refs/heads/b", |
| 352 | "url": "https://api.github.com/repos/o/r/git/refs/heads/b", |
| 353 | "object": { |
| 354 | "type": "commit", |
| 355 | "sha": "aa218f56b14c9653891f9e74264a383fa43fefbd", |
| 356 | "url": "https://api.github.com/repos/o/r/git/commits/aa218f56b14c9653891f9e74264a383fa43fefbd" |
| 357 | } |
| 358 | }`) |
| 359 | }) |
| 360 | |
| 361 | ctx := t.Context() |
| 362 | ref, _, err := client.Git.CreateRef(ctx, "o", "r", CreateRef{ |
| 363 | Ref: "refs/heads/b", |
| 364 | SHA: "aa218f56b14c9653891f9e74264a383fa43fefbd", |
| 365 | }) |
| 366 | if err != nil { |
| 367 | t.Errorf("Git.CreateRef returned error: %v", err) |
| 368 | } |
| 369 | |
| 370 | want := &Reference{ |
| 371 | Ref: Ptr("refs/heads/b"), |
| 372 | URL: Ptr("https://api.github.com/repos/o/r/git/refs/heads/b"), |
| 373 | Object: &GitObject{ |
| 374 | Type: Ptr("commit"), |
| 375 | SHA: Ptr("aa218f56b14c9653891f9e74264a383fa43fefbd"), |
| 376 | URL: Ptr("https://api.github.com/repos/o/r/git/commits/aa218f56b14c9653891f9e74264a383fa43fefbd"), |
| 377 | }, |
| 378 | } |
| 379 | if !cmp.Equal(ref, want) { |
| 380 | t.Errorf("Git.CreateRef returned %+v, want %+v", ref, want) |
| 381 | } |
| 382 | |
| 383 | // without 'refs/' prefix |
| 384 | _, _, err = client.Git.CreateRef(ctx, "o", "r", CreateRef{ |
| 385 | Ref: "heads/b", |
| 386 | SHA: "aa218f56b14c9653891f9e74264a383fa43fefbd", |
| 387 | }) |
| 388 | if err != nil { |
| 389 | t.Errorf("Git.CreateRef returned error: %v", err) |
| 390 | } |
| 391 | |
| 392 | const methodName = "CreateRef" |
| 393 | testBadOptions(t, methodName, func() (err error) { |
| 394 | _, _, err = client.Git.CreateRef(ctx, "o", "r", CreateRef{Ref: ""}) |
nothing calls this directly
no test coverage detected
searching dependent graphs…