-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuffer_test.go
More file actions
35 lines (29 loc) · 973 Bytes
/
Copy pathbuffer_test.go
File metadata and controls
35 lines (29 loc) · 973 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
package pulse
import (
"testing"
"time"
)
func TestRingBufferOverflowAndOrder(t *testing.T) {
b, err := NewRingBuffer(2)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
b.Push(Sample{Timestamp: time.Unix(1, 0), Values: map[string]float64{"v": 1}})
b.Push(Sample{Timestamp: time.Unix(2, 0), Values: map[string]float64{"v": 2}})
b.Push(Sample{Timestamp: time.Unix(3, 0), Values: map[string]float64{"v": 3}})
if got := b.OverflowCount(); got != 1 {
t.Fatalf("expected overflow 1, got %d", got)
}
drained := b.DrainAll()
if len(drained) != 2 {
t.Fatalf("expected 2 samples, got %d", len(drained))
}
if drained[0].Values["v"] != 2 || drained[1].Values["v"] != 3 {
t.Fatalf("expected values 2,3 got %v,%v", drained[0].Values["v"], drained[1].Values["v"])
}
}
func TestRingBufferInvalidCapacity(t *testing.T) {
if _, err := NewRingBuffer(0); err != ErrInvalidBufferCapacity {
t.Fatalf("expected ErrInvalidBufferCapacity, got %v", err)
}
}