コード例 #1
0
ファイル: down_test.go プロジェクト: wawandco/transporter
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
ファイル: up_test.go プロジェクト: wawandco/transporter
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
ファイル: init_test.go プロジェクト: wawandco/transporter
func TestInitCommand(t *testing.T) {
	setupTestingEnv()
	utils.ClearTestMigrations()

	context := cli.Context{}
	Init(&context)
	base := os.Getenv("TRANS_TESTING_FOLDER")

	files := []string{
		filepath.Join(base, "db"),
		filepath.Join(base, "db", "migrations"),
		filepath.Join(base, "db", "config.yml"),
	}

	for _, file := range files {
		isThere, _ := exists(file)
		assert.True(t, isThere)
	}

	// //Content
	content, _ := ioutil.ReadFile(files[2])
	assert.Contains(t, string(content), "development")
	assert.Contains(t, string(content), "url")
	assert.Contains(t, string(content), "driver")

}
コード例 #4
0
ファイル: down_test.go プロジェクト: wawandco/transporter
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)
	}
}