forked from charmbracelet/wishlist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wishlist_test.go
129 lines (117 loc) · 2.09 KB
/
wishlist_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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package wishlist
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
)
func TestEndointToListItems(t *testing.T) {
result := endpointsToListItems([]*Endpoint{
{
Name: "name",
Address: "anything",
},
{
// invalid
},
}, nil, makeStyles(testRenderer))
require.Len(t, result, 1)
item := result[0]
require.Equal(t, "name", item.FilterValue())
}
func TestNewWishlist(t *testing.T) {
t.Run("local", func(t *testing.T) {
cl := NewLocalSSHClient()
lm := NewListing([]*Endpoint{
{
Name: "name",
Address: "anything",
},
}, cl, testRenderer)
require.Len(t, lm.endpoints, 1)
require.Equal(t, lm.client, cl)
})
}
func TestFeatures(t *testing.T) {
t.Run("complete", func(t *testing.T) {
descriptors := features([]*Endpoint{
{
// invalid
Desc: "desc",
},
{
Name: "foo",
Address: "foo:22",
},
{
Name: "foo",
Address: "foo:22",
Desc: "desc",
},
{
Name: "foo",
Address: "foo:22",
Link: Link{
URL: "link",
},
},
})
require.Len(t, descriptors, 3)
})
t.Run("simple", func(t *testing.T) {
descriptors := features([]*Endpoint{
{
// invalid
Desc: "desc",
},
{
Name: "foo",
Address: "foo:22",
},
})
require.Len(t, descriptors, 1)
})
t.Run("with desc", func(t *testing.T) {
descriptors := features([]*Endpoint{
{
Name: "foo",
Address: "foo:22",
Desc: "desc",
},
})
require.Len(t, descriptors, 2)
})
t.Run("with link", func(t *testing.T) {
descriptors := features([]*Endpoint{
{
Name: "foo",
Address: "foo:22",
Link: Link{
URL: "url",
},
},
})
require.Len(t, descriptors, 2)
})
}
func TestRootCause(t *testing.T) {
require.Equal(
t,
rootCause(
fmt.Errorf(
"foo bar: %w",
fmt.Errorf(
"foo bar 2: %w",
fmt.Errorf(
"foo bar 3: %w",
fmt.Errorf("the root cause"),
),
),
),
).Error(),
"the root cause",
)
}
func TestFirstNonEmpty(t *testing.T) {
require.Equal(t, "a", FirstNonEmpty("", "a"))
require.Equal(t, "", FirstNonEmpty("", ""))
}