test: update benchmarks to use b.Loop and refactor map copying

# CHANGES

- update benchmark loops to use cleaner `b.Loop()` syntax
- remove unnecessary `b.ResetTimer()` call in token benchmark
- use `maps.Copy` for merging variables in patterns handler
This commit is contained in:
Kayvan Sylvan
2025-12-15 22:40:55 -08:00
parent 98038707f1
commit dccdfbac8c
2 changed files with 4 additions and 6 deletions

View File

@@ -416,7 +416,7 @@ func TestGetValidTokenWithValidToken(t *testing.T) {
// Benchmark tests
func BenchmarkGeneratePKCE(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
_, _, err := generatePKCE()
if err != nil {
b.Fatal(err)
@@ -427,8 +427,7 @@ func BenchmarkGeneratePKCE(b *testing.B) {
func BenchmarkTokenIsExpired(b *testing.B) {
token := createTestToken("access", "refresh", 3600)
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
token.IsExpired(5)
}
}

View File

@@ -1,6 +1,7 @@
package restapi
import (
"maps"
"net/http"
"github.com/danielmiessler/fabric/internal/plugins/db/fsdb"
@@ -74,9 +75,7 @@ func (h *PatternsHandler) ApplyPattern(c *gin.Context) {
variables[key] = values[0]
}
}
for key, value := range request.Variables {
variables[key] = value
}
maps.Copy(variables, request.Variables)
pattern, err := h.patterns.GetApplyVariables(name, variables, request.Input)
if err != nil {