コード例 #1
0
ファイル: exec_test.go プロジェクト: coreroller/coreroller
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")
}
コード例 #2
0
ファイル: select_exec_test.go プロジェクト: syreclabs/dat
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")
}
コード例 #3
0
ファイル: cache_test.go プロジェクト: syreclabs/dat
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")
	}
}