func fetchDatabases() (*db.DB, *gobble.DB) { env := application.NewEnvironment() sqlDB, err := sql.Open("mysql", env.DatabaseURL) if err != nil { ginkgo.Fail(err.Error(), 1) } database := db.NewDatabase(sqlDB, db.Config{DefaultTemplatePath: path.Join(env.RootPath, "templates", "default.json")}) gobbleDB := gobble.NewDatabase(sqlDB) return database, gobbleDB }
var _ = Describe("Worker", func() { var ( queue *gobble.Queue worker gobble.Worker callbackWasCalledWith gobble.Job callback func(*gobble.Job) database *gobble.DB ) BeforeEach(func() { TruncateTables() callback = func(job *gobble.Job) { callbackWasCalledWith = *job } database = gobble.NewDatabase(sqlDB) queue = gobble.NewQueue(database, gobble.Config{}) worker = gobble.NewWorker(1, queue, callback) }) AfterEach(func() { queue.Close() }) Describe("Perform", func() { It("reserves a job, performs the callback, and then dequeues the completed job", func() { job, err := queue.Enqueue(gobble.Job{ Payload: "the-payload", }) if err != nil {
) var sqlDB *sql.DB func TestGobbleSuite(t *testing.T) { RegisterFailHandler(Fail) RunSpecs(t, "gobble") } var _ = BeforeSuite(func() { var err error sqlDB, err = instantiateDBConnection() Expect(err).NotTo(HaveOccurred()) env := application.NewEnvironment() gobble.NewDatabase(sqlDB).Migrate(env.GobbleMigrationsPath) }) var _ = BeforeEach(func() { var err error sqlDB, err = instantiateDBConnection() Expect(err).NotTo(HaveOccurred()) }) func instantiateDBConnection() (*sql.DB, error) { databaseURL := os.Getenv("DATABASE_URL") databaseURL = strings.TrimPrefix(databaseURL, "http://") databaseURL = strings.TrimPrefix(databaseURL, "https://") databaseURL = strings.TrimPrefix(databaseURL, "tcp://") databaseURL = strings.TrimPrefix(databaseURL, "mysql://") databaseURL = strings.TrimPrefix(databaseURL, "mysql2://")
func TruncateTables() { database := gobble.NewDatabase(sqlDB) database.Connection.TruncateTables() }
func (m *Mother) GobbleDatabase() gobble.DatabaseInterface { return gobble.NewDatabase(m.SQLDatabase()) }