Example #1
0
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
}
Example #2
0
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 {
Example #3
0
)

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://")
Example #4
0
func TruncateTables() {
	database := gobble.NewDatabase(sqlDB)
	database.Connection.TruncateTables()
}
Example #5
0
func (m *Mother) GobbleDatabase() gobble.DatabaseInterface {
	return gobble.NewDatabase(m.SQLDatabase())
}