Esempio n. 1
0
func verifyNoActivity(db *pg.DB) error {
	var queries pg.Strings
	_, err := db.Query(&queries, `
		SELECT query FROM pg_stat_activity WHERE datname = 'test'
	`)
	if err != nil {
		return err
	}
	if len(queries) > 1 {
		return fmt.Errorf("there are %d active queries running: %#v", len(queries), queries)
	}
	return nil
}
Esempio n. 2
0
func createSchema(db *pg.DB) error {
	queries := []string{
		`CREATE TEMP TABLE users (id serial, name text, emails jsonb)`,
		`CREATE TEMP TABLE stories (id serial, title text, user_id bigint)`,
	}
	for _, q := range queries {
		_, err := db.Exec(q)
		if err != nil {
			return err
		}
	}
	return nil
}
Esempio n. 3
0
func createTestSchema(db *pg.DB) error {
	sql := []string{
		`DROP TABLE IF EXISTS comments`,
		`DROP TABLE IF EXISTS translations`,
		`DROP TABLE IF EXISTS authors`,
		`DROP TABLE IF EXISTS books`,
		`DROP TABLE IF EXISTS genres`,
		`DROP TABLE IF EXISTS book_genres`,
		`CREATE TABLE authors (id serial, name text)`,
		`CREATE TABLE books (id serial, title text, author_id int, editor_id int, created_at timestamptz)`,
		`CREATE TABLE genres (id serial, name text)`,
		`CREATE TABLE book_genres (book_id int, genre_id int, genre__rating int)`,
		`CREATE TABLE translations (id serial, book_id int, lang varchar(2))`,
		`CREATE TABLE comments (trackable_id int, trackable_type varchar(100), text text)`,
	}
	for _, q := range sql {
		_, err := db.Exec(q)
		if err != nil {
			return err
		}
	}
	return nil
}
Esempio n. 4
0
		ReadTimeout:  10 * time.Second,
		WriteTimeout: 10 * time.Second,
		PoolSize:     10,
		PoolTimeout:  30 * time.Second,
		IdleTimeout:  time.Second, // be aggressive in tests
	}
}

type valuerError string

func (e valuerError) Value() (driver.Value, error) {
	return nil, errors.New(string(e))
}

var _ = Describe("driver.Valuer", func() {
	var db *pg.DB

	BeforeEach(func() {
		db = pg.Connect(pgOptions())
	})

	AfterEach(func() {
		Expect(db.Close()).NotTo(HaveOccurred())
	})

	It("handles driver.Valuer error", func() {
		_, err := db.Exec("SELECT ?", valuerError("driver.Valuer error"))
		Expect(err).To(MatchError("driver.Valuer error"))
	})
})