(t *testing.T)
| 165 | } |
| 166 | |
| 167 | func TestDownloadDriveFile_HTTPError(t *testing.T) { |
| 168 | download := func(context.Context, *drive.Service, string) (*http.Response, error) { |
| 169 | return &http.Response{ |
| 170 | Status: "403 Forbidden", |
| 171 | StatusCode: http.StatusForbidden, |
| 172 | Body: io.NopCloser(strings.NewReader("nope\n")), |
| 173 | }, nil |
| 174 | } |
| 175 | |
| 176 | tmp := t.TempDir() |
| 177 | dest := filepath.Join(tmp, "file.bin") |
| 178 | ctx := withDriveTestOperations(context.Background(), &drive.Service{}, download, nil) |
| 179 | _, _, err := downloadDriveFile(ctx, &drive.Service{}, &drive.File{Id: "id1", MimeType: "application/pdf"}, dest, "", false) |
| 180 | if err == nil { |
| 181 | t.Fatalf("expected error") |
| 182 | } |
| 183 | if !strings.Contains(err.Error(), "download failed") || !strings.Contains(err.Error(), "nope") { |
| 184 | t.Fatalf("unexpected error: %v", err) |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | func TestDownloadDriveFile_CreatesMissingParentDirs(t *testing.T) { |
| 189 | download := func(context.Context, *drive.Service, string) (*http.Response, error) { |
nothing calls this directly
no test coverage detected