forked from vitessio/vitess
-
Notifications
You must be signed in to change notification settings - Fork 6
/
vschema.go
59 lines (50 loc) · 1.27 KB
/
vschema.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
// Copyright 2015, Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package test
import (
"strings"
"testing"
"github.com/youtube/vitess/go/vt/topo"
"golang.org/x/net/context"
)
// CheckVSchema runs the tests on the VSchema part of the API
func CheckVSchema(ctx context.Context, t *testing.T, ts topo.Impl) {
got, err := ts.GetVSchema(ctx)
if err != nil {
t.Error(err)
}
want := "{}"
if got != want {
t.Errorf("GetVSchema: %s, want %s", got, want)
}
err = ts.SaveVSchema(ctx, `{ "Keyspaces": {}}`)
if err != nil {
t.Error(err)
}
got, err = ts.GetVSchema(ctx)
if err != nil {
t.Error(err)
}
want = `{ "Keyspaces": {}}`
if got != want {
t.Errorf("GetVSchema: %s, want %s", got, want)
}
err = ts.SaveVSchema(ctx, `{ "Keyspaces": { "aa": { "Sharded": false}}}`)
if err != nil {
t.Error(err)
}
got, err = ts.GetVSchema(ctx)
if err != nil {
t.Error(err)
}
want = `{ "Keyspaces": { "aa": { "Sharded": false}}}`
if got != want {
t.Errorf("GetVSchema: %s, want %s", got, want)
}
err = ts.SaveVSchema(ctx, "invalid")
want = "Unmarshal failed:"
if err == nil || !strings.HasPrefix(err.Error(), want) {
t.Errorf("SaveVSchema: %v, must start with %s", err, want)
}
}