Skip to content

Commit

Permalink
* sql: add catalog tests. (src-d#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
smola authored Dec 2, 2016
1 parent 61b9e6d commit 2b1f264
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions sql/catalog_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package sql_test

import (
"testing"

"github.com/gitql/gitql/mem"
"github.com/gitql/gitql/sql"

"github.com/stretchr/testify/assert"
)

func TestCatalog_Database(t *testing.T) {
assert := assert.New(t)

c := sql.Catalog{}
db, err := c.Database("foo")
assert.EqualError(err, "database not found: foo")
assert.Nil(db)

mydb := mem.NewDatabase("foo")
c.Databases = append(c.Databases, mydb)

db, err = c.Database("foo")
assert.NoError(err)
assert.Equal(mydb, db)
}

func TestCatalog_Table(t *testing.T) {
assert := assert.New(t)

c := sql.Catalog{}

table, err := c.Table("foo", "bar")
assert.EqualError(err, "database not found: foo")
assert.Nil(table)

mydb := mem.NewDatabase("foo")
c.Databases = append(c.Databases, mydb)

table, err = c.Table("foo", "bar")
assert.EqualError(err, "table not found: bar")
assert.Nil(table)

mytable := mem.NewTable("bar", sql.Schema{})
mydb.AddTable("bar", mytable)

table, err = c.Table("foo", "bar")
assert.NoError(err)
assert.Equal(mytable, table)
}

0 comments on commit 2b1f264

Please sign in to comment.