Exemple #1
0
func TestRunError(t *testing.T) {
	output, err := RunOutput(`
		{{.cat}} test/doesnotexist.txt
		{{.cat}} test/bar.txt
		`, M{"cat": cat})
	assert.Error(t, err)
	assert.Contains(t, err.Error(), "line=1")
	assert.Contains(t, output, "doesnotexist")
}
Exemple #2
0
func TestSelectQueryStruct(t *testing.T) {
	s := beginTxWithFixtures()
	defer s.AutoRollback()

	// Found:
	var person Person
	err := s.
		Select("id", "name", "email").
		From("people").
		Where("email = $1", "*****@*****.**").
		QueryStruct(&person)
	assert.NoError(t, err)
	assert.True(t, person.ID > 0)
	assert.Equal(t, person.Name, "John")
	assert.True(t, person.Email.Valid)
	assert.Equal(t, person.Email.String, "*****@*****.**")

	// Not found:
	var person2 Person
	err = s.
		Select("id", "name", "email").
		From("people").Where("email = $1", "*****@*****.**").
		QueryStruct(&person2)
	assert.Contains(t, err.Error(), "no rows")
}
Exemple #3
0
func TestCacheSelectQueryStruct(t *testing.T) {
	Cache.FlushDB()
	for i := 0; i < 2; i++ {

		// Found:
		var person Person
		err := testDB.
			Select("id", "name", "email").
			From("people").
			Where("email = $1", "*****@*****.**").
			Cache("selectdoc.5", 1*time.Second, false).
			QueryStruct(&person)
		assert.NoError(t, err)
		assert.True(t, person.ID > 0)
		assert.Equal(t, person.Name, "John")
		assert.True(t, person.Email.Valid)
		assert.Equal(t, person.Email.String, "*****@*****.**")

		// Not found:
		var person2 Person
		err = testDB.
			Select("id", "name", "email").
			From("people").Where("email = $1", "*****@*****.**").
			Cache("selectdoc.6", 1*time.Second, false).
			QueryStruct(&person2)
		assert.Contains(t, err.Error(), "no rows")
	}
}