forked from dolthub/vitess
/
testing.go
107 lines (88 loc) · 2.15 KB
/
testing.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
// Package test contains utilities to test topo.Impl
// implementations. If you are testing your implementation, you will
// want to call TopoServerTestSuite in your test method. For an
// example, look at the tests in
// github.com/youtube/vitess/go/vt/topo/memorytopo.
package test
import (
"testing"
"github.com/youtube/vitess/go/vt/topo"
"golang.org/x/net/context"
topodatapb "github.com/youtube/vitess/go/vt/proto/topodata"
)
func newKeyRange(value string) *topodatapb.KeyRange {
_, result, err := topo.ValidateShardName(value)
if err != nil {
panic(err)
}
return result
}
func getLocalCell(ctx context.Context, t *testing.T, ts topo.Impl) string {
cells, err := ts.GetKnownCells(ctx)
if err != nil {
t.Fatalf("GetKnownCells: %v", err)
}
if len(cells) < 1 {
t.Fatalf("provided topo.Impl doesn't have enough cells (need at least 1): %v", cells)
}
return cells[0]
}
// TopoServerTestSuite runs the full topo.Impl test suite.
// The factory method should return a topo server that has a single cell
// called 'test'.
func TopoServerTestSuite(t *testing.T, factory func() topo.Impl) {
var ts topo.Impl
t.Log("=== checkKeyspace")
ts = factory()
checkKeyspace(t, ts)
ts.Close()
t.Log("=== checkShard")
ts = factory()
checkShard(t, ts)
ts.Close()
t.Log("=== checkTablet")
ts = factory()
checkTablet(t, ts)
ts.Close()
t.Log("=== checkShardReplication")
ts = factory()
checkShardReplication(t, ts)
ts.Close()
t.Log("=== checkSrvKeyspace")
ts = factory()
checkSrvKeyspace(t, ts)
ts.Close()
t.Log("=== checkSrvVSchema")
ts = factory()
checkSrvVSchema(t, ts)
ts.Close()
t.Log("=== checkKeyspaceLock")
ts = factory()
checkKeyspaceLock(t, ts)
ts.Close()
t.Log("=== checkShardLock")
ts = factory()
checkShardLock(t, ts)
ts.Close()
t.Log("=== checkVSchema")
ts = factory()
checkVSchema(t, ts)
ts.Close()
t.Log("=== checkElection")
ts = factory()
checkElection(t, ts)
ts.Close()
t.Log("=== checkDirectory")
ts = factory()
checkDirectory(t, ts)
ts.Close()
t.Log("=== checkFile")
ts = factory()
checkFile(t, ts)
ts.Close()
t.Log("=== checkWatch")
ts = factory()
checkWatch(t, ts)
checkWatchInterrupt(t, ts)
ts.Close()
}