Relaxed constratint that method receiver has to be of Driver interface.

This commit is contained in:
dimag 2016-08-08 21:34:52 +03:00
parent 223908f9d2
commit 70b23c3f84
4 changed files with 6 additions and 6 deletions

View File

@ -8,7 +8,6 @@ import (
"os" "os"
"path" "path"
"bufio" "bufio"
"github.com/dimag-jfrog/migrate/driver"
"github.com/dimag-jfrog/migrate/file" "github.com/dimag-jfrog/migrate/file"
) )
@ -31,7 +30,7 @@ func (e *MethodInvocationFailedError) Error() string {
type Migrator struct { type Migrator struct {
Driver driver.Driver MigrationMethodsReceiver interface{}
RollbackOnFailure bool RollbackOnFailure bool
} }
@ -73,12 +72,12 @@ func (m *Migrator) Migrate(f file.File, pipe chan interface{}) error {
} }
func (m *Migrator) IsValid(methodName string) bool { func (m *Migrator) IsValid(methodName string) bool {
return reflect.ValueOf(m.Driver).MethodByName(methodName).IsValid() return reflect.ValueOf(m.MigrationMethodsReceiver).MethodByName(methodName).IsValid()
} }
func (m *Migrator) Invoke(methodName string) error { func (m *Migrator) Invoke(methodName string) error {
name := methodName name := methodName
migrateMethod := reflect.ValueOf(m.Driver).MethodByName(name) migrateMethod := reflect.ValueOf(m.MigrationMethodsReceiver).MethodByName(name)
if !migrateMethod.IsValid() { if !migrateMethod.IsValid() {
return MissingMethodError(methodName) return MissingMethodError(methodName)
} }

View File

@ -232,7 +232,7 @@ func TestMigrate(t *testing.T) {
for _, c := range cases { for _, c := range cases {
migrator := Migrator{} migrator := Migrator{}
d := &FakeGoMethodsDriver{Migrator: migrator, InvokedMethods:[]string{}} d := &FakeGoMethodsDriver{Migrator: migrator, InvokedMethods:[]string{}}
migrator.Driver = d migrator.MigrationMethodsReceiver = d
migrator.RollbackOnFailure = c.expectRollback migrator.RollbackOnFailure = c.expectRollback
pipe := pipep.New() pipe := pipep.New()

View File

@ -16,7 +16,7 @@ type GoMethodsMongoDbDriver struct {
} }
func (d *GoMethodsMongoDbDriver) Initialize(url string) error { func (d *GoMethodsMongoDbDriver) Initialize(url string) error {
return d.DriverTemplate.Initialize(url, DB_NAME, gomethods.Migrator{Driver: d}) return d.DriverTemplate.Initialize(url, DB_NAME, gomethods.Migrator{MigrationMethodsReceiver: d})
} }
func init() { func init() {

View File

@ -68,6 +68,7 @@ func RunMigrationAndAssertResult(
if !reflect.DeepEqual(expected.Errors, errs) { if !reflect.DeepEqual(expected.Errors, errs) {
t.Fatalf("Migration '%s': FAILED\nexpected errors %v\nbut got %v", title, expected.Errors, errs) t.Fatalf("Migration '%s': FAILED\nexpected errors %v\nbut got %v", title, expected.Errors, errs)
} }
t.Logf("Migration '%s': PASSED", title)
} }