mirror of
https://github.com/binwiederhier/ntfy.git
synced 2024-12-28 04:32:30 +01:00
31 lines
555 B
Go
31 lines
555 B
Go
|
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())
|
||
|
}
|
||
|
}
|