Skip to content

Commit

Permalink
added checks rows values
Browse files Browse the repository at this point in the history
  • Loading branch information
asmyasnikov committed Jun 10, 2024
1 parent 4bc2850 commit 62dbf1e
Showing 1 changed file with 36 additions and 19 deletions.
55 changes: 36 additions & 19 deletions tests/integration/query_range_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import (
"context"
"fmt"
"os"
"strconv"
"testing"
"time"

"github.com/stretchr/testify/require"

"github.com/ydb-platform/ydb-go-sdk/v3"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/value"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/version"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xtest"
"github.com/ydb-platform/ydb-go-sdk/v3/query"
Expand All @@ -32,40 +34,55 @@ func TestQueryRange(t *testing.T) {
)
require.NoError(t, err)
t.Run("Execute", func(t *testing.T) {
var (
p1 string
p2 uint64
p3 time.Duration
)
listItems := make([]value.Value, 1000)
for i := range make([]struct{}, 1000) {
listItems[i] = value.StructValue(
value.StructValueField{
Name: "p1",
V: value.TextValue(strconv.Itoa(i)),
},
value.StructValueField{
Name: "p2",
V: value.Uint64Value(uint64(i)),
},
value.StructValueField{
Name: "p3",
V: value.IntervalValueFromDuration(time.Duration(i * 1000)),
},
)
}
r, err := db.Query().Execute(ctx, `
DECLARE $p1 AS Text;
DECLARE $p2 AS Uint64;
DECLARE $p3 AS Interval;
SELECT $p1, $p2, $p3;
`,
DECLARE $values AS List<Struct<p1:Text,p2:Uint64,p3:Interval>>;
SELECT p1, p2, p3 FROM AS_TABLE($values);
`,
query.WithParameters(
ydb.ParamsBuilder().
Param("$p1").Text("test").
Param("$p2").Uint64(100500000000).
Param("$p3").Interval(time.Duration(100500000000)).
Build(),
ydb.ParamsBuilder().Param("$values").BeginList().AddItems(listItems...).EndList().Build(),
),
query.WithSyntax(query.SyntaxYQL),
)
require.NoError(t, err)
count := 0
for rs, err := range r.Range(ctx) {
require.NoError(t, err)
for row, err := range rs.Range(ctx) {
require.NoError(t, err)

var (
p1 string
p2 uint64
p3 time.Duration
)

err = row.Scan(&p1, &p2, &p3)
require.NoError(t, err)

require.EqualValues(t, "test", p1)
require.EqualValues(t, 100500000000, p2)
require.EqualValues(t, time.Duration(100500000000), p3)
require.EqualValues(t, strconv.Itoa(count), p1)
require.EqualValues(t, count, p2)
require.EqualValues(t, time.Duration(count*1000), p3)

count++
}
}
require.EqualValues(t, 1000, count)
})
t.Run("Do", func(t *testing.T) {
var (
Expand Down

0 comments on commit 62dbf1e

Please sign in to comment.