Skip to content

Commit

Permalink
Merge branch 'main' into s3-import
Browse files Browse the repository at this point in the history
  • Loading branch information
xuanyu66 committed Sep 5, 2024
2 parents bbf193f + bd7c1f2 commit 8832559
Show file tree
Hide file tree
Showing 162 changed files with 13,278 additions and 11,681 deletions.
22 changes: 12 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,22 @@ generate-v1beta1-client: install-openapi-generator ## Generate v1beta1 client
go install github.com/go-swagger/go-swagger/cmd/swagger@latest
@echo "==> Generating serverless branch client"
rm -rf pkg/tidbcloud/v1beta1/serverless/branch
cd tools/openapi-generator && npx openapi-generator-cli generate --additional-properties=withGoMod=false,enumClassPrefix=true --global-property=apiTests=false,apiDocs=false,modelDocs=fasle,modelTests=false -i ../../pkg/tidbcloud/v1beta1/serverless/branch.swagger.json -g go -o ../../pkg/tidbcloud/v1beta1/serverless/branch --package-name branch
@echo "==> Generating serverless client"
swagger generate client -f pkg/tidbcloud/v1beta1/serverless/serverless.swagger.json -A tidbcloud-serverless -t pkg/tidbcloud/v1beta1/serverless
@echo "==> Generating serverless br client"
swagger generate client -f pkg/tidbcloud/v1beta1/serverless_br/serverless-br.swagger.json -A tidbcloud-serverless -t pkg/tidbcloud/v1beta1/serverless_br
@echo "==> Generating serverless import client"
rm -rf pkg/tidbcloud/v1beta1/serverless/import
cd tools/openapi-generator && npx openapi-generator-cli generate --additional-properties=withGoMod=false,enumClassPrefix=true --global-property=apiTests=false,apiDocs=false,modelDocs=false,modelTests=false -i ../../pkg/tidbcloud/v1beta1/serverless/import.swagger.json -g go -o ../../pkg/tidbcloud/v1beta1/serverless/import --package-name imp
cd tools/openapi-generator && npx openapi-generator-cli generate --additional-properties=withGoMod=false,enumClassPrefix=true --global-property=apiTests=false,apiDocs=false,modelDocs=false,modelTests=false -i ../../pkg/tidbcloud/v1beta1/serverless/branch.swagger.json -g go -o ../../pkg/tidbcloud/v1beta1/serverless/branch --package-name branch
@echo "==> Generating serverless cluster client"
rm -rf pkg/tidbcloud/v1beta1/serverless/cluster
cd tools/openapi-generator && npx openapi-generator-cli generate --additional-properties=withGoMod=false,enumClassPrefix=true --global-property=apiTests=false,apiDocs=false,modelDocs=false,modelTests=false -i ../../pkg/tidbcloud/v1beta1/serverless/cluster.swagger.json -g go -o ../../pkg/tidbcloud/v1beta1/serverless/cluster --package-name cluster --skip-validate-spec
@echo "==> Generating serverless export client"
rm -rf pkg/tidbcloud/v1beta1/serverless/export
cd tools/openapi-generator && npx openapi-generator-cli generate --additional-properties=withGoMod=false,enumClassPrefix=true --global-property=apiTests=false,apiDocs=false,modelDocs=fasle,modelTests=false -i ../../pkg/tidbcloud/v1beta1/serverless/export.swagger.json -g go -o ../../pkg/tidbcloud/v1beta1/serverless/export --package-name export
cd tools/openapi-generator && npx openapi-generator-cli generate --additional-properties=withGoMod=false,enumClassPrefix=true --global-property=apiTests=false,apiDocs=false,modelDocs=false,modelTests=false -i ../../pkg/tidbcloud/v1beta1/serverless/export.swagger.json -g go -o ../../pkg/tidbcloud/v1beta1/serverless/export --package-name export
@echo "==> Generating iam client"
rm -rf pkg/tidbcloud/v1beta1/iam
cd tools/openapi-generator && npx openapi-generator-cli generate --additional-properties=withGoMod=false,enumClassPrefix=true --global-property=apiTests=false,apiDocs=false,modelDocs=fasle,modelTests=false -i ../../pkg/tidbcloud/v1beta1/iam.swagger.json -g go -o ../../pkg/tidbcloud/v1beta1/iam --package-name iam
cd tools/openapi-generator && npx openapi-generator-cli generate --additional-properties=withGoMod=false,enumClassPrefix=true --global-property=apiTests=false,apiDocs=false,modelDocs=false,modelTests=false -i ../../pkg/tidbcloud/v1beta1/iam.swagger.json -g go -o ../../pkg/tidbcloud/v1beta1/iam --package-name iam
@echo "==> Generating serverless br client"
rm -rf pkg/tidbcloud/v1beta1/serverless/br
cd tools/openapi-generator && npx openapi-generator-cli generate --additional-properties=withGoMod=false,enumClassPrefix=true --global-property=apiTests=false,apiDocs=false,modelDocs=false,modelTests=false -i ../../pkg/tidbcloud/v1beta1/serverless/br.swagger.json -g go -o ../../pkg/tidbcloud/v1beta1/serverless/br --package-name br
@echo "==> Generating serverless import client"
rm -rf pkg/tidbcloud/v1beta1/serverless/import
cd tools/openapi-generator && npx openapi-generator-cli generate --additional-properties=withGoMod=false,enumClassPrefix=true --global-property=apiTests=false,apiDocs=false,modelDocs=false,modelTests=false -i ../../pkg/tidbcloud/v1beta1/serverless/import.swagger.json -g go -o ../../pkg/tidbcloud/v1beta1/serverless/import --package-name imp
go fmt ./pkg/...

