Skip to content

Commit

Permalink
Test that the tableName is really taken in account and the default value
Browse files Browse the repository at this point in the history
  • Loading branch information
marema31 committed Nov 20, 2019
1 parent df6f689 commit cac4cff
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,12 +558,12 @@ func (s *SqliteMigrateSuite) TestExecWithUnknownMigrationInDatabase(c *C) {
c.Assert(err, NotNil)
}

func (s *SqliteMigrateSuite) TestRunMigrationObj(c *C) {
func (s *SqliteMigrateSuite) TestRunMigrationObjDefaultTable(c *C) {
migrations := &MemoryMigrationSource{
Migrations: sqliteMigrations[:1],
}

ms := NewMigrationSet("", "")
ms := MigrationSet{}
// Executes one migration
n, err := ms.Exec(s.Db, "sqlite3", migrations, Up)
c.Assert(err, IsNil)
Expand All @@ -573,6 +573,35 @@ func (s *SqliteMigrateSuite) TestRunMigrationObj(c *C) {
_, err = s.DbMap.Exec("SELECT * FROM people")
c.Assert(err, IsNil)

// Uses default tableName
_, err = s.DbMap.Exec("SELECT * FROM gorp_migrations")
c.Assert(err, IsNil)

// Shouldn't apply migration again
n, err = ms.Exec(s.Db, "sqlite3", migrations, Up)
c.Assert(err, IsNil)
c.Assert(n, Equals, 0)
}

func (s *SqliteMigrateSuite) TestRunMigrationObjOtherTable(c *C) {
migrations := &MemoryMigrationSource{
Migrations: sqliteMigrations[:1],
}

ms := MigrationSet{TableName: "other_migrations"}
// Executes one migration
n, err := ms.Exec(s.Db, "sqlite3", migrations, Up)
c.Assert(err, IsNil)
c.Assert(n, Equals, 1)

// Can use table now
_, err = s.DbMap.Exec("SELECT * FROM people")
c.Assert(err, IsNil)

// Uses default tableName
_, err = s.DbMap.Exec("SELECT * FROM other_migrations")
c.Assert(err, IsNil)

// Shouldn't apply migration again
n, err = ms.Exec(s.Db, "sqlite3", migrations, Up)
c.Assert(err, IsNil)
Expand Down

0 comments on commit cac4cff

Please sign in to comment.