add test for HasTable()

This commit is contained in:
Robert B Gordon 2014-08-29 00:51:45 -05:00
parent 94aa843830
commit 4ee47c9228
1 changed files with 18 additions and 1 deletions

View File

@ -4,13 +4,14 @@ import (
"database/sql" "database/sql"
"database/sql/driver" "database/sql/driver"
"fmt" "fmt"
"strconv"
testdb "github.com/erikstmartin/go-testdb" testdb "github.com/erikstmartin/go-testdb"
_ "github.com/go-sql-driver/mysql" _ "github.com/go-sql-driver/mysql"
"github.com/jinzhu/gorm" "github.com/jinzhu/gorm"
"github.com/jinzhu/now" "github.com/jinzhu/now"
_ "github.com/lib/pq" _ "github.com/lib/pq"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"strconv"
"os" "os"
"testing" "testing"
@ -127,6 +128,22 @@ func (c Cart) TableName() string {
return "shopping_cart" return "shopping_cart"
} }
func TestHasTable(t *testing.T) {
type Foo struct {
Id int
Stuff string
}
if table_ok := db.HasTable(&Foo{}); table_ok {
t.Errorf("Table should not exist, but does")
}
if err := db.CreateTable(&Foo{}).Error; err != nil {
t.Errorf("Table should be created")
}
if table_ok := db.HasTable(&Foo{}); !table_ok {
t.Errorf("Table should exist, but HasTable informs it does not")
}
}
func TestTableName(t *testing.T) { func TestTableName(t *testing.T) {
db := db.Model("") db := db.Model("")
if db.NewScope(Order{}).TableName() != "orders" { if db.NewScope(Order{}).TableName() != "orders" {