table_dependency_service_test.go
1.6 KB
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
package domainService
import (
"fmt"
"github.com/stretchr/testify/assert"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
"sort"
"testing"
)
func TestTableDependTree(t *testing.T) {
/*
5 8
/ \ / \
1 3 9 10
/ / \ / \
4 6 2 11 12
\
7
*/
tables := []*domain.Table{
newTable(5, 1, 3),
newTable(1, 4),
newTable(4),
newTable(3, 6, 2),
newTable(6),
newTable(2, 7),
newTable(7),
newTable(8, 9, 10),
newTable(10),
newTable(9, 11, 12),
newTable(11),
newTable(12, 9),
}
tableDependencyService := &TableDependencyService{DebugLog: func(s string) {
//t.Log(s)
}}
inputs := []struct {
BindTableId int
Trees []int
Circle bool
}{
{
3,
[]int{1, 2, 3, 4, 5, 6, 7},
false,
},
{
4,
[]int{1, 2, 3, 4, 5, 6, 7},
false,
},
{
12,
[]int{8, 9, 10, 11, 12},
true,
},
{
8,
[]int{8, 9, 10, 11, 12},
true,
},
{
10,
[]int{8, 9, 10, 11, 12},
true,
},
}
for _, input := range inputs {
tree := tableDependencyService.TableDependTree(tables, input.BindTableId)
got := tree.Tree
sort.Ints(got)
assert.Equal(t, got, input.Trees)
assert.Equal(t, tableDependencyService.Detect(nil, tree.EdgesArray()), input.Circle)
}
}
func newTable(id int, dependTables ...int) *domain.Table {
return &domain.Table{
TableId: id,
Name: fmt.Sprintf("t%d", id),
TableInfo: &domain.TableInfo{
DependencyTables: dependTables,
},
}
}