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

View File

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

View File

@ -16,7 +16,7 @@ type GoMethodsMongoDbDriver struct {
}
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() {

View File

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