コード例 #1
0
func TestCreateTestDatabasePostgresWorksWithValidEntry(t *testing.T) {
	db, err := database.CreateTestDatabasePostgres(testDBUser, testDBName, nil, nil)
	assert.NoError(t, err)
	assert.NotNil(t, db)
	err = db.Close()
	assert.Nil(t, err)
}
コード例 #2
0
ファイル: suite_test.go プロジェクト: RichardKnop/example-api
// The SetupSuite method will be run by testify once, at the very
// start of the testing suite, before any tests are run.
func (suite *FacebookTestSuite) SetupSuite() {
	// Initialise the config
	suite.cnf = config.NewConfig(false, false)

	// Create the test database
	db, err := database.CreateTestDatabasePostgres(
		testDbUser,
		testDbName,
		testMigrations,
		testFixtures,
	)
	if err != nil {
		log.Fatal(err)
	}
	suite.db = db

	// Fetch test accounts
	suite.accounts = make([]*accounts.Account, 0)
	err = accounts.AccountPreload(suite.db).Order("id").Find(&suite.accounts).Error
	if err != nil {
		log.Fatal(err)
	}

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

	// Initialise mocks
	suite.adapterMock = new(facebook.AdapterMock)

	// Initialise the service
	suite.service = facebook.NewService(
		suite.cnf,
		suite.db,
		accounts.NewService(
			suite.cnf,
			suite.db,
			oauth.NewService(suite.cnf, suite.db),
			new(emailMocks.ServiceInterface),
			new(accountsMocks.EmailFactoryInterface),
		),
		suite.adapterMock,
	)

	// Register routes
	suite.router = mux.NewRouter()
	suite.service.RegisterRoutes(suite.router, "/v1/facebook")
}
コード例 #3
0
func TestCreateTestDatabasePostgresFailsWithMissingFixtureFile(t *testing.T) {
	badFixtures := []string{"/badfilename"}
	db, err := database.CreateTestDatabasePostgres(testDBUser, testDBName, nil, badFixtures)
	assert.EqualError(t, err, "Error loading file /badfilename: open /badfilename: no such file or directory")
	assert.Nil(t, db)
}
コード例 #4
0
func TestCreateTestDatabasePostgresFailsWithBadValues(t *testing.T) {
	db, err := database.CreateTestDatabasePostgres("", "", nil, nil)
	assert.Error(t, err)
	assert.Nil(t, db)
}