package test import ( "fmt" "os" "strings" "testing" "time" "llm-api-benchmark-tool/pkg/report" "llm-api-benchmark-tool/pkg/stats" "github.com/stretchr/testify/assert" ) // createSampleStats creates a sample FinalStats struct for testing. func createSampleStats() stats.FinalStats { return stats.FinalStats{ TotalRequests: 1000, SuccessfulRequests: 950, FailedRequests: 50, TotalDuration: 30 * time.Second, AvgLatency: 150 * time.Millisecond, MinLatency: 50 * time.Millisecond, MaxLatency: 500 * time.Millisecond, P90Latency: 250 * time.Millisecond, P95Latency: 300 * time.Millisecond, P99Latency: 400 * time.Millisecond, AvgTimeToFirstToken: 80 * time.Millisecond, MinTimeToFirstToken: 30 * time.Millisecond, MaxTimeToFirstToken: 200 * time.Millisecond, P90TimeToFirstToken: 120 * time.Millisecond, P95TimeToFirstToken: 150 * time.Millisecond, P99TimeToFirstToken: 180 * time.Millisecond, AvgQPS: 33.33, AvgTokensPerSecond: 500.5, // Add more fields if necessary for report testing } } // TestGenerateHTMLReport tests the basic HTML report generation. func TestGenerateHTMLReport(t *testing.T) { sampleStats := createSampleStats() outputDir := t.TempDir() // Create a temporary directory for the report outputFilePath := outputDir + "/report.html" // Define expected chart IDs (must match IDs set in generator.go) latencyChartID := "latencyHistogram" ttftChartID := "ttftHistogram" // Generate the report err := report.GenerateHTMLReport(sampleStats, outputFilePath) assert.NoError(t, err, "GenerateHTMLReport should not return an error") // Check if the file was created _, err = os.Stat(outputFilePath) assert.NoError(t, err, "HTML report file should be created") // Read the generated file content contentBytes, err := os.ReadFile(outputFilePath) assert.NoError(t, err, "Should be able to read the generated report file") content := string(contentBytes) // Basic checks on the HTML content assert.True(t, strings.HasPrefix(content, ""), "Output should start with DOCTYPE html") assert.Contains(t, content, "