.PHONY: install-openapi-generator
Expand Down
3 changes: 0 additions & 3 deletions docs/generate_doc/ticloud_serverless_update.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ ticloud serverless update [flags]
### Options

```
--annotations string The annotations of the cluster to be added or updated.
Interactive example: {"annotation1":"value1","annotation2":"value2"}.
NonInteractive example: "{\"annotation1\":\"value1\",\"annotation2\":\"value2\"}".
-c, --cluster-id string The ID of the cluster to be updated.
--disable-public-endpoint Disable the public endpoint of the cluster.
-n, --display-name string The new displayName of the cluster to be updated.
Expand Down
4 changes: 1 addition & 3 deletions internal/cli/serverless/backup/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"tidbcloud-cli/internal/flag"
"tidbcloud-cli/internal/service/cloud"
"tidbcloud-cli/internal/util"
brApi "tidbcloud-cli/pkg/tidbcloud/v1beta1/serverless_br/client/backup_restore_service"

"github.com/AlecAivazis/survey/v2"
"github.com/AlecAivazis/survey/v2/terminal"
Expand Down Expand Up @@ -148,8 +147,7 @@ func DeleteCmd(h *internal.Helper) *cobra.Command {
}
}

params := brApi.NewBackupRestoreServiceDeleteBackupParams().WithBackupID(backupID).WithContext(ctx)
_, err = d.DeleteBackup(params)
_, err = d.DeleteBackup(ctx, backupID)
if err != nil {
return errors.Trace(err)
}
Expand Down
7 changes: 3 additions & 4 deletions internal/cli/serverless/backup/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"tidbcloud-cli/internal/iostream"
"tidbcloud-cli/internal/mock"
"tidbcloud-cli/internal/service/cloud"
brApi "tidbcloud-cli/pkg/tidbcloud/v1beta1/serverless_br/client/backup_restore_service"
"tidbcloud-cli/pkg/tidbcloud/v1beta1/serverless/br"

"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
Expand Down Expand Up @@ -57,9 +57,8 @@ func (suite *DeleteBackupSuite) TestDeleteBackup() {
ctx := context.Background()

backupID := "289048"
suite.mockClient.On("DeleteBackup", brApi.NewBackupRestoreServiceDeleteBackupParams().
WithBackupID(backupID).WithContext(ctx)).
Return(&brApi.BackupRestoreServiceDeleteBackupOK{}, nil)
suite.mockClient.On("DeleteBackup", ctx, backupID).
Return(&br.V1beta1Backup{}, nil)

tests := []struct {
name string
Expand Down
12 changes: 4 additions & 8 deletions internal/cli/serverless/backup/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,14 @@ package backup
import (
"fmt"

"tidbcloud-cli/internal/output"

"tidbcloud-cli/internal"
"tidbcloud-cli/internal/config"
"tidbcloud-cli/internal/flag"
"tidbcloud-cli/internal/output"
"tidbcloud-cli/internal/service/cloud"
brAPI "tidbcloud-cli/pkg/tidbcloud/v1beta1/serverless_br/client/backup_restore_service"

"github.com/spf13/cobra"

"github.com/juju/errors"
"github.com/spf13/cobra"
)

type DescribeOpts struct {
Expand Down Expand Up @@ -121,15 +118,14 @@ func DescribeCmd(h *internal.Helper) *cobra.Command {
}
}

params := brAPI.NewBackupRestoreServiceGetBackupParams().WithBackupID(backupID).WithContext(ctx)
if err != nil {
return errors.Trace(err)
}
backup, err := d.GetBackup(params)
backup, err := d.GetBackup(ctx, backupID)
if err != nil {
return errors.Trace(err)
}
err = output.PrintJson(h.IOStreams.Out, backup.Payload)
err = output.PrintJson(h.IOStreams.Out, backup)
if err != nil {
return errors.Trace(err)
}
Expand Down
15 changes: 5 additions & 10 deletions internal/cli/serverless/backup/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ import (
"tidbcloud-cli/internal/iostream"
"tidbcloud-cli/internal/mock"
"tidbcloud-cli/internal/service/cloud"
brApi "tidbcloud-cli/pkg/tidbcloud/v1beta1/serverless_br/client/backup_restore_service"
brModel "tidbcloud-cli/pkg/tidbcloud/v1beta1/serverless_br/models"
"tidbcloud-cli/pkg/tidbcloud/v1beta1/serverless/br"

"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
Expand All @@ -36,7 +35,7 @@ import (
const getBackupResult = `{
"backupId": "289048",
"clusterId": "10048930788495339885",
"createTime": "2023-12-15T07:00:00.000Z",
"createTime": "2023-12-15T07:00:00Z",
"name": "backups/289048"
}
`
Expand Down Expand Up @@ -66,17 +65,13 @@ func (suite *DescribeBackupSuite) TestDescribeBackup() {
assert := require.New(suite.T())
ctx := context.Background()

body := &brModel.V1beta1Backup{}
body := &br.V1beta1Backup{}
err := json.Unmarshal([]byte(getBackupResult), body)
assert.Nil(err)
result := &brApi.BackupRestoreServiceGetBackupOK{
Payload: body,
}
backupId := "289048"

suite.mockClient.On("GetBackup", brApi.NewBackupRestoreServiceGetBackupParams().
WithBackupID(backupId).WithContext(ctx)).
Return(result, nil)
suite.mockClient.On("GetBackup", ctx, backupId).
Return(body, nil)

tests := []struct {
name string
Expand Down
13 changes: 7 additions & 6 deletions internal/cli/serverless/backup/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ package backup

import (
"fmt"
"time"

"tidbcloud-cli/internal"
"tidbcloud-cli/internal/config"
"tidbcloud-cli/internal/flag"
"tidbcloud-cli/internal/output"
"tidbcloud-cli/internal/service/cloud"
brModel "tidbcloud-cli/pkg/tidbcloud/v1beta1/serverless_br/models"
"tidbcloud-cli/pkg/tidbcloud/v1beta1/serverless/br"

"github.com/juju/errors"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -126,9 +127,9 @@ func ListCmd(h *internal.Helper) *cobra.Command {
// for terminal which can prompt, humanFormat is the default format.
// for other terminals, json format is the default format.
if format == output.JsonFormat || !h.IOStreams.CanPrompt {
res := &brModel.V1beta1ListBackupsResponse{
res := &br.V1beta1ListBackupsResponse{
Backups: items,
TotalSize: total,
TotalSize: &total,
}
err := output.PrintJson(h.IOStreams.Out, res)
if err != nil {
Expand All @@ -144,9 +145,9 @@ func ListCmd(h *internal.Helper) *cobra.Command {
var rows []output.Row
for _, item := range items {
rows = append(rows, output.Row{
item.BackupID,
*item.ClusterID,
item.CreateTime.String(),
*item.BackupId,
item.ClusterId,
item.CreateTime.Format(time.RFC3339),
})
}

Expand Down
35 changes: 14 additions & 21 deletions internal/cli/serverless/backup/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ import (
"tidbcloud-cli/internal/iostream"
"tidbcloud-cli/internal/mock"
"tidbcloud-cli/internal/service/cloud"
brApi "tidbcloud-cli/pkg/tidbcloud/v1beta1/serverless_br/client/backup_restore_service"
brModel "tidbcloud-cli/pkg/tidbcloud/v1beta1/serverless_br/models"
"tidbcloud-cli/pkg/tidbcloud/v1beta1/serverless/br"

"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
Expand All @@ -38,7 +37,7 @@ const listResultStr = `{
{
"backupId": "289048",
"clusterId": "10048930788495339885",
"createTime": "2023-12-15T07:00:00.000Z",
"createTime": "2023-12-15T07:00:00Z",
"name": "backups/289048"
}
],
Expand All @@ -51,13 +50,13 @@ const listResultMultiPageStr = `{
{
"backupId": "289048",
"clusterId": "10048930788495339885",
"createTime": "2023-12-15T07:00:00.000Z",
"createTime": "2023-12-15T07:00:00Z",
"name": "backups/289048"
},
{
"backupId": "289048",
"clusterId": "10048930788495339885",
"createTime": "2023-12-15T07:00:00.000Z",
"createTime": "2023-12-15T07:00:00Z",
"name": "backups/289048"
}
],
Expand Down Expand Up @@ -92,17 +91,13 @@ func (suite *ListBackupSuite) TestListBackups() {
assert := require.New(suite.T())
ctx := context.Background()

body := &brModel.V1beta1ListBackupsResponse{}
body := &br.V1beta1ListBackupsResponse{}
err := json.Unmarshal([]byte(listResultStr), body)
assert.Nil(err)
result := &brApi.BackupRestoreServiceListBackupsOK{
Payload: body,
}
pageSize := int32(suite.pageSize)
clusterID := "10048930788495339885"
suite.mockClient.On("ListBackups", brApi.NewBackupRestoreServiceListBackupsParams().
WithClusterID(clusterID).WithPageSize(&pageSize).WithContext(ctx)).
Return(result, nil)
suite.mockClient.On("ListBackups", ctx, &clusterID, &pageSize, (*string)(nil)).
Return(body, nil)

tests := []struct {
name string
Expand Down Expand Up @@ -156,20 +151,18 @@ func (suite *ListBackupSuite) TestListBackupsWithMultiPages() {
pageToken := "2"
clusterID := "10048930788495339885"

body := &brModel.V1beta1ListBackupsResponse{}
body := &br.V1beta1ListBackupsResponse{}
err := json.Unmarshal([]byte(strings.ReplaceAll(listResultStr, `"total": 1`, `"total": 2`)), body)
assert.Nil(err)
body.NextPageToken = pageToken
suite.mockClient.On("ListBackups", brApi.NewBackupRestoreServiceListBackupsParams().
WithClusterID(clusterID).WithPageSize(&pageSize).WithContext(ctx)).
Return(&brApi.BackupRestoreServiceListBackupsOK{Payload: body}, nil)
body.NextPageToken = &pageToken
suite.mockClient.On("ListBackups", ctx, &clusterID, &pageSize, (*string)(nil)).
Return(body, nil)

body2 := &brModel.V1beta1ListBackupsResponse{}
body2 := &br.V1beta1ListBackupsResponse{}
err = json.Unmarshal([]byte(strings.ReplaceAll(listResultStr, `"total": 1`, `"total": 2`)), body2)
assert.Nil(err)
suite.mockClient.On("ListBackups", brApi.NewBackupRestoreServiceListBackupsParams().
WithClusterID(clusterID).WithPageToken(&pageToken).WithPageSize(&pageSize).WithContext(ctx)).
Return(&brApi.BackupRestoreServiceListBackupsOK{Payload: body2}, nil)
suite.mockClient.On("ListBackups", ctx, &clusterID, &pageSize, &pageToken).
Return(body2, nil)

tests := []struct {
name string
Expand Down
Loading

0 comments on commit 8832559

Please sign in to comment.