Skip to content

Commit 61507d7

Browse files
authored
Merge pull request #822 from ydb-platform/test
upgrade test
2 parents d88af67 + aae7794 commit 61507d7

File tree

1 file changed

+73
-6
lines changed

1 file changed

+73
-6
lines changed

tests/integration/database_sql_test.go

Lines changed: 73 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,20 @@ func TestDatabaseSql(t *testing.T) {
182182
t.Run("select", func(t *testing.T) {
183183
t.Run("isolation", func(t *testing.T) {
184184
t.Run("snapshot", func(t *testing.T) {
185+
query := `
186+
PRAGMA TablePathPrefix("` + path.Join(cc.Name(), scope.folder) + `");
187+
DECLARE $seriesID AS Uint64;
188+
DECLARE $seasonID AS Uint64;
189+
DECLARE $episodeID AS Uint64;
190+
SELECT views FROM episodes
191+
WHERE
192+
series_id = $seriesID AND
193+
season_id = $seasonID AND
194+
episode_id = $episodeID;
195+
`
185196
err = retry.DoTx(ctx, scope.db,
186197
func(ctx context.Context, tx *sql.Tx) error {
187-
row := tx.QueryRowContext(ctx, `
188-
PRAGMA TablePathPrefix("`+path.Join(cc.Name(), scope.folder)+`");
189-
DECLARE $seriesID AS Uint64;
190-
DECLARE $seasonID AS Uint64;
191-
DECLARE $episodeID AS Uint64;
192-
SELECT views FROM episodes WHERE series_id = $seriesID AND season_id = $seasonID AND episode_id = $episodeID;`,
198+
row := tx.QueryRowContext(ctx, query,
193199
sql.Named("seriesID", uint64(1)),
194200
sql.Named("seasonID", uint64(1)),
195201
sql.Named("episodeID", uint64(1)),
@@ -215,6 +221,67 @@ func TestDatabaseSql(t *testing.T) {
215221
require.NoError(t, err)
216222
})
217223
})
224+
t.Run("scan", func(t *testing.T) {
225+
t.Run("query", func(t *testing.T) {
226+
var (
227+
seriesID *uint64
228+
seasonID *uint64
229+
episodeID *uint64
230+
title *string
231+
airDate *time.Time
232+
views sql.NullFloat64
233+
query = `
234+
PRAGMA TablePathPrefix("` + path.Join(cc.Name(), scope.folder) + `");
235+
DECLARE $seriesID AS Optional<Uint64>;
236+
DECLARE $seasonID AS Optional<Uint64>;
237+
DECLARE $episodeID AS Optional<Uint64>;
238+
SELECT
239+
series_id,
240+
season_id,
241+
episode_id,
242+
title,
243+
air_date,
244+
views
245+
FROM episodes
246+
WHERE
247+
(series_id >= $seriesID OR $seriesID IS NULL) AND
248+
(season_id >= $seasonID OR $seasonID IS NULL) AND
249+
(episode_id >= $episodeID OR $episodeID IS NULL)
250+
ORDER BY
251+
series_id, season_id, episode_id;
252+
`
253+
)
254+
err = retry.Do(ctx, scope.db,
255+
func(ctx context.Context, cc *sql.Conn) error {
256+
rows, err := cc.QueryContext(ydb.WithQueryMode(ctx, ydb.ScanQueryMode), query,
257+
sql.Named("seriesID", seriesID),
258+
sql.Named("seasonID", seasonID),
259+
sql.Named("episodeID", episodeID),
260+
)
261+
if err != nil {
262+
return err
263+
}
264+
defer func() {
265+
_ = rows.Close()
266+
}()
267+
for rows.NextResultSet() {
268+
for rows.Next() {
269+
if err = rows.Scan(&seriesID, &seasonID, &episodeID, &title, &airDate, &views); err != nil {
270+
return fmt.Errorf("cannot select current views: %w", err)
271+
}
272+
t.Logf("[%d][%d][%d] - %s %q (%d views)",
273+
*seriesID, *seasonID, *episodeID, airDate.Format("2006-01-02"),
274+
*title, uint64(views.Float64),
275+
)
276+
}
277+
}
278+
return rows.Err()
279+
},
280+
retry.WithDoRetryOptions(retry.WithIdempotent(true)),
281+
)
282+
require.NoError(t, err)
283+
})
284+
})
218285
})
219286
})
220287
})

0 commit comments

Comments
 (0)