@@ -127,10 +127,66 @@ func TestRepositoriesService_GetReadme(t *testing.T) {
127127 })
128128}
129129
130- func TestRepositoriesService_DownloadContents_Success (t * testing.T ) {
130+ func TestRepositoriesService_DownloadContents_SuccessForFile (t * testing.T ) {
131131 t .Parallel ()
132132 client , mux , serverURL := setup (t )
133133
134+ mux .HandleFunc ("/repos/o/r/contents/d/f" , func (w http.ResponseWriter , r * http.Request ) {
135+ testMethod (t , r , "GET" )
136+ fmt .Fprint (w , `{
137+ "type": "file",
138+ "name": "f",
139+ "content": "foo",
140+ "download_url": "` + serverURL + baseURLPath + `/download/f"
141+ }` )
142+ })
143+
144+ ctx := context .Background ()
145+ r , resp , err := client .Repositories .DownloadContents (ctx , "o" , "r" , "d/f" , nil )
146+ if err != nil {
147+ t .Errorf ("Repositories.DownloadContents returned error: %v" , err )
148+ }
149+
150+ if got , want := resp .Response .StatusCode , http .StatusOK ; got != want {
151+ t .Errorf ("Repositories.DownloadContents returned status code %v, want %v" , got , want )
152+ }
153+
154+ bytes , err := io .ReadAll (r )
155+ if err != nil {
156+ t .Errorf ("Error reading response body: %v" , err )
157+ }
158+ r .Close ()
159+
160+ if got , want := string (bytes ), "foo" ; got != want {
161+ t .Errorf ("Repositories.DownloadContents returned %v, want %v" , got , want )
162+ }
163+
164+ const methodName = "DownloadContents"
165+ testBadOptions (t , methodName , func () (err error ) {
166+ _ , _ , err = client .Repositories .DownloadContents (ctx , "\n " , "\n " , "\n " , nil )
167+ return err
168+ })
169+
170+ testNewRequestAndDoFailure (t , methodName , client , func () (* Response , error ) {
171+ got , resp , err := client .Repositories .DownloadContents (ctx , "o" , "r" , "d/f" , nil )
172+ if got != nil {
173+ t .Errorf ("testNewRequestAndDoFailure %v = %#v, want nil" , methodName , got )
174+ }
175+ return resp , err
176+ })
177+ }
178+
179+ func TestRepositoriesService_DownloadContents_SuccessForDirectory (t * testing.T ) {
180+ t .Parallel ()
181+ client , mux , serverURL := setup (t )
182+
183+ mux .HandleFunc ("/repos/o/r/contents/d/f" , func (w http.ResponseWriter , r * http.Request ) {
184+ testMethod (t , r , "GET" )
185+ fmt .Fprint (w , `{
186+ "type": "file",
187+ "name": "f"
188+ }` )
189+ })
134190 mux .HandleFunc ("/repos/o/r/contents/d" , func (w http.ResponseWriter , r * http.Request ) {
135191 testMethod (t , r , "GET" )
136192 fmt .Fprint (w , `[{
@@ -183,6 +239,13 @@ func TestRepositoriesService_DownloadContents_FailedResponse(t *testing.T) {
183239 t .Parallel ()
184240 client , mux , serverURL := setup (t )
185241
242+ mux .HandleFunc ("/repos/o/r/contents/d/f" , func (w http.ResponseWriter , r * http.Request ) {
243+ testMethod (t , r , "GET" )
244+ fmt .Fprint (w , `{
245+ "type": "file",
246+ "name": "f"
247+ }` )
248+ })
186249 mux .HandleFunc ("/repos/o/r/contents/d" , func (w http.ResponseWriter , r * http.Request ) {
187250 testMethod (t , r , "GET" )
188251 fmt .Fprint (w , `[{
@@ -222,6 +285,14 @@ func TestRepositoriesService_DownloadContents_NoDownloadURL(t *testing.T) {
222285 t .Parallel ()
223286 client , mux , _ := setup (t )
224287
288+ mux .HandleFunc ("/repos/o/r/contents/d/f" , func (w http.ResponseWriter , r * http.Request ) {
289+ testMethod (t , r , "GET" )
290+ fmt .Fprint (w , `{
291+ "type": "file",
292+ "name": "f",
293+ "content": ""
294+ }` )
295+ })
225296 mux .HandleFunc ("/repos/o/r/contents/d" , func (w http.ResponseWriter , r * http.Request ) {
226297 testMethod (t , r , "GET" )
227298 fmt .Fprint (w , `[{
0 commit comments