-
Notifications
You must be signed in to change notification settings - Fork 2
/
client_test.go
71 lines (59 loc) · 1.58 KB
/
client_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
package olapsql_test
import (
"gorm.io/gorm"
"path/filepath"
"testing"
"github.com/awatercolorpen/olap-sql"
"github.com/awatercolorpen/olap-sql/api/types"
"github.com/stretchr/testify/assert"
"gorm.io/driver/sqlite"
)
func TestNewClients(t *testing.T) {
_, err := newClients(t.TempDir())
assert.NoError(t, err)
}
func TestClients_BuildDB(t *testing.T) {
m, err := newManager(t)
assert.NoError(t, err)
assert.NoError(t, MockLoad(m))
query := MockQuery1()
dictionary, err := m.GetDictionary()
assert.NoError(t, err)
clause, err := dictionary.Translate(query)
assert.NoError(t, err)
client, err := m.GetClients()
assert.NoError(t, err)
db, err := client.BuildDB(clause)
rows, err := olapsql.RunSync(db)
assert.NoError(t, err)
result, err := olapsql.BuildResultSync(query, rows)
assert.NoError(t, err)
MockQuery1ResultAssert(t, result)
}
// func TestClients_BuildSQL(t *testing.T) {
// m, err := newManager(t)
// assert.NoError(t, err)
// assert.NoError(t, MockLoad(m))
//
// clause := MockClause()
//
// client, err := m.GetClients()
// assert.NoError(t, err)
// sql, err := client.BuildSQL(clause)
// assert.NoError(t, err)
// t.Log(sql)
// }
func newClients(sqlitePath string) (olapsql.Clients, error) {
db, err := getDB(sqlitePath)
if err != nil {
return nil, err
}
client := olapsql.Clients{}
client.RegisterByKV(types.DBTypeSQLite, mockWikiStatDataSet, db)
client.RegisterByKV(types.DBTypeSQLite, "", db)
return client, nil
}
func getDB(path string) (*gorm.DB, error) {
dsn := filepath.Join(path, "sqlite")
return gorm.Open(sqlite.Open(dsn), &gorm.Config{})
}