|
| 1 | +package table |
| 2 | + |
| 3 | +import ( |
| 4 | + "runtime" |
| 5 | + "testing" |
| 6 | +) |
| 7 | + |
| 8 | +const input = ` |
| 9 | +NAME ROLES OS IMAGE KERNEL-VERSION CONTAINER RUNTIME |
| 10 | +master-1 control-plane,master Ubuntu 20.04.1 LTS 5.13.0-39-generic containerd://1.4.1 |
| 11 | +monitor-1 monitor Ubuntu 20.04.2 LTS 5.13.0-39-generic containerd://1.4.2 |
| 12 | +worker-1 worker Ubuntu 20.04.3 LTS 5.13.0-39-generic containerd://1.4.3 |
| 13 | +` |
| 14 | + |
| 15 | +func TestTable_Row(t *testing.T) { |
| 16 | + tx := ReadAll(input) |
| 17 | + |
| 18 | + tests := []struct { |
| 19 | + row Row |
| 20 | + want string |
| 21 | + }{ |
| 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), ""}, |
| 27 | + } |
| 28 | + for _, tt := range tests { |
| 29 | + if tt.row.Text != tt.want { |
| 30 | + t.Errorf("Row: got = %v, want %v", tt.row.Text, tt.want) |
| 31 | + } |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +func TestRow_Cell(t *testing.T) { |
| 36 | + tx := ReadAll(input) |
| 37 | + row := tx.Row(0) |
| 38 | + |
| 39 | + tests := []struct { |
| 40 | + cell RowCell |
| 41 | + want string |
| 42 | + }{ |
| 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), ""}, |
| 50 | + } |
| 51 | + for _, tt := range tests { |
| 52 | + if tt.cell.Value != tt.want { |
| 53 | + t.Errorf("Cell: got = %v, want %v", tt.cell.Value, tt.want) |
| 54 | + } |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +func TestRow_CellByName(t *testing.T) { |
| 59 | + tx := ReadAll(input) |
| 60 | + row := tx.Row(0) |
| 61 | + |
| 62 | + tests := []struct { |
| 63 | + cell RowCell |
| 64 | + want string |
| 65 | + }{ |
| 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), ""}, |
| 73 | + } |
| 74 | + for _, tt := range tests { |
| 75 | + if tt.cell.Value != tt.want { |
| 76 | + t.Errorf("CellByName: got = %v, want %v", tt.cell.Value, tt.want) |
| 77 | + } |
| 78 | + } |
| 79 | +} |
0 commit comments