2025-11-20 18:05:45 +00:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"net/http"
|
|
|
|
|
"net/http/httptest"
|
|
|
|
|
"testing"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// BenchmarkHome benchmarks the Home handler
|
|
|
|
|
func BenchmarkHome(b *testing.B) {
|
2025-12-06 15:57:23 +00:00
|
|
|
handler := newTestCVHandler(b, "localhost:8080", nil)
|
2025-11-20 18:05:45 +00:00
|
|
|
|
|
|
|
|
b.ResetTimer()
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
|
req := httptest.NewRequest(http.MethodGet, "/?lang=en", nil)
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
handler.Home(w, req)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// BenchmarkCVContent benchmarks the CVContent handler
|
|
|
|
|
func BenchmarkCVContent(b *testing.B) {
|
2025-12-06 15:57:23 +00:00
|
|
|
handler := newTestCVHandler(b, "localhost:8080", nil)
|
2025-11-20 18:05:45 +00:00
|
|
|
|
|
|
|
|
b.ResetTimer()
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
|
req := httptest.NewRequest(http.MethodGet, "/cv?lang=en", nil)
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
handler.CVContent(w, req)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// BenchmarkToggleLength benchmarks the ToggleLength handler
|
|
|
|
|
func BenchmarkToggleLength(b *testing.B) {
|
2025-12-06 15:57:23 +00:00
|
|
|
handler := newTestCVHandler(b, "localhost:8080", nil)
|
2025-11-20 18:05:45 +00:00
|
|
|
|
|
|
|
|
b.ResetTimer()
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
|
req := httptest.NewRequest(http.MethodPost, "/toggle-length", nil)
|
|
|
|
|
req.AddCookie(&http.Cookie{Name: "cv-length", Value: "short"})
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
handler.ToggleLength(w, req)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// BenchmarkParsePDFExportRequest benchmarks request parsing
|
|
|
|
|
func BenchmarkParsePDFExportRequest(b *testing.B) {
|
|
|
|
|
req := httptest.NewRequest(http.MethodGet, "/export-pdf?lang=en&length=long&icons=show&version=with_skills", nil)
|
|
|
|
|
|
|
|
|
|
b.ResetTimer()
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
|
_, err := ParsePDFExportRequest(req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
b.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// BenchmarkPrepareTemplateData benchmarks template data preparation
|
|
|
|
|
func BenchmarkPrepareTemplateData(b *testing.B) {
|
2025-12-06 15:57:23 +00:00
|
|
|
handler := newTestCVHandler(b, "localhost:8080", nil)
|
2025-11-20 18:05:45 +00:00
|
|
|
|
|
|
|
|
b.ResetTimer()
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
|
_, err := handler.prepareTemplateData("en")
|
|
|
|
|
if err != nil {
|
|
|
|
|
b.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// BenchmarkResponseTypes benchmarks response creation
|
|
|
|
|
func BenchmarkSuccessResponse(b *testing.B) {
|
|
|
|
|
data := map[string]interface{}{
|
|
|
|
|
"status": "ok",
|
|
|
|
|
"count": 100,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
b.ResetTimer()
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
|
_ = SuccessResponse(data)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func BenchmarkNewErrorResponse(b *testing.B) {
|
|
|
|
|
b.ResetTimer()
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
|
_ = NewErrorResponse("INVALID_INPUT", "Invalid request parameter")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// BenchmarkParallelHome benchmarks Home handler under parallel load
|
|
|
|
|
func BenchmarkParallelHome(b *testing.B) {
|
2025-12-06 15:57:23 +00:00
|
|
|
handler := newTestCVHandler(b, "localhost:8080", nil)
|
2025-11-20 18:05:45 +00:00
|
|
|
|
|
|
|
|
b.ResetTimer()
|
|
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
|
|
|
for pb.Next() {
|
|
|
|
|
req := httptest.NewRequest(http.MethodGet, "/?lang=en", nil)
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
handler.Home(w, req)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// BenchmarkParallelToggleLength benchmarks toggle under parallel load
|
|
|
|
|
func BenchmarkParallelToggleLength(b *testing.B) {
|
2025-12-06 15:57:23 +00:00
|
|
|
handler := newTestCVHandler(b, "localhost:8080", nil)
|
2025-11-20 18:05:45 +00:00
|
|
|
|
|
|
|
|
b.ResetTimer()
|
|
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
|
|
|
for pb.Next() {
|
|
|
|
|
req := httptest.NewRequest(http.MethodPost, "/toggle-length", nil)
|
|
|
|
|
req.AddCookie(&http.Cookie{Name: "cv-length", Value: "short"})
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
handler.ToggleLength(w, req)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|