TestCreateTaskHandler tests the create task endpoint
(t *testing.T)
| 25 | |
| 26 | // TestCreateTaskHandler tests the create task endpoint |
| 27 | func TestCreateTaskHandler(t *testing.T) { |
| 28 | handlers, _ := setupTestServer(t) |
| 29 | |
| 30 | tests := []struct { |
| 31 | name string |
| 32 | method string |
| 33 | body any |
| 34 | wantStatus int |
| 35 | wantErr bool |
| 36 | }{ |
| 37 | { |
| 38 | name: "Method not allowed", |
| 39 | method: http.MethodGet, |
| 40 | body: nil, |
| 41 | wantStatus: http.StatusMethodNotAllowed, |
| 42 | wantErr: true, |
| 43 | }, |
| 44 | { |
| 45 | name: "Invalid JSON body", |
| 46 | method: http.MethodPost, |
| 47 | body: "invalid json", |
| 48 | wantStatus: http.StatusBadRequest, |
| 49 | wantErr: true, |
| 50 | }, |
| 51 | { |
| 52 | name: "Empty request body", |
| 53 | method: http.MethodPost, |
| 54 | body: CreateTaskRequest{}, |
| 55 | // Will fail validation for missing type |
| 56 | wantStatus: http.StatusBadRequest, |
| 57 | wantErr: true, |
| 58 | }, |
| 59 | { |
| 60 | name: "Missing type", |
| 61 | method: http.MethodPost, |
| 62 | body: CreateTaskRequest{ |
| 63 | Storage: "test-storage", |
| 64 | Path: "downloads", |
| 65 | }, |
| 66 | wantStatus: http.StatusBadRequest, |
| 67 | wantErr: true, |
| 68 | }, |
| 69 | { |
| 70 | name: "Missing storage", |
| 71 | method: http.MethodPost, |
| 72 | body: CreateTaskRequest{ |
| 73 | Type: tasktype.TaskTypeDirectlinks, |
| 74 | Path: "downloads", |
| 75 | }, |
| 76 | wantStatus: http.StatusBadRequest, |
| 77 | wantErr: true, |
| 78 | }, |
| 79 | { |
| 80 | name: "Storage not found", |
| 81 | method: http.MethodPost, |
| 82 | body: CreateTaskRequest{ |
| 83 | Type: tasktype.TaskTypeDirectlinks, |
| 84 | Storage: "non-existent-storage", |
nothing calls this directly
no test coverage detected