jet/tests/main_test.go

61 lines
1.6 KiB
Go
Raw Normal View History

2019-04-07 09:58:12 +02:00
package tests
import (
"database/sql"
2019-06-05 17:56:24 +02:00
"github.com/go-jet/jet/tests/.test_files/dvd_rental/dvds/model"
2019-06-11 12:47:35 +02:00
"github.com/go-jet/jet/tests/dbconfig"
2019-04-14 17:55:10 +02:00
_ "github.com/lib/pq"
2019-05-20 17:37:55 +02:00
"github.com/pkg/profile"
2019-05-01 18:23:19 +02:00
"gotest.tools/assert"
2019-04-07 09:58:12 +02:00
"os"
2019-05-24 13:13:13 +02:00
"reflect"
2019-04-07 09:58:12 +02:00
"testing"
)
var db *sql.DB
2019-04-14 17:55:10 +02:00
2019-04-07 09:58:12 +02:00
func TestMain(m *testing.M) {
2019-05-20 17:37:55 +02:00
defer profile.Start().Stop()
2019-04-07 09:58:12 +02:00
var err error
2019-06-11 12:47:35 +02:00
db, err = sql.Open("postgres", dbconfig.ConnectString)
2019-04-07 09:58:12 +02:00
if err != nil {
panic("Failed to connect to test db")
}
2019-06-11 12:47:35 +02:00
defer db.Close()
2019-04-07 09:58:12 +02:00
ret := m.Run()
os.Exit(ret)
}
2019-05-24 13:13:13 +02:00
func TestGenerateModel(t *testing.T) {
2019-05-20 17:37:55 +02:00
2019-05-24 13:13:13 +02:00
actor := model.Actor{}
2019-05-20 17:37:55 +02:00
2019-05-24 13:13:13 +02:00
assert.Equal(t, reflect.TypeOf(actor.ActorID).String(), "int32")
actorIDField, ok := reflect.TypeOf(actor).FieldByName("ActorID")
assert.Assert(t, ok)
2019-06-12 12:47:30 +02:00
assert.Equal(t, actorIDField.Tag.Get("sql"), "primary_key")
2019-05-24 13:13:13 +02:00
assert.Equal(t, reflect.TypeOf(actor.FirstName).String(), "string")
assert.Equal(t, reflect.TypeOf(actor.LastName).String(), "string")
assert.Equal(t, reflect.TypeOf(actor.LastUpdate).String(), "time.Time")
2019-05-20 17:37:55 +02:00
2019-05-24 13:13:13 +02:00
filmActor := model.FilmActor{}
2019-05-20 17:37:55 +02:00
2019-05-24 13:13:13 +02:00
assert.Equal(t, reflect.TypeOf(filmActor.FilmID).String(), "int16")
filmIDField, ok := reflect.TypeOf(filmActor).FieldByName("FilmID")
assert.Assert(t, ok)
2019-06-12 12:47:30 +02:00
assert.Equal(t, filmIDField.Tag.Get("sql"), "primary_key")
2019-05-01 18:23:19 +02:00
2019-05-24 13:13:13 +02:00
assert.Equal(t, reflect.TypeOf(filmActor.ActorID).String(), "int16")
actorIDField, ok = reflect.TypeOf(filmActor).FieldByName("ActorID")
assert.Assert(t, ok)
2019-06-12 12:47:30 +02:00
assert.Equal(t, filmIDField.Tag.Get("sql"), "primary_key")
2019-05-01 18:23:19 +02:00
2019-05-24 13:13:13 +02:00
staff := model.Staff{}
2019-05-01 18:23:19 +02:00
2019-05-24 13:13:13 +02:00
assert.Equal(t, reflect.TypeOf(staff.Email).String(), "*string")
assert.Equal(t, reflect.TypeOf(staff.Picture).String(), "[]uint8")
2019-05-01 18:23:19 +02:00
}