package main import ( "bytes" "encoding/json" "net/http" "testing" "time" ) func TestAPIStatistics(t *testing.T) { // Start server in background go func() { StartAPIServer("3001") }() // Wait for server to start time.Sleep(2 * time.Second) // Make request reqBody := APIStatisticsRequest{ KillmailLimit: &[]int{20}[0], // 20 } jsonData, err := json.Marshal(reqBody) if err != nil { t.Fatalf("Failed to marshal request: %v", err) } start := time.Now() resp, err := http.Post("http://localhost:3001/api/statistics", "application/json", bytes.NewBuffer(jsonData)) queryStart := time.Now() t.Logf("Request sent at: %v", start) t.Logf("Response received at: %v (took %v)", queryStart, queryStart.Sub(start)) if err != nil { t.Fatalf("Failed to make request: %v", err) } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { t.Errorf("Expected status 200, got %d", resp.StatusCode) } var result FitStatistics if err := json.NewDecoder(resp.Body).Decode(&result); err != nil { t.Fatalf("Failed to decode response: %v", err) } t.Logf("Total killmails: %d", result.TotalKillmails) t.Logf("Ships: %d", len(result.ShipBreakdown)) if len(result.ShipBreakdown) > 0 { for id, count := range result.ShipBreakdown { t.Logf("First ship: id=%d, count=%d", id, count) break } } t.Logf("Systems: %d", len(result.SystemBreakdown)) t.Logf("High slots: %d", len(result.HighSlotModules)) t.Logf("Killmail IDs: %d", len(result.KillmailIDs)) totalTime := time.Since(start) t.Logf("Total request time: %v", totalTime) }