summaryrefslogtreecommitdiffstats
path: root/vendor/gopkg.in/throttled/throttled.v1/store/mem_test.go
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2016-05-12 23:56:07 -0400
committerChristopher Speller <crspeller@gmail.com>2016-05-12 23:56:07 -0400
commit38ee83e45b4de7edf89bf9f0ef629eb4c6ad0fa8 (patch)
treea4fde09672192b97d453ad605b030bd5a10c5a45 /vendor/gopkg.in/throttled/throttled.v1/store/mem_test.go
parent84d2482ddbff9564c9ad75b2d30af66e3ddfd44d (diff)
downloadchat-38ee83e45b4de7edf89bf9f0ef629eb4c6ad0fa8.tar.gz
chat-38ee83e45b4de7edf89bf9f0ef629eb4c6ad0fa8.tar.bz2
chat-38ee83e45b4de7edf89bf9f0ef629eb4c6ad0fa8.zip
Moving to glide
Diffstat (limited to 'vendor/gopkg.in/throttled/throttled.v1/store/mem_test.go')
-rw-r--r--vendor/gopkg.in/throttled/throttled.v1/store/mem_test.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/vendor/gopkg.in/throttled/throttled.v1/store/mem_test.go b/vendor/gopkg.in/throttled/throttled.v1/store/mem_test.go
new file mode 100644
index 000000000..e8ef8d0da
--- /dev/null
+++ b/vendor/gopkg.in/throttled/throttled.v1/store/mem_test.go
@@ -0,0 +1,43 @@
+package store
+
+import (
+ "testing"
+ "time"
+)
+
+func TestMemStore(t *testing.T) {
+ st := NewMemStore(0)
+ win := time.Second
+
+ // Reset stores a key with count of 1, current timestamp
+ err := st.Reset("k", time.Second)
+ if err != nil {
+ t.Errorf("expected reset to return nil, got %s", err)
+ }
+ cnt, sec1, _ := st.Incr("k", win)
+ if cnt != 2 {
+ t.Errorf("expected reset+incr to set count to 2, got %d", cnt)
+ }
+
+ // Incr increments the key, keeps same timestamp
+ cnt, sec2, err := st.Incr("k", win)
+ if err != nil {
+ t.Errorf("expected 2nd incr to return nil error, got %s", err)
+ }
+ if cnt != 3 {
+ t.Errorf("expected 2nd incr to return 3, got %d", cnt)
+ }
+ if sec1 != sec2 {
+ t.Errorf("expected 2nd incr to return %d secs, got %d", sec1, sec2)
+ }
+
+ // Reset on existing key brings it back to 1, new timestamp
+ err = st.Reset("k", win)
+ if err != nil {
+ t.Errorf("expected reset on existing key to return nil, got %s", err)
+ }
+ cnt, _, _ = st.Incr("k", win)
+ if cnt != 2 {
+ t.Errorf("expected last reset+incr to return 2, got %d", cnt)
+ }
+}