Exemplo n.º 1
0
func TestSelectDocOneNoRows(t *testing.T) {
	s := beginTxWithFixtures()
	defer s.AutoRollback()

	type User struct {
		ID int64
	}

	type PostEmbedded struct {
		ID    int    `db:"id"`
		State string `db:"state"`
		User  *User
	}

	var post PostEmbedded
	err := s.SelectDoc("id", "state").
		One("user", `select * from people where id = 1232345`).
		From("posts").
		Where("id = $1", 1).
		QueryStruct(&post)

	assert.NoError(t, err)
	assert.Equal(t, 1, post.ID)
	assert.Nil(t, post.User)
}
Exemplo n.º 2
0
func TestSelectColumns(t *testing.T) {
	sql, args := Select("id, user_name").
		From("users").
		Columns("created_at").
		ToSQL()
	assert.Equal(t, stripWS(`
		SELECT id, user_name, created_at
		FROM users
		`), stripWS(sql))
	assert.Nil(t, args)
}
Exemplo n.º 3
0
func TestSelectDocColumns(t *testing.T) {
	sql, args := SelectDoc("id, user_name").
		From("users").
		Columns("created_at").
		ToSQL()
	assert.Equal(t, stripWS(`
		SELECT row_to_json(dat__item.*)
		FROM (
			SELECT id, user_name, created_at
			FROM users
		) as dat__item`), stripWS(sql))
	assert.Nil(t, args)
}
Exemplo n.º 4
0
func TestExtractHeadersFromMail(t *testing.T) {
	assert := assert.New(t)

	email, err := os.Open("test.eml")
	if err != nil {
		t.Fatal(err)
	}

	expected := make(map[string]string)
	expected["From"] = "Fictious sender <*****@*****.**>"
	expected["To"] = "\"Fictious recipient\" <*****@*****.**>"
	expected["Subject"] = "Example subject"
	expected["No_such_header"] = ""

	headerlist := ParseHeaderList("from,to,subject,no_such_header")
	headers, err := extractHeadersFromMail(email, headerlist)
	assert.Nil(err)
	assert.Equal(expected, headers)
}
Exemplo n.º 5
0
func TestCallNoArgsSql(t *testing.T) {
	sql, args := Call("foo").ToSQL()
	assert.Equal(t, "SELECT * FROM foo()", sql)
	assert.Nil(t, args)
}