mirror of
https://github.com/binwiederhier/ntfy.git
synced 2025-04-04 21:57:40 +03:00
parent
02f8a32b46
commit
534b93e142
13 changed files with 425 additions and 29 deletions
30
util/limit_test.go
Normal file
30
util/limit_test.go
Normal file
|
@ -0,0 +1,30 @@
|
|||
package util
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestLimiter_Add(t *testing.T) {
|
||||
l := NewLimiter(10)
|
||||
if err := l.Add(5); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := l.Add(5); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := l.Add(5); err != ErrLimitReached {
|
||||
t.Fatalf("expected ErrLimitReached, got %#v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLimiter_AddSub(t *testing.T) {
|
||||
l := NewLimiter(10)
|
||||
l.Add(5)
|
||||
if l.Value() != 5 {
|
||||
t.Fatalf("expected value to be %d, got %d", 5, l.Value())
|
||||
}
|
||||
l.Sub(2)
|
||||
if l.Value() != 3 {
|
||||
t.Fatalf("expected value to be %d, got %d", 3, l.Value())
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue