()
| 17 | ) |
| 18 | |
| 19 | func docsCreateCopyCatHandler() http.Handler { |
| 20 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 21 | path := r.URL.Path |
| 22 | drivePath := strings.TrimPrefix(path, "/drive/v3") |
| 23 | switch { |
| 24 | case strings.HasPrefix(path, "/v1/documents/") && r.Method == http.MethodGet: |
| 25 | id := strings.TrimPrefix(path, "/v1/documents/") |
| 26 | w.Header().Set("Content-Type", "application/json") |
| 27 | _ = json.NewEncoder(w).Encode(map[string]any{ |
| 28 | "documentId": id, |
| 29 | "title": "Doc", |
| 30 | "body": map[string]any{"content": []any{map[string]any{ |
| 31 | "paragraph": map[string]any{"elements": []any{map[string]any{ |
| 32 | "textRun": map[string]any{"content": "doc text"}, |
| 33 | }}}, |
| 34 | }}}, |
| 35 | }) |
| 36 | case strings.HasPrefix(drivePath, "/files/") && r.Method == http.MethodGet: |
| 37 | w.Header().Set("Content-Type", "application/json") |
| 38 | _ = json.NewEncoder(w).Encode(map[string]any{ |
| 39 | "id": "doc1", "mimeType": "application/vnd.google-apps.document", |
| 40 | }) |
| 41 | case drivePath == "/files" && r.Method == http.MethodPost: |
| 42 | w.Header().Set("Content-Type", "application/json") |
| 43 | _ = json.NewEncoder(w).Encode(map[string]any{ |
| 44 | "id": "doc1", "name": "Doc", "mimeType": "application/vnd.google-apps.document", |
| 45 | "webViewLink": "http://example.com/doc1", |
| 46 | }) |
| 47 | case strings.Contains(drivePath, "/files/doc1/copy") && r.Method == http.MethodPost: |
| 48 | w.Header().Set("Content-Type", "application/json") |
| 49 | _ = json.NewEncoder(w).Encode(map[string]any{ |
| 50 | "id": "doc2", "name": "Copy", "mimeType": "application/vnd.google-apps.document", |
| 51 | "webViewLink": "http://example.com/doc2", |
| 52 | }) |
| 53 | default: |
| 54 | http.NotFound(w, r) |
| 55 | } |
| 56 | }) |
| 57 | } |
| 58 | |
| 59 | func TestDocsCreateCopyCat_JSON(t *testing.T) { |
| 60 | t.Parallel() |
no test coverage detected