/
split_at_test.go
86 lines (77 loc) · 2.08 KB
/
split_at_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
// Copyright 2016 The Cockroach Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied. See the License for the specific language governing
// permissions and limitations under the License.
//
// Author: Matt Jibson (mjibson@gmail.com)
package sql_test
import (
"strings"
"testing"
"time"
"github.com/cockroachdb/cockroach/testutils/serverutils"
"github.com/cockroachdb/cockroach/util/leaktest"
)
func TestSplitAt(t *testing.T) {
defer leaktest.AfterTest(t)()
params, _ := createTestServerParams()
s, db, _ := serverutils.StartServer(t, params)
defer s.Stopper().Stop()
if _, err := db.Exec(`
CREATE DATABASE d;
CREATE TABLE d.t (i INT, s STRING, PRIMARY KEY (i, s))
`); err != nil {
t.Fatal(err)
}
// Without this, this test regularly fails with: "conflict updating range
// descriptors".
time.Sleep(time.Millisecond * 100)
tests := []struct {
in string
error string
}{
{
in: "SPLIT d.t AT 2, 'b'",
},
{
in: "SPLIT d.t AT 2, 'b'",
error: "range is already split",
},
{
in: "SPLIT d.t AT 'c', 3",
error: "expected type int for column 1, got string",
},
{
in: "SPLIT d.t AT 4",
error: "expected 2 expressions, got 1",
},
{
in: "SPLIT d.t AT 5, 'd'",
},
{
in: "SPLIT d.t AT i, s",
error: `name "i" is not defined`,
},
}
for _, tt := range tests {
_, err := db.Exec(tt.in)
if err != nil && tt.error == "" {
t.Fatalf("%s: unexpected error: %s", tt.in, err)
} else if tt.error != "" && err == nil {
t.Fatalf("%s: expected error: %s", tt.in, tt.error)
} else if err != nil && tt.error != "" {
if !strings.Contains(err.Error(), tt.error) {
t.Fatalf("%s: unexpected error: %s", tt.in, err)
}
}
}
}