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) }
// 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") }
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) }
func TestCreateTestDatabasePostgresFailsWithBadValues(t *testing.T) { db, err := database.CreateTestDatabasePostgres("", "", nil, nil) assert.Error(t, err) assert.Nil(t, db) }