Пример #1
0
func TestDownBadMigration(t *testing.T) {
	for dname, man := range mans {
		utils.ClearTestTables(dname)
		utils.ClearTestMigrations()
		utils.SetupTestingFolders(dname)

		firstID := transporter.MigrationIdentifier()
		lastID := transporter.MigrationIdentifier()

		utils.GenerateMigrationFiles([]utils.TestMigration{
			utils.TestMigration{
				Identifier:  firstID,
				UpCommand:   "CREATE TABLE down_table (a varchar(255))",
				DownCommand: "DROP TABLE down_table",
			},
			utils.TestMigration{
				Identifier:  lastID,
				UpCommand:   "ALTER TABLE down_table ADD COLUMN o varchar(255)",
				DownCommand: "WUHdnns oius (Bad mig!);",
			},
		})

		context := cli.NewContext(nil, &flag.FlagSet{}, nil)
		Up(context)
		Down(context)

		con, _ := utils.BuildTestingConnection(dname)
		transporter.SetManager(man)

		version := transporter.DatabaseVersion(con)
		assert.Equal(t, version, strconv.FormatInt(lastID, 10))
		defer con.Close()
	}
}
Пример #2
0
func TestUpBadMigration(t *testing.T) {
	for dname := range mans {
		utils.ClearTestTables(dname)
		utils.ClearTestMigrations()
		utils.SetupTestingFolders(dname)

		utils.GenerateMigrationFiles([]utils.TestMigration{
			utils.TestMigration{
				Identifier:  transporter.MigrationIdentifier(),
				UpCommand:   "Create table other_table (a varchar(255) );",
				DownCommand: "Drop Table other_table;",
			},
			utils.TestMigration{
				Identifier:  transporter.MigrationIdentifier(),
				UpCommand:   "Alter table shshshshs other_table add column o varchar(12);",
				DownCommand: "Drop column Wihii;",
			},
			utils.TestMigration{
				Identifier:  transporter.MigrationIdentifier(),
				UpCommand:   "Alter table other_table drop column a;",
				DownCommand: "",
			},
		})

		context := cli.NewContext(nil, &flag.FlagSet{}, nil)
		Up(context)

		con, _ := utils.BuildTestingConnection(dname)
		_, err := con.Query("Select a from other_table;")
		assert.Nil(t, err)
	}
}
Пример #3
0
func TestDown(t *testing.T) {
	for dname := range mans {
		utils.ClearTestTables(dname)
		utils.ClearTestMigrations()
		utils.SetupTestingFolders(dname)

		utils.GenerateMigrationFiles([]utils.TestMigration{
			utils.TestMigration{
				Identifier:  transporter.MigrationIdentifier(),
				UpCommand:   "CREATE TABLE down_table (a varchar(255))",
				DownCommand: "DROP TABLE down_table",
			},
			utils.TestMigration{
				Identifier:  transporter.MigrationIdentifier(),
				UpCommand:   "ALTER TABLE down_table ADD COLUMN o varchar(255)",
				DownCommand: "ALTER TABLE down_table DROP COLUMN o",
			},
		})

		context := cli.NewContext(nil, &flag.FlagSet{}, nil)
		Up(context)
		Down(context)

		con, _ := utils.BuildTestingConnection(dname)
		defer con.Close()

		_, err := con.Query("SELECT a FROM down_table")
		assert.Nil(t, err)

		Down(context)

		_, err = con.Query("SELECT a FROM down_table")
		log.Println(err)
		assert.NotNil(t, err)
	}
}