Example #1
0
func migrate(db *gorm.DB) {
	// Bootsrrap migrations
	if err := migrations.Bootstrap(db); err != nil {
		log.Fatal(err)
	}
	// Run migrations for the oauth service
	if err := oauth.MigrateAll(db); err != nil {
		log.Fatal(err)
	}
}
Example #2
0
// The SetupSuite method will be run by testify once, at the very
// start of the testing suite, before any tests are run.
func (suite *OauthTestSuite) SetupSuite() {
	// Delete the test database
	os.Remove(testDbPath)

	// Initialise the config
	suite.cnf = config.NewConfig(false)

	// Init in-memory test database
	inMemoryDB, err := gorm.Open("sqlite3", testDbPath)
	if err != nil {
		log.Fatal(err)
	}
	suite.db = &inMemoryDB

	// Run all migrations
	if err := migrations.Bootstrap(suite.db); err != nil {
		log.Print(err)
	}
	if err := MigrateAll(suite.db); err != nil {
		log.Print(err)
	}

	// Load test data from fixtures
	for _, path := range []string{
		"../fixtures/test_data.yml",
	} {
		// Read fixture data from the file
		data, err := ioutil.ReadFile(path)
		if err != nil {
			log.Fatal(err)
		}

		// Insert the fixture data
		err = fixtures.Load(data, suite.db.DB(), suite.cnf.Database.Type)
		if err != nil {
			log.Fatal(err)
		}
	}

	// Fetch the test client
	suite.client = new(Client)
	if err := suite.db.First(suite.client, 1).Error; err != nil {
		log.Fatal(err)
	}

	// Fetch the test user
	suite.user = new(User)
	if err := suite.db.First(suite.user, 1).Error; err != nil {
		log.Fatal(err)
	}

	// Initialise the service
	suite.service = NewService(suite.cnf, suite.db)
}
Example #3
0
// The SetupSuite method will be run by testify once, at the very
// start of the testing suite, before any tests are run.
func (suite *OauthTestSuite) SetupSuite() {
	// Delete the test database
	os.Remove(testDbPath)

	// Initialise the config
	suite.cnf = config.NewConfig(false, false)

	// Init in-memory test database
	inMemoryDB, err := gorm.Open("sqlite3", testDbPath)
	if err != nil {
		log.Fatal(err)
	}
	suite.db = &inMemoryDB

	// Run all migrations
	if err := migrations.Bootstrap(suite.db); err != nil {
		log.Print(err)
	}
	if err := MigrateAll(suite.db); err != nil {
		log.Print(err)
	}

	// Load test data from fixtures
	for _, path := range testFixtures {
		// Read fixture data from the file
		data, err := ioutil.ReadFile(path)
		if err != nil {
			log.Fatal(err)
		}

		// Insert the fixture data
		err = fixtures.Load(data, suite.db.DB(), "sqlite")
		if err != nil {
			log.Fatal(err)
		}
	}

	// Fetch test client
	suite.clients = make([]*Client, 0)
	if err := suite.db.Find(&suite.clients).Error; err != nil {
		log.Fatal(err)
	}

	// Fetch test users
	suite.users = make([]*User, 0)
	if err := suite.db.Find(&suite.users).Error; err != nil {
		log.Fatal(err)
	}

	// Initialise the service
	suite.service = NewService(suite.cnf, suite.db)
}
Example #4
0
// Migrate migrates the database
func Migrate(db *gorm.DB) error {
	// Bootsrrap migrations
	if err := migrations.Bootstrap(db); err != nil {
		return err
	}

	// Run migrations for the oauth service
	if err := oauth.MigrateAll(db); err != nil {
		return err
	}

	return nil
}
Example #5
0
// Migrate runs database migrations
func Migrate() error {
	_, db, err := initConfigDB(true, false)
	if err != nil {
		return err
	}
	defer db.Close()

	// Bootstrap migrations
	if err := migrations.Bootstrap(db); err != nil {
		return err
	}

	// Run migrations for the oauth service
	if err := oauth.MigrateAll(db); err != nil {
		return err
	}

	return nil
}