Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bma13 committed Jul 30, 2024
1 parent 5d1e622 commit df02bb1
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ vet:

build: ydbcp
ydbcp:
go build ./cmd/ydbcp -o ydbcp
go build -C cmd/ydbcp -o ydbcp
58 changes: 41 additions & 17 deletions internal/connectors/db/yql/queries/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package queries

import (
"context"
"github.com/stretchr/testify/assert"
"github.com/ydb-platform/ydb-go-sdk/v3/table"
table_types "github.com/ydb-platform/ydb-go-sdk/v3/table/types"
"testing"
"time"
"ydbcp/internal/types"

"github.com/stretchr/testify/assert"
"github.com/ydb-platform/ydb-go-sdk/v3/table"
table_types "github.com/ydb-platform/ydb-go-sdk/v3/table/types"
)

func TestQueryBuilder_UpdateUpdate(t *testing.T) {
Expand Down Expand Up @@ -57,23 +58,27 @@ func TestQueryBuilder_CreateCreate(t *testing.T) {
queryString = `DECLARE $id_0 AS Uuid;
DECLARE $container_id_0 AS String;
DECLARE $database_0 AS String;
DECLARE $endpoint_0 AS String;
DECLARE $initiated_0 AS String;
DECLARE $s3_endpoint_0 AS String;
DECLARE $s3_region_0 AS String;
DECLARE $s3_bucket_0 AS String;
DECLARE $s3_path_prefix_0 AS String;
DECLARE $status_0 AS String;
UPSERT INTO Backups (id, container_id, database, initiated, s3_endpoint, s3_region, s3_bucket, s3_path_prefix, status) VALUES ($id_0, $container_id_0, $database_0, $initiated_0, $s3_endpoint_0, $s3_region_0, $s3_bucket_0, $s3_path_prefix_0, $status_0);
DECLARE $message_0 AS String;
UPSERT INTO Backups (id, container_id, database, endpoint, initiated, s3_endpoint, s3_region, s3_bucket, s3_path_prefix, status, message) VALUES ($id_0, $container_id_0, $database_0, $endpoint_0, $initiated_0, $s3_endpoint_0, $s3_region_0, $s3_bucket_0, $s3_path_prefix_0, $status_0, $message_0);
DECLARE $id_1 AS Uuid;
DECLARE $type_1 AS String;
DECLARE $status_1 AS String;
DECLARE $container_id_1 AS String;
DECLARE $database_1 AS String;
DECLARE $endpoint_1 AS String;
DECLARE $backup_id_1 AS Uuid;
DECLARE $initiated_1 AS String;
DECLARE $created_at_1 AS Timestamp;
DECLARE $operation_id_1 AS String;
UPSERT INTO Operations (id, type, status, container_id, database, backup_id, initiated, created_at, operation_id) VALUES ($id_1, $type_1, $status_1, $container_id_1, $database_1, $backup_id_1, $initiated_1, $created_at_1, $operation_id_1)`
DECLARE $message_1 AS String;
UPSERT INTO Operations (id, type, status, container_id, database, endpoint, backup_id, initiated, created_at, operation_id, message) VALUES ($id_1, $type_1, $status_1, $container_id_1, $database_1, $endpoint_1, $backup_id_1, $initiated_1, $created_at_1, $operation_id_1, $message_1)`
)
opId := types.GenerateObjectID()
backupId := types.GenerateObjectID()
Expand All @@ -82,9 +87,9 @@ UPSERT INTO Operations (id, type, status, container_id, database, backup_id, ini
ContainerID: "a",
BackupId: backupId,
State: "PENDING",
Message: "Message",
Message: "msg op",
YdbConnectionParams: types.YdbConnectionParams{
Endpoint: "",
Endpoint: "endpoint",
DatabaseName: "dbname",
},
YdbOperationId: "1234",
Expand All @@ -93,14 +98,16 @@ UPSERT INTO Operations (id, type, status, container_id, database, backup_id, ini
CreatedAt: time.Unix(0, 0),
}
backup := types.Backup{
ID: backupId,
ContainerID: "a",
DatabaseName: "b",
S3Endpoint: "c",
S3Region: "d",
S3Bucket: "e",
S3PathPrefix: "f",
Status: "Available",
ID: backupId,
ContainerID: "a",
DatabaseName: "b",
DatabaseEndpoint: "g",
S3Endpoint: "c",
S3Region: "d",
S3Bucket: "e",
S3PathPrefix: "f",
Status: "Available",
Message: "msg backup",
}
builder := NewWriteTableQuery().
WithCreateBackup(backup).
Expand All @@ -110,12 +117,14 @@ UPSERT INTO Operations (id, type, status, container_id, database, backup_id, ini
table.ValueParam("$id_0", table_types.UUIDValue(backupId)),
table.ValueParam("$container_id_0", table_types.StringValueFromString("a")),
table.ValueParam("$database_0", table_types.StringValueFromString("b")),
table.ValueParam("$endpoint_0", table_types.StringValueFromString("g")),
table.ValueParam("$initiated_0", table_types.StringValueFromString("")),
table.ValueParam("$s3_endpoint_0", table_types.StringValueFromString("c")),
table.ValueParam("$s3_region_0", table_types.StringValueFromString("d")),
table.ValueParam("$s3_bucket_0", table_types.StringValueFromString("e")),
table.ValueParam("$s3_path_prefix_0", table_types.StringValueFromString("f")),
table.ValueParam("$status_0", table_types.StringValueFromString("Available")),
table.ValueParam("$message_0", table_types.StringValueFromString("msg backup")),
table.ValueParam("$id_1", table_types.UUIDValue(opId)),
table.ValueParam("$type_1", table_types.StringValueFromString("TB")),
table.ValueParam(
Expand All @@ -128,6 +137,10 @@ UPSERT INTO Operations (id, type, status, container_id, database, backup_id, ini
"$database_1",
table_types.StringValueFromString(tbOp.YdbConnectionParams.DatabaseName),
),
table.ValueParam(
"$endpoint_1",
table_types.StringValueFromString(tbOp.YdbConnectionParams.Endpoint),
),
table.ValueParam(
"$backup_id_1",
table_types.UUIDValue(tbOp.BackupId),
Expand All @@ -144,6 +157,7 @@ UPSERT INTO Operations (id, type, status, container_id, database, backup_id, ini
"$operation_id_1",
table_types.StringValueFromString(tbOp.YdbOperationId),
),
table.ValueParam("$message_1", table_types.StringValueFromString("msg op")),
)
)
query, err := builder.FormatQuery(context.Background())
Expand All @@ -165,11 +179,13 @@ DECLARE $type_1 AS String;
DECLARE $status_1 AS String;
DECLARE $container_id_1 AS String;
DECLARE $database_1 AS String;
DECLARE $endpoint_1 AS String;
DECLARE $backup_id_1 AS Uuid;
DECLARE $initiated_1 AS String;
DECLARE $created_at_1 AS Timestamp;
DECLARE $operation_id_1 AS String;
UPSERT INTO Operations (id, type, status, container_id, database, backup_id, initiated, created_at, operation_id) VALUES ($id_1, $type_1, $status_1, $container_id_1, $database_1, $backup_id_1, $initiated_1, $created_at_1, $operation_id_1)`
DECLARE $message_1 AS String;
UPSERT INTO Operations (id, type, status, container_id, database, endpoint, backup_id, initiated, created_at, operation_id, message) VALUES ($id_1, $type_1, $status_1, $container_id_1, $database_1, $endpoint_1, $backup_id_1, $initiated_1, $created_at_1, $operation_id_1, $message_1)`
)
opId := types.GenerateObjectID()
backupId := types.GenerateObjectID()
Expand All @@ -180,7 +196,7 @@ UPSERT INTO Operations (id, type, status, container_id, database, backup_id, ini
State: "PENDING",
Message: "Message",
YdbConnectionParams: types.YdbConnectionParams{
Endpoint: "",
Endpoint: "endpoint",
DatabaseName: "dbname",
},
YdbOperationId: "1234",
Expand Down Expand Up @@ -211,6 +227,10 @@ UPSERT INTO Operations (id, type, status, container_id, database, backup_id, ini
"$database_1",
table_types.StringValueFromString(tbOp.YdbConnectionParams.DatabaseName),
),
table.ValueParam(
"$endpoint_1",
table_types.StringValueFromString(tbOp.YdbConnectionParams.Endpoint),
),
table.ValueParam(
"$backup_id_1",
table_types.UUIDValue(tbOp.BackupId),
Expand All @@ -227,6 +247,10 @@ UPSERT INTO Operations (id, type, status, container_id, database, backup_id, ini
"$operation_id_1",
table_types.StringValueFromString(tbOp.YdbOperationId),
),
table.ValueParam(
"$message_1",
table_types.StringValueFromString(tbOp.Message),
),
)
)
query, err := builder.FormatQuery(context.Background())
Expand Down

0 comments on commit df02bb1

Please sign in to comment.