Skip to content

Commit

Permalink
test(acceptance): skip rate limit to avoid flaky tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bastean committed Feb 13, 2025
1 parent 8b254d9 commit 73224ca
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions internal/app/server/middleware/limiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"time"

ratelimit "github.com/JGLTechnologies/gin-rate-limit"
"github.com/bastean/codexgo/v4/internal/pkg/service/env"
"github.com/gin-gonic/gin"
)

Expand All @@ -14,6 +15,9 @@ func RateLimiter() gin.HandlerFunc {
&ratelimit.InMemoryOptions{
Rate: time.Second,
Limit: 10,
Skip: func(c *gin.Context) bool {
return env.IsServerGinModeTest()
},
},
),
&ratelimit.Options{
Expand Down
2 changes: 1 addition & 1 deletion internal/app/server/service/captcha/captcha.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func Generate() (*Captcha, error) {
}

func Verify(id, answer string) error {
if !base64Captcha.DefaultMemStore.Verify(id, answer, false) && env.IsNotServerGinModeTest() {
if !base64Captcha.DefaultMemStore.Verify(id, answer, false) && !env.IsServerGinModeTest() {
return errors.New[errors.Failure](&errors.Bubble{
Where: "Verify",
What: "Wrong captcha answer",
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/service/env/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ func HasServerGinProxy() (string, bool) {
return "", false
}

func IsNotServerGinModeTest() bool {
return ServerGinMode != "test"
func IsServerGinModeTest() bool {
return ServerGinMode == "test"
}

0 comments on commit 73224ca

Please sign in to comment.