| 217 | } |
| 218 | |
| 219 | func TestFeedback_RateLimit(t *testing.T) { |
| 220 | server, _, _ := setupAPI(t) |
| 221 | |
| 222 | // Send 10 requests (the limit) |
| 223 | for i := 0; i < 10; i++ { |
| 224 | payload := fmt.Sprintf(`{"message":"feedback %d"}`, i) |
| 225 | resp, _ := http.Post(server.URL+"/api/feedback", "application/json", bytes.NewBufferString(payload)) |
| 226 | resp.Body.Close() |
| 227 | if resp.StatusCode != 200 { |
| 228 | t.Fatalf("request %d: status = %d, want 200", i, resp.StatusCode) |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | // 11th request should be rate limited |
| 233 | resp, _ := http.Post(server.URL+"/api/feedback", "application/json", bytes.NewBufferString(`{"message":"one too many"}`)) |
| 234 | defer resp.Body.Close() |
| 235 | |
| 236 | if resp.StatusCode != 429 { |
| 237 | t.Errorf("status = %d, want 429 for rate-limited request", resp.StatusCode) |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | func TestFeedback_OptionalEmail(t *testing.T) { |
| 242 | server, _, _ := setupAPI(t) |