-
Notifications
You must be signed in to change notification settings - Fork 2
/
grid_test.go
94 lines (87 loc) · 2.37 KB
/
grid_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
package chaakoo
import (
"github.com/spf13/viper"
"github.com/stretchr/testify/require"
"testing"
)
type GridTestCase struct {
ID int
Error bool
GridActual [][]string
Grid string
Panes []*Pane
PaneError string
}
func (g GridSuite) testPrepareGrid(t *testing.T) {
var gridTestCases []GridTestCase
if err := viper.UnmarshalKey("grids", &gridTestCases); err != nil {
t.Log("unable to read from the config", err)
t.Fail()
}
for i := range gridTestCases {
t.Log("Test case", gridTestCases[i].ID)
result, err := PrepareGrid(gridTestCases[i].Grid)
if gridTestCases[i].Error {
require.Error(t, err)
require.Nil(t, result)
} else {
require.NoError(t, err)
require.Equal(t, gridTestCases[i].GridActual, result)
}
}
}
func (g GridSuite) testPreparePanes(t *testing.T) {
var gridTestCases []GridTestCase
if err := viper.UnmarshalKey("grids", &gridTestCases); err != nil {
t.Log("unable to read from the config", err)
t.Fail()
}
for _, testcase := range gridTestCases {
if !testcase.Error {
t.Log("Test case", testcase.ID)
grid, err := PrepareGrid(testcase.Grid)
result, err := preparePanes(grid)
if len(testcase.PaneError) == 0 {
require.NoError(t, err)
var expectedPanes = make(map[string]*Pane)
for _, pane := range testcase.Panes {
expectedPanes[pane.Name] = pane
}
var actualPanes = make(map[string]*Pane)
for _, pane := range result {
actualPanes[pane.Name] = pane
}
require.Equal(t, len(expectedPanes), len(actualPanes))
for paneName := range expectedPanes {
require.Equal(t, expectedPanes[paneName], actualPanes[paneName])
}
} else {
require.Error(t, err)
require.EqualError(t, err, testcase.PaneError)
}
}
}
}
func (g GridSuite) testPrepareGraph(t *testing.T) {
var gridTestCases []GridTestCase
if err := viper.UnmarshalKey("grids", &gridTestCases); err != nil {
t.Log("unable to read from the config", err)
t.Fail()
}
for _, testcase := range gridTestCases {
t.Log("Test case", testcase.ID)
if testcase.ID == 7 {
t.Log("For Debug")
}
grid, err := PrepareGrid(testcase.Grid)
require.NoError(t, err)
topPane, err := PrepareGraph(grid)
if !testcase.Error {
require.NoError(t, err)
require.Equal(t, topPane.AsGrid(), testcase.GridActual)
} else {
require.Error(t, err)
require.EqualError(t, err, testcase.PaneError)
}
}
}