Welcome to mirror list, hosted at ThFree Co, Russian Federation.

testing_test.go « glsql « datastore « praefect « internal - gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ad576d1ba15b8cede6aa0a3d940b58df2c2cfbf6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// +build postgres

package glsql

import (
	"testing"

	"github.com/stretchr/testify/require"
)

func TestDB_Truncate(t *testing.T) {
	db := GetDB(t)

	_, err := db.Exec("CREATE TABLE truncate_tbl(id BIGSERIAL PRIMARY KEY)")
	require.NoError(t, err)

	res, err := db.Exec("INSERT INTO truncate_tbl VALUES (DEFAULT), (DEFAULT)")
	require.NoError(t, err)
	affected, err := res.RowsAffected()
	require.NoError(t, err)
	require.Equal(t, int64(2), affected, "2 rows must be inserted into the table")

	db.Truncate(t, "truncate_tbl")

	var count int
	require.NoError(t, db.QueryRow("SELECT COUNT(*) FROM truncate_tbl").Scan(&count))
	require.Equal(t, 0, count, "no rows must exist after TRUNCATE operation")

	var id int
	require.NoError(t, db.QueryRow("INSERT INTO truncate_tbl VALUES (DEFAULT) RETURNING id").Scan(&id))
	require.Equal(t, 1, id, "sequence for primary key must be restarted")
}