Skip to content

Commit 15ddec8

Browse files
committed
add TestCreateTableRegression
1 parent 6fd76e8 commit 15ddec8

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed

internal/table/session_test.go

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package table
33
import (
44
"context"
55
"fmt"
6+
"github.com/stretchr/testify/require"
7+
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Operations"
68
"reflect"
79
"testing"
810
"time"
@@ -388,3 +390,103 @@ func TestSessionOperationModeOnExecuteDataQuery(t *testing.T) {
388390
)
389391
}
390392
}
393+
394+
func TestCreateTableRegression(t *testing.T) {
395+
client := New(
396+
testutil.NewRouter(
397+
testutil.WithInvokeHandlers(
398+
testutil.InvokeHandlers{
399+
testutil.TableCreateSession: func(request interface{}) (proto.Message, error) {
400+
return &Ydb_Table.CreateSessionResult{
401+
SessionId: "",
402+
}, nil
403+
},
404+
testutil.TableCreateTable: func(act interface{}) (proto.Message, error) {
405+
exp := &Ydb_Table.CreateTableRequest{
406+
SessionId: "",
407+
Path: "episodes",
408+
Columns: []*Ydb_Table.ColumnMeta{
409+
{
410+
Name: "series_id",
411+
Type: &Ydb.Type{Type: &Ydb.Type_OptionalType{
412+
OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{Type: &Ydb.Type_TypeId{
413+
TypeId: Ydb.Type_UINT64,
414+
}}},
415+
}},
416+
},
417+
{
418+
Name: "season_id",
419+
Type: &Ydb.Type{Type: &Ydb.Type_OptionalType{
420+
OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{Type: &Ydb.Type_TypeId{
421+
TypeId: Ydb.Type_UINT64,
422+
}}},
423+
}},
424+
},
425+
{
426+
Name: "episode_id",
427+
Type: &Ydb.Type{Type: &Ydb.Type_OptionalType{
428+
OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{Type: &Ydb.Type_TypeId{
429+
TypeId: Ydb.Type_UINT64,
430+
}}},
431+
}},
432+
},
433+
{
434+
Name: "title",
435+
Type: &Ydb.Type{Type: &Ydb.Type_OptionalType{
436+
OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{Type: &Ydb.Type_TypeId{
437+
TypeId: Ydb.Type_UTF8,
438+
}}},
439+
}},
440+
},
441+
{
442+
Name: "air_date",
443+
Type: &Ydb.Type{Type: &Ydb.Type_OptionalType{
444+
OptionalType: &Ydb.OptionalType{Item: &Ydb.Type{Type: &Ydb.Type_TypeId{
445+
TypeId: Ydb.Type_UINT64,
446+
}}},
447+
}},
448+
},
449+
},
450+
PrimaryKey: []string{
451+
"series_id",
452+
"season_id",
453+
"episode_id",
454+
},
455+
OperationParams: &Ydb_Operations.OperationParams{
456+
OperationMode: Ydb_Operations.OperationParams_SYNC,
457+
},
458+
Attributes: map[string]string{
459+
"attr": "attr_value",
460+
},
461+
}
462+
if !proto.Equal(exp, act.(proto.Message)) {
463+
return nil, fmt.Errorf("act: %v\n\nexp: %s\n\n", act, exp)
464+
}
465+
return &Ydb_Table.CreateTableResponse{}, nil
466+
},
467+
},
468+
),
469+
),
470+
config.New(),
471+
)
472+
473+
ctx, cancel := context.WithTimeout(
474+
context.Background(),
475+
time.Second,
476+
)
477+
defer cancel()
478+
479+
err := client.Do(ctx, func(ctx context.Context, s table.Session) error {
480+
return s.CreateTable(ctx, "episodes",
481+
options.WithColumn("series_id", types.Optional(types.TypeUint64)),
482+
options.WithColumn("season_id", types.Optional(types.TypeUint64)),
483+
options.WithColumn("episode_id", types.Optional(types.TypeUint64)),
484+
options.WithColumn("title", types.Optional(types.TypeUTF8)),
485+
options.WithColumn("air_date", types.Optional(types.TypeUint64)),
486+
options.WithPrimaryKeyColumn("series_id", "season_id", "episode_id"),
487+
options.WithAttribute("attr", "attr_value"),
488+
)
489+
})
490+
491+
require.NoError(t, err, "")
492+
}

0 commit comments

Comments
 (0)