-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdampener_test.go
More file actions
36 lines (32 loc) · 943 Bytes
/
Copy pathdampener_test.go
File metadata and controls
36 lines (32 loc) · 943 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright 2015 - husobee associates, llc; all rights reserved.
// Package dampener - A toolkit to apply throttling to web applications
package dampener_test
import (
"net/http"
"testing"
"time"
"github.com/husobee/dampener"
. "github.com/smartystreets/goconvey/convey"
)
func TestNewThrottler(t *testing.T) {
Convey("Test creating a NewThrottle", t, func() {
throttle := dampener.NewThrottle(
dampener.NewThrottleOptions(
"IPAddress", 100, 1*time.Minute,
func(r *http.Request) bool {
return true
},
dampener.NewMemoryStorage()))
Convey("set add event ot storage", func() {
req, _ := http.NewRequest("GET", "/", nil)
for i := 0; i < 100; i++ {
throttle.AppendEvent(req)
}
beingThrottled, _ := throttle.ShouldThrottle(req)
So(beingThrottled, ShouldBeFalse)
throttle.AppendEvent(req)
beingThrottled, _ = throttle.ShouldThrottle(req)
So(beingThrottled, ShouldBeTrue)
})
})
}