mirror of
https://github.com/danielmiessler/Fabric.git
synced 2026-01-09 22:38:10 -05:00
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:
@@ -416,7 +416,7 @@ func TestGetValidTokenWithValidToken(t *testing.T) {
|
|||||||
|
|
||||||
// Benchmark tests
|
// Benchmark tests
|
||||||
func BenchmarkGeneratePKCE(b *testing.B) {
|
func BenchmarkGeneratePKCE(b *testing.B) {
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
_, _, err := generatePKCE()
|
_, _, err := generatePKCE()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
@@ -427,8 +427,7 @@ func BenchmarkGeneratePKCE(b *testing.B) {
|
|||||||
func BenchmarkTokenIsExpired(b *testing.B) {
|
func BenchmarkTokenIsExpired(b *testing.B) {
|
||||||
token := createTestToken("access", "refresh", 3600)
|
token := createTestToken("access", "refresh", 3600)
|
||||||
|
|
||||||
b.ResetTimer()
|
for b.Loop() {
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
token.IsExpired(5)
|
token.IsExpired(5)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package restapi
|
package restapi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"maps"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/danielmiessler/fabric/internal/plugins/db/fsdb"
|
"github.com/danielmiessler/fabric/internal/plugins/db/fsdb"
|
||||||
@@ -74,9 +75,7 @@ func (h *PatternsHandler) ApplyPattern(c *gin.Context) {
|
|||||||
variables[key] = values[0]
|
variables[key] = values[0]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for key, value := range request.Variables {
|
maps.Copy(variables, request.Variables)
|
||||||
variables[key] = value
|
|
||||||
}
|
|
||||||
|
|
||||||
pattern, err := h.patterns.GetApplyVariables(name, variables, request.Input)
|
pattern, err := h.patterns.GetApplyVariables(name, variables, request.Input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user