-
Notifications
You must be signed in to change notification settings - Fork 124
/
regression_test.go
70 lines (59 loc) · 1.54 KB
/
regression_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
package gitbase_test
import (
"context"
"io/ioutil"
"os"
"testing"
"github.com/src-d/gitbase"
"github.com/src-d/go-mysql-server/sql"
"github.com/src-d/go-mysql-server/sql/index/pilosa"
"github.com/stretchr/testify/require"
yaml "gopkg.in/yaml.v2"
)
type Query struct {
ID string `yaml:"ID"`
Name string `yaml:"Name,omitempty"`
Statements []string `yaml:"Statements"`
}
func TestRegressionQueries(t *testing.T) {
_, pool, cleanup := setup(t)
defer cleanup()
engine := newSquashEngine(pool)
tmpDir, err := ioutil.TempDir(os.TempDir(), "pilosa-idx-gitbase")
require.NoError(t, err)
defer os.RemoveAll(tmpDir)
engine.Catalog.RegisterIndexDriver(pilosa.NewDriver(tmpDir))
ctx := sql.NewContext(
context.TODO(),
sql.WithSession(gitbase.NewSession(pool)),
)
queries, err := loadQueriesYaml("./_testdata/regression.yml")
require.NoError(t, err)
for _, q := range queries {
t.Run(q.ID, func(t *testing.T) {
require := require.New(t)
for _, stmt := range q.Statements {
_, iter, err := engine.Query(ctx, stmt)
if err != nil {
require.Failf(err.Error(), "ID: %s, Name: %s, Statement: %s", q.ID, q.Name, stmt)
}
_, err = sql.RowIterToRows(iter)
if err != nil {
require.Failf(err.Error(), "ID: %s, Name: %s, Statement: %s", q.ID, q.Name, stmt)
}
}
})
}
}
func loadQueriesYaml(file string) ([]Query, error) {
text, err := ioutil.ReadFile(file)
if err != nil {
return nil, err
}
var q []Query
err = yaml.Unmarshal(text, &q)
if err != nil {
return nil, err
}
return q, nil
}