Move batch simple protocol test to batch_test.go

pull/761/head
Jack Christensen 2020-05-25 11:36:18 -05:00
parent 8bad186207
commit 72bba7fb42
2 changed files with 41 additions and 41 deletions

View File

@ -725,3 +725,44 @@ func TestLogBatchStatementsOnBatchResultClose(t *testing.T) {
t.Errorf("Expected second query to be 'select 1 = 1;' but was '%s'", l1.logs[1].data["sql"])
}
}
func TestSendBatchSimpleProtocol(t *testing.T) {
t.Parallel()
config := mustParseConfig(t, os.Getenv("PGX_TEST_DATABASE"))
config.PreferSimpleProtocol = true
ctx, cancelFunc := context.WithCancel(context.Background())
defer cancelFunc()
conn := mustConnect(t, config)
defer closeConn(t, conn)
var batch pgx.Batch
batch.Queue("SELECT 1::int")
batch.Queue("SELECT 2::int; SELECT $1::int", 3)
results := conn.SendBatch(ctx, &batch)
rows, err := results.Query()
assert.NoError(t, err)
assert.True(t, rows.Next())
values, err := rows.Values()
assert.NoError(t, err)
assert.Equal(t, int32(1), values[0])
assert.False(t, rows.Next())
rows, err = results.Query()
assert.NoError(t, err)
assert.True(t, rows.Next())
values, err = rows.Values()
assert.NoError(t, err)
assert.Equal(t, int32(2), values[0])
assert.False(t, rows.Next())
rows, err = results.Query()
assert.NoError(t, err)
assert.True(t, rows.Next())
values, err = rows.Values()
assert.NoError(t, err)
assert.Equal(t, int32(3), values[0])
assert.False(t, rows.Next())
}

View File

@ -360,47 +360,6 @@ func TestExecPerQuerySimpleProtocol(t *testing.T) {
}
func TestSendBatchSimpleProtocol(t *testing.T) {
t.Parallel()
config := mustParseConfig(t, os.Getenv("PGX_TEST_DATABASE"))
config.PreferSimpleProtocol = true
ctx, cancelFunc := context.WithCancel(context.Background())
defer cancelFunc()
conn := mustConnect(t, config)
defer closeConn(t, conn)
var batch pgx.Batch
batch.Queue("SELECT 1::int")
batch.Queue("SELECT 2::int; SELECT $1::int", 3)
results := conn.SendBatch(ctx, &batch)
rows, err := results.Query()
assert.NoError(t, err)
assert.True(t, rows.Next())
values, err := rows.Values()
assert.NoError(t, err)
assert.Equal(t, int32(1), values[0])
assert.False(t, rows.Next())
rows, err = results.Query()
assert.NoError(t, err)
assert.True(t, rows.Next())
values, err = rows.Values()
assert.NoError(t, err)
assert.Equal(t, int32(2), values[0])
assert.False(t, rows.Next())
rows, err = results.Query()
assert.NoError(t, err)
assert.True(t, rows.Next())
values, err = rows.Values()
assert.NoError(t, err)
assert.Equal(t, int32(3), values[0])
assert.False(t, rows.Next())
}
func TestPrepare(t *testing.T) {
t.Parallel()