Пример #1
0
// NewEmpire returns a new Empire instance suitable for testing. It ensures that
// the database is clean before returning.
func NewEmpire(t testing.TB) *empire.Empire {
	db, err := empire.OpenDB(DatabaseURL)
	if err != nil {
		t.Fatal(err)
	}

	if err := db.MigrateUp(); err != nil {
		t.Fatal(err)
	}

	// Log queries if verbose mode is set.
	if testing.Verbose() {
		db.Debug()
	}

	e := empire.New(db)
	e.Scheduler = scheduler.NewFakeScheduler()
	e.ProcfileExtractor = ExtractProcfile(nil)
	e.RunRecorder = empire.RecordTo(ioutil.Discard)

	if err := e.Reset(); err != nil {
		t.Fatal(err)
	}

	return e
}
Пример #2
0
func Example() {
	// Open a postgres connection.
	db, _ := empire.OpenDB("postgres://localhost/empire?sslmode=disable")

	// Migrate the database schema.
	_ = db.MigrateUp()

	// Initialize a new Empire instance.
	e := empire.New(db)

	// Run operations against Empire.
	apps, _ := e.Apps(empire.AppsQuery{})
	fmt.Println(apps)
	// Output:
	// []
}
Пример #3
0
// NewEmpire returns a new Empire instance suitable for testing. It ensures that
// the database is clean before returning.
func NewEmpire(t testing.TB) *empire.Empire {
	db, err := empire.OpenDB(DatabaseURL)
	if err != nil {
		t.Fatal(err)
	}

	// TODO: Run db.MigrateUp once migrations are in the binary.

	// Log queries if verbose mode is set.
	if testing.Verbose() {
		db.Debug()
	}

	e := empire.New(db, empire.DefaultOptions)
	e.Scheduler = scheduler.NewFakeScheduler()
	e.ExtractProcfile = ExtractProcfile

	if err := e.Reset(); err != nil {
		t.Fatal(err)
	}

	return e
}
Пример #4
0
func newDB(c *cli.Context) (*empire.DB, error) {
	return empire.OpenDB(c.String(FlagDB))
}