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

Function TestGistsService_Create

github/gists_test.go:475–536  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

473}
474
475func TestGistsService_Create(t *testing.T) {
476 t.Parallel()
477 client, mux, _ := setup(t)
478
479 input := &Gist{
480 Description: Ptr("Gist description"),
481 Public: Ptr(false),
482 Files: map[GistFilename]GistFile{
483 "test.txt": {Content: Ptr("Gist file content")},
484 },
485 }
486
487 mux.HandleFunc("/gists", func(w http.ResponseWriter, r *http.Request) {
488 var v *Gist
489 assertNilError(t, json.NewDecoder(r.Body).Decode(&v))
490
491 testMethod(t, r, "POST")
492 if !cmp.Equal(v, input) {
493 t.Errorf("Request body = %+v, want %+v", v, input)
494 }
495
496 fmt.Fprint(w,
497 `
498 {
499 "id": "1",
500 "description": "Gist description",
501 "public": false,
502 "files": {
503 "test.txt": {
504 "filename": "test.txt"
505 }
506 }
507 }`)
508 })
509
510 ctx := t.Context()
511 gist, _, err := client.Gists.Create(ctx, input)
512 if err != nil {
513 t.Errorf("Gists.Create returned error: %v", err)
514 }
515
516 want := &Gist{
517 ID: Ptr("1"),
518 Description: Ptr("Gist description"),
519 Public: Ptr(false),
520 Files: map[GistFilename]GistFile{
521 "test.txt": {Filename: Ptr("test.txt")},
522 },
523 }
524 if !cmp.Equal(gist, want) {
525 t.Errorf("Gists.Create returned %+v, want %+v", gist, want)
526 }
527
528 const methodName = "Create"
529 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
530 got, resp, err := client.Gists.Create(ctx, input)
531 if got != nil {
532 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)

Callers

nothing calls this directly

Calls 7

testMethodFunction · 0.85
EqualMethod · 0.80
setupFunction · 0.70
PtrFunction · 0.70
assertNilErrorFunction · 0.70
CreateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…