forked from derailed/k9s
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log_int_test.go
79 lines (63 loc) · 1.44 KB
/
log_int_test.go
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package model
import (
"context"
"strconv"
"testing"
"time"
"github.com/derailed/k9s/internal/client"
"github.com/derailed/k9s/internal/dao"
"github.com/stretchr/testify/assert"
)
func TestUpdateLogs(t *testing.T) {
size := 100
m := NewLog(client.NewGVR("fred"), makeLogOpts(size), 10*time.Millisecond)
m.Init(makeFactory())
v := newMockLogView()
m.AddListener(v)
c := make(dao.LogChan)
go func() {
m.updateLogs(context.Background(), c)
}()
for i := 0; i < 2*size; i++ {
c <- dao.NewLogItemFromString("line" + strconv.Itoa(i))
}
close(c)
time.Sleep(2 * time.Second)
assert.Equal(t, size, v.count)
}
func BenchmarkUpdateLogs(b *testing.B) {
size := 100
m := NewLog(client.NewGVR("fred"), makeLogOpts(size), 10*time.Millisecond)
m.Init(makeFactory())
v := newMockLogView()
m.AddListener(v)
c := make(dao.LogChan)
go func() {
m.updateLogs(context.Background(), c)
}()
b.ReportAllocs()
b.ResetTimer()
for n := 0; n < b.N; n++ {
c <- dao.NewLogItemFromString("line" + strconv.Itoa(n))
}
close(c)
}
// Helpers...
func makeLogOpts(count int) dao.LogOptions {
return dao.LogOptions{
Path: "fred",
Container: "blee",
Lines: int64(count),
}
}
type mockLogView struct {
count int
}
func newMockLogView() *mockLogView {
return &mockLogView{}
}
func (t *mockLogView) LogChanged(ll [][]byte) {
t.count += len(ll)
}
func (t *mockLogView) LogCleared() {}
func (t *mockLogView) LogFailed(err error) {}