forked from derailed/k9s
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hint_test.go
71 lines (59 loc) · 1.22 KB
/
hint_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
package model_test
import (
"testing"
"github.com/derailed/k9s/internal/model"
"github.com/stretchr/testify/assert"
)
func TestHint(t *testing.T) {
uu := map[string]struct {
hh model.MenuHints
e int
}{
"none": {
model.MenuHints{},
0,
},
"hints": {
model.MenuHints{
{Mnemonic: "a", Description: "blee"},
{Mnemonic: "b", Description: "fred"},
},
2,
},
}
for k := range uu {
u := uu[k]
t.Run(k, func(t *testing.T) {
h := model.NewHint()
l := hintL{count: -1}
h.AddListener(&l)
h.SetHints(u.hh)
assert.Equal(t, u.e, l.count)
assert.Equal(t, u.e, len(h.Peek()))
})
}
}
func TestHintRemoveListener(t *testing.T) {
h := model.NewHint()
l1, l2, l3 := &hintL{}, &hintL{}, &hintL{}
h.AddListener(l1)
h.AddListener(l2)
h.RemoveListener(l2)
h.RemoveListener(l3)
h.RemoveListener(l1)
h.SetHints(model.MenuHints{
model.MenuHint{Mnemonic: "a", Description: "Blee"},
})
assert.Equal(t, 0, l1.count)
assert.Equal(t, 0, l2.count)
assert.Equal(t, 0, l3.count)
}
// ----------------------------------------------------------------------------
// Helpers...
type hintL struct {
count int
}
func (h *hintL) HintsChanged(hh model.MenuHints) {
h.count++
h.count += len(hh)
}