1
1
package table
2
2
3
3
import (
4
+ "reflect"
4
5
"runtime"
5
6
"testing"
6
7
)
@@ -16,18 +17,53 @@ func TestTable_Row(t *testing.T) {
16
17
tx := ReadAll (input )
17
18
18
19
tests := []struct {
19
- row Row
20
- want string
20
+ row * Row
21
+ want * Row
21
22
}{
22
- {tx .Row (0 ), "master-1 control-plane,master Ubuntu 20.04.1 LTS 5.13.0-39-generic containerd://1.4.1" },
23
- {tx .Row (1 ), "monitor-1 monitor Ubuntu 20.04.2 LTS 5.13.0-39-generic containerd://1.4.2" },
24
- {tx .Row (2 ), "worker-1 worker Ubuntu 20.04.3 LTS 5.13.0-39-generic containerd://1.4.3" },
25
- {tx .Row (3 ), "" },
26
- {tx .Row (99 ), "" },
23
+ {
24
+ tx .Row (0 ),
25
+ & Row {
26
+ Text : "master-1 control-plane,master Ubuntu 20.04.1 LTS 5.13.0-39-generic containerd://1.4.1" ,
27
+ Cells : []RowCell {
28
+ {Relation : "NAME" , Value : "master-1" },
29
+ {Relation : "ROLES" , Value : "control-plane,master" },
30
+ {Relation : "OS IMAGE" , Value : "Ubuntu 20.04.1 LTS" },
31
+ {Relation : "KERNEL-VERSION" , Value : "5.13.0-39-generic" },
32
+ {Relation : "CONTAINER RUNTIME" , Value : "containerd://1.4.1" },
33
+ },
34
+ }},
35
+ {
36
+ tx .Row (1 ),
37
+ & Row {
38
+ Text : "monitor-1 monitor Ubuntu 20.04.2 LTS 5.13.0-39-generic containerd://1.4.2" ,
39
+ Cells : []RowCell {
40
+ {Relation : "NAME" , Value : "monitor-1" },
41
+ {Relation : "ROLES" , Value : "monitor" },
42
+ {Relation : "OS IMAGE" , Value : "Ubuntu 20.04.2 LTS" },
43
+ {Relation : "KERNEL-VERSION" , Value : "5.13.0-39-generic" },
44
+ {Relation : "CONTAINER RUNTIME" , Value : "containerd://1.4.2" },
45
+ },
46
+ },
47
+ },
48
+ {
49
+ tx .Row (2 ),
50
+ & Row {
51
+ Text : "worker-1 worker Ubuntu 20.04.3 LTS 5.13.0-39-generic containerd://1.4.3" ,
52
+ Cells : []RowCell {
53
+ {Relation : "NAME" , Value : "worker-1" },
54
+ {Relation : "ROLES" , Value : "worker" },
55
+ {Relation : "OS IMAGE" , Value : "Ubuntu 20.04.3 LTS" },
56
+ {Relation : "KERNEL-VERSION" , Value : "5.13.0-39-generic" },
57
+ {Relation : "CONTAINER RUNTIME" , Value : "containerd://1.4.3" },
58
+ },
59
+ },
60
+ },
61
+ {tx .Row (3 ), nil },
62
+ {tx .Row (99 ), nil },
27
63
}
28
64
for _ , tt := range tests {
29
- if tt .row . Text != tt .want {
30
- t .Errorf ("Row: got = %v, want %v" , tt .row .Text , tt .want )
65
+ if ! reflect . DeepEqual ( tt .row , tt .want ) {
66
+ t .Errorf ("Row failed \n got: %v \n want: %v" , tt .row .Text , tt .want )
31
67
}
32
68
}
33
69
}
@@ -37,20 +73,35 @@ func TestRow_Cell(t *testing.T) {
37
73
row := tx .Row (0 )
38
74
39
75
tests := []struct {
40
- cell RowCell
41
- want string
76
+ cell * RowCell
77
+ want * RowCell
42
78
}{
43
- {row .Cell (0 ), "master-1" },
44
- {row .Cell (1 ), "control-plane,master" },
45
- {row .Cell (2 ), "Ubuntu 20.04.1 LTS" },
46
- {row .Cell (3 ), "5.13.0-39-generic" },
47
- {row .Cell (4 ), "containerd://1.4.1" },
48
- {row .Cell (5 ), "" },
49
- {row .Cell (99 ), "" },
79
+ {row .Cell (0 ), & RowCell {
80
+ Value : "master-1" ,
81
+ Relation : "NAME" ,
82
+ }},
83
+ {row .Cell (1 ), & RowCell {
84
+ Value : "control-plane,master" ,
85
+ Relation : "ROLES" ,
86
+ }},
87
+ {row .Cell (2 ), & RowCell {
88
+ Value : "Ubuntu 20.04.1 LTS" ,
89
+ Relation : "OS IMAGE" ,
90
+ }},
91
+ {row .Cell (3 ), & RowCell {
92
+ Value : "5.13.0-39-generic" ,
93
+ Relation : "KERNEL-VERSION" ,
94
+ }},
95
+ {row .Cell (4 ), & RowCell {
96
+ Value : "containerd://1.4.1" ,
97
+ Relation : "CONTAINER RUNTIME" ,
98
+ }},
99
+ {row .Cell (5 ), nil },
100
+ {row .Cell (99 ), nil },
50
101
}
51
102
for _ , tt := range tests {
52
- if tt .cell . Value != tt .want {
53
- t .Errorf ("Cell: got = %v, want %v" , tt .cell . Value , tt .want )
103
+ if ! reflect . DeepEqual ( tt .cell , tt .want ) {
104
+ t .Errorf ("Cell failed \n got: %v \n want: %v" , tt .cell , tt .want )
54
105
}
55
106
}
56
107
}
@@ -60,20 +111,35 @@ func TestRow_CellByName(t *testing.T) {
60
111
row := tx .Row (0 )
61
112
62
113
tests := []struct {
63
- cell RowCell
64
- want string
114
+ cell * RowCell
115
+ want * RowCell
65
116
}{
66
- {row .CellByName ("NAME" ), "master-1" },
67
- {row .CellByName ("ROLES" ), "control-plane,master" },
68
- {row .CellByName ("OS IMAGE" ), "Ubuntu 20.04.1 LTS" },
69
- {row .CellByName ("KERNEL-VERSION" ), "5.13.0-39-generic" },
70
- {row .CellByName ("CONTAINER RUNTIME" ), "containerd://1.4.1" },
71
- {row .CellByName ("NOTHING" ), "" },
72
- {row .CellByName (runtime .GOOS ), "" },
117
+ {row .CellByName ("NAME" ), & RowCell {
118
+ Value : "master-1" ,
119
+ Relation : "NAME" ,
120
+ }},
121
+ {row .CellByName ("ROLES" ), & RowCell {
122
+ Value : "control-plane,master" ,
123
+ Relation : "ROLES" ,
124
+ }},
125
+ {row .CellByName ("OS IMAGE" ), & RowCell {
126
+ Value : "Ubuntu 20.04.1 LTS" ,
127
+ Relation : "OS IMAGE" ,
128
+ }},
129
+ {row .CellByName ("KERNEL-VERSION" ), & RowCell {
130
+ Value : "5.13.0-39-generic" ,
131
+ Relation : "KERNEL-VERSION" ,
132
+ }},
133
+ {row .CellByName ("CONTAINER RUNTIME" ), & RowCell {
134
+ Value : "containerd://1.4.1" ,
135
+ Relation : "CONTAINER RUNTIME" ,
136
+ }},
137
+ {row .CellByName ("NOTHING" ), nil },
138
+ {row .CellByName (runtime .GOOS ), nil },
73
139
}
74
140
for _ , tt := range tests {
75
- if tt .cell . Value != tt .want {
76
- t .Errorf ("CellByName: got = %v, want %v" , tt .cell . Value , tt .want )
141
+ if ! reflect . DeepEqual ( tt .cell , tt .want ) {
142
+ t .Errorf ("CellByName failed \n got: %v \n want: %v" , tt .cell , tt .want )
77
143
}
78
144
}
79
145
}
0 commit comments