-
Notifications
You must be signed in to change notification settings - Fork 39
/
cli_test.go
50 lines (42 loc) · 1.02 KB
/
cli_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
package unicreds
import (
"bytes"
"testing"
"github.com/stretchr/testify/assert"
)
func TestRender(t *testing.T) {
tt := []struct {
tableFormat int
output string
headers []string
rows [][]string
}{
{
tableFormat: TableFormatTerm,
output: `+------------+-----------+
| NAME | VERSION |
+------------+-----------+
| testlogin1 | testpass1 |
| testlogin2 | testpass2 |
+------------+-----------+
`,
headers: []string{"Name", "Version"},
rows: [][]string{{"testlogin1", "testpass1"}, {"testlogin2", "testpass2"}},
},
{
tableFormat: TableFormatCSV,
output: "testlogin1,testpass1\ntestlogin2,testpass2\n",
headers: []string{"Name", "Version"},
rows: [][]string{{"testlogin1", "testpass1"}, {"testlogin2", "testpass2"}},
},
}
for _, tv := range tt {
var b bytes.Buffer
table := NewTable(&b)
table.SetHeaders(tv.headers)
table.SetFormat(tv.tableFormat)
table.BulkWrite(tv.rows)
table.Render()
assert.Equal(t, tv.output, b.String())
}
}