-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtable_test.go
145 lines (137 loc) · 3.81 KB
/
table_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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package table
import (
"reflect"
"runtime"
"testing"
)
const input = `
NAME ROLES OS IMAGE KERNEL-VERSION CONTAINER RUNTIME
master-1 control-plane,master Ubuntu 20.04.1 LTS 5.13.0-39-generic containerd://1.4.1
monitor-1 monitor Ubuntu 20.04.2 LTS 5.13.0-39-generic containerd://1.4.2
worker-1 worker Ubuntu 20.04.3 LTS 5.13.0-39-generic containerd://1.4.3
`
func TestTable_Row(t *testing.T) {
tx := ReadAll(input)
tests := []struct {
row *Row
want *Row
}{
{
tx.Row(0),
&Row{
Text: "master-1 control-plane,master Ubuntu 20.04.1 LTS 5.13.0-39-generic containerd://1.4.1",
Cells: []RowCell{
{Relation: "NAME", Value: "master-1"},
{Relation: "ROLES", Value: "control-plane,master"},
{Relation: "OS IMAGE", Value: "Ubuntu 20.04.1 LTS"},
{Relation: "KERNEL-VERSION", Value: "5.13.0-39-generic"},
{Relation: "CONTAINER RUNTIME", Value: "containerd://1.4.1"},
},
}},
{
tx.Row(1),
&Row{
Text: "monitor-1 monitor Ubuntu 20.04.2 LTS 5.13.0-39-generic containerd://1.4.2",
Cells: []RowCell{
{Relation: "NAME", Value: "monitor-1"},
{Relation: "ROLES", Value: "monitor"},
{Relation: "OS IMAGE", Value: "Ubuntu 20.04.2 LTS"},
{Relation: "KERNEL-VERSION", Value: "5.13.0-39-generic"},
{Relation: "CONTAINER RUNTIME", Value: "containerd://1.4.2"},
},
},
},
{
tx.Row(2),
&Row{
Text: "worker-1 worker Ubuntu 20.04.3 LTS 5.13.0-39-generic containerd://1.4.3",
Cells: []RowCell{
{Relation: "NAME", Value: "worker-1"},
{Relation: "ROLES", Value: "worker"},
{Relation: "OS IMAGE", Value: "Ubuntu 20.04.3 LTS"},
{Relation: "KERNEL-VERSION", Value: "5.13.0-39-generic"},
{Relation: "CONTAINER RUNTIME", Value: "containerd://1.4.3"},
},
},
},
{tx.Row(3), nil},
{tx.Row(99), nil},
}
for _, tt := range tests {
if !reflect.DeepEqual(tt.row, tt.want) {
t.Errorf("Row failed\n got: %v\nwant: %v", tt.row.Text, tt.want)
}
}
}
func TestRow_Cell(t *testing.T) {
tx := ReadAll(input)
row := tx.Row(0)
tests := []struct {
cell *RowCell
want *RowCell
}{
{row.Cell(0), &RowCell{
Value: "master-1",
Relation: "NAME",
}},
{row.Cell(1), &RowCell{
Value: "control-plane,master",
Relation: "ROLES",
}},
{row.Cell(2), &RowCell{
Value: "Ubuntu 20.04.1 LTS",
Relation: "OS IMAGE",
}},
{row.Cell(3), &RowCell{
Value: "5.13.0-39-generic",
Relation: "KERNEL-VERSION",
}},
{row.Cell(4), &RowCell{
Value: "containerd://1.4.1",
Relation: "CONTAINER RUNTIME",
}},
{row.Cell(5), nil},
{row.Cell(99), nil},
}
for _, tt := range tests {
if !reflect.DeepEqual(tt.cell, tt.want) {
t.Errorf("Cell failed\n got: %v\nwant: %v", tt.cell, tt.want)
}
}
}
func TestRow_CellByName(t *testing.T) {
tx := ReadAll(input)
row := tx.Row(0)
tests := []struct {
cell *RowCell
want *RowCell
}{
{row.CellByName("NAME"), &RowCell{
Value: "master-1",
Relation: "NAME",
}},
{row.CellByName("ROLES"), &RowCell{
Value: "control-plane,master",
Relation: "ROLES",
}},
{row.CellByName("OS IMAGE"), &RowCell{
Value: "Ubuntu 20.04.1 LTS",
Relation: "OS IMAGE",
}},
{row.CellByName("KERNEL-VERSION"), &RowCell{
Value: "5.13.0-39-generic",
Relation: "KERNEL-VERSION",
}},
{row.CellByName("CONTAINER RUNTIME"), &RowCell{
Value: "containerd://1.4.1",
Relation: "CONTAINER RUNTIME",
}},
{row.CellByName("NOTHING"), nil},
{row.CellByName(runtime.GOOS), nil},
}
for _, tt := range tests {
if !reflect.DeepEqual(tt.cell, tt.want) {
t.Errorf("CellByName failed\n got: %v\nwant: %v", tt.cell, tt.want)
}
}
}