-
Notifications
You must be signed in to change notification settings - Fork 2
/
database_test.go
86 lines (65 loc) · 1.61 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
75
76
77
78
79
80
81
82
83
84
85
86
package gitquery
import (
"sort"
"testing"
"gopkg.in/sqle/sqle.v0/sql"
"github.com/stretchr/testify/assert"
"gopkg.in/src-d/go-billy.v4/memfs"
"gopkg.in/src-d/go-git-fixtures.v3"
"gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/storage/filesystem"
)
func init() {
fixtures.RootFolder = "vendor/gopkg.in/src-d/go-git-fixtures.v3/"
}
const (
testDBName = "foo"
)
func TestDatabase_Tables(t *testing.T) {
assert := assert.New(t)
f := fixtures.Basic().One()
db := getDB(assert, f, testDBName)
tables := db.Tables()
var tableNames []string
for key := range tables {
tableNames = append(tableNames, key)
}
sort.Strings(tableNames)
expected := []string{
commitsTableName,
referencesTableName,
treeEntriesTableName,
tagsTableName,
blobsTableName,
objectsTableName,
}
sort.Strings(expected)
assert.Equal(expected, tableNames)
}
func TestDatabase_Name(t *testing.T) {
assert := assert.New(t)
f := fixtures.Basic().One()
db := getDB(assert, f, testDBName)
assert.Equal(testDBName, db.Name())
}
func getDB(assert *assert.Assertions, fixture *fixtures.Fixture,
name string) sql.Database {
s, err := filesystem.NewStorage(fixture.DotGit())
assert.NoError(err)
r, err := git.Open(s, memfs.New())
assert.NoError(err)
db := NewDatabase(name, r)
assert.NotNil(db)
return db
}
func getTable(assert *assert.Assertions, fixture *fixtures.Fixture,
name string) sql.Table {
db := getDB(assert, fixture, "foo")
assert.NotNil(db)
assert.Equal(db.Name(), "foo")
tables := db.Tables()
table, ok := tables[name]
assert.True(ok, "table %s does not exist", table)
assert.NotNil(table)
return table
}