2026-10-08 07:36:33 +02:00
|
|
|
package handler
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
|
2026-11-07 18:02:59 +01:00
|
|
|
"github.com/git-pkgs/proxy/internal/metadata/npm/npmbench"
|
|
|
|
|
)
|
2026-10-08 07:36:33 +02:00
|
|
|
|
|
|
|
|
func BenchmarkNPMRewriteMetadata(b *testing.B) {
|
2026-11-07 18:02:59 +01:00
|
|
|
body := npmbench.Packument(5000)
|
2026-10-08 07:36:33 +02:00
|
|
|
h := &NPMHandler{proxy: testProxy(), proxyURL: "http://proxy.example"}
|
|
|
|
|
b.SetBytes(int64(len(body)))
|
|
|
|
|
b.ReportAllocs()
|
|
|
|
|
for b.Loop() {
|
2026-10-25 22:19:24 +01:00
|
|
|
if _, _, err := h.rewriteMetadataKeeping("big", body); err != nil {
|
2026-10-08 07:36:33 +02:00
|
|
|
b.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func BenchmarkNPMVersionTarball(b *testing.B) {
|
2026-11-07 18:02:59 +01:00
|
|
|
body := npmbench.Packument(5000)
|
2026-10-08 07:36:33 +02:00
|
|
|
b.SetBytes(int64(len(body)))
|
|
|
|
|
b.ReportAllocs()
|
|
|
|
|
for b.Loop() {
|
|
|
|
|
if npmVersionTarball(body, "1.0.2500") == "" {
|
|
|
|
|
b.Fatal("tarball not found")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|