github.com/google/go-github/v33@v33.0.0/github/gitignore_test.go (about) 1 // Copyright 2013 The go-github AUTHORS. All rights reserved. 2 // 3 // Use of this source code is governed by a BSD-style 4 // license that can be found in the LICENSE file. 5 6 package github 7 8 import ( 9 "context" 10 "fmt" 11 "net/http" 12 "reflect" 13 "testing" 14 ) 15 16 func TestGitignoresService_List(t *testing.T) { 17 client, mux, _, teardown := setup() 18 defer teardown() 19 20 mux.HandleFunc("/gitignore/templates", func(w http.ResponseWriter, r *http.Request) { 21 testMethod(t, r, "GET") 22 fmt.Fprint(w, `["C", "Go"]`) 23 }) 24 25 available, _, err := client.Gitignores.List(context.Background()) 26 if err != nil { 27 t.Errorf("Gitignores.List returned error: %v", err) 28 } 29 30 want := []string{"C", "Go"} 31 if !reflect.DeepEqual(available, want) { 32 t.Errorf("Gitignores.List returned %+v, want %+v", available, want) 33 } 34 } 35 36 func TestGitignoresService_Get(t *testing.T) { 37 client, mux, _, teardown := setup() 38 defer teardown() 39 40 mux.HandleFunc("/gitignore/templates/name", func(w http.ResponseWriter, r *http.Request) { 41 testMethod(t, r, "GET") 42 fmt.Fprint(w, `{"name":"Name","source":"template source"}`) 43 }) 44 45 gitignore, _, err := client.Gitignores.Get(context.Background(), "name") 46 if err != nil { 47 t.Errorf("Gitignores.List returned error: %v", err) 48 } 49 50 want := &Gitignore{Name: String("Name"), Source: String("template source")} 51 if !reflect.DeepEqual(gitignore, want) { 52 t.Errorf("Gitignores.Get returned %+v, want %+v", gitignore, want) 53 } 54 } 55 56 func TestGitignoresService_Get_invalidTemplate(t *testing.T) { 57 client, _, _, teardown := setup() 58 defer teardown() 59 60 _, _, err := client.Gitignores.Get(context.Background(), "%") 61 testURLParseError(t, err) 62 }