forked from src-d/gitbase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
database_test.go
74 lines (59 loc) · 1.49 KB
/
database_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
package gitbase
import (
"sort"
"testing"
"github.com/src-d/go-borges/libraries"
"github.com/src-d/go-mysql-server/sql"
"github.com/stretchr/testify/require"
)
const testDBName = "foo"
func TestDatabase_Tables(t *testing.T) {
require := require.New(t)
lib := libraries.New(nil)
db := getDB(t, testDBName, NewRepositoryPool(nil, lib))
tables := db.Tables()
var tableNames []string
for key := range tables {
tableNames = append(tableNames, key)
}
sort.Strings(tableNames)
expected := []string{
CommitsTableName,
CommitTreesTableName,
RefCommitsTableName,
ReferencesTableName,
TreeEntriesTableName,
BlobsTableName,
RepositoriesTableName,
RemotesTableName,
CommitBlobsTableName,
FilesTableName,
CommitFilesTableName,
}
sort.Strings(expected)
require.Equal(expected, tableNames)
}
func TestDatabase_Name(t *testing.T) {
require := require.New(t)
lib := libraries.New(nil)
db := getDB(t, testDBName, NewRepositoryPool(nil, lib))
require.Equal(testDBName, db.Name())
}
func getDB(t *testing.T, name string, pool *RepositoryPool) sql.Database {
t.Helper()
db := NewDatabase(name, pool)
require.NotNil(t, db)
return db
}
func getTable(t *testing.T, name string, ctx *sql.Context) sql.Table {
t.Helper()
require := require.New(t)
db := getDB(t, "foo", poolFromCtx(t, ctx))
require.NotNil(db)
require.Equal(db.Name(), "foo")
tables := db.Tables()
table, ok := tables[name]
require.True(ok, "table %s does not exist", table)
require.NotNil(table)
return table
}