Skip to content

Commit

Permalink
Print import id when failed (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
xuanyu66 authored Nov 19, 2024
1 parent 8a3efe4 commit de15f56
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 79 deletions.
23 changes: 12 additions & 11 deletions sceneTest/import/import_azure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,19 @@ import (
"time"

"github.com/AlekSi/pointer"
"github.com/pingcap/log"
"github.com/tidbcloud/serverless-test/config"
"github.com/tidbcloud/serverless-test/util"
"github.com/tidbcloud/tidbcloud-cli/pkg/tidbcloud/v1beta1/serverless/imp"
"go.uber.org/zap"
)

func TestAzureImport(t *testing.T) {
ctx := context.Background()
logger := log.L().With(zap.String("test", "e2eAzureImport"))
_, err := db.Exec("DROP TABLE IF EXISTS `test`.`a`")
if err != nil {
logger.Fatal("failed to drop table -> ", zap.Error(err))
t.Fatalf("failed to drop table, err: %s", err.Error())
}

logger.Info("start import")
t.Log("start import")
startImportContext, cancel := context.WithTimeout(ctx, 1*time.Minute)
defer cancel()

Expand Down Expand Up @@ -53,20 +50,19 @@ func TestAzureImport(t *testing.T) {

err = waitImport(ctx, *i.ImportId)
if err != nil {
t.Fatal("import failed -> ", err)
t.Fatalf("import failed, importId: %s, error: %s", *i.ImportId, err.Error())
}
logger.Info("import finished")
t.Log("import finished")
}

func TestAzureNoPrivilegeImport(t *testing.T) {
ctx := context.Background()
logger := log.L().With(zap.String("test", "e2eAzureNoPrivilegeImport"))
_, err := db.Exec("DROP TABLE IF EXISTS `test`.`a`")
if err != nil {
logger.Fatal("failed to drop table -> ", zap.Error(err))
t.Fatalf("failed to drop table, err: %s", err.Error())
}

logger.Info("start import")
t.Log("start import")
startImportContext, cancel := context.WithTimeout(ctx, 1*time.Minute)
defer cancel()

Expand Down Expand Up @@ -96,5 +92,10 @@ func TestAzureNoPrivilegeImport(t *testing.T) {
t.Fatal(err)
}
err = waitImport(ctx, *i.ImportId)
expectFail(err, "error", logger, t)
err = expectFail(err, "error")
if err != nil {
t.Fatalf("test failed, importId: %s, err: %s", *i.ImportId, err.Error())
} else {
t.Log("import failed as expected")
}
}
23 changes: 12 additions & 11 deletions sceneTest/import/import_gcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,19 @@ import (
"time"

"github.com/AlekSi/pointer"
"github.com/pingcap/log"
"github.com/tidbcloud/serverless-test/config"
"github.com/tidbcloud/serverless-test/util"
"github.com/tidbcloud/tidbcloud-cli/pkg/tidbcloud/v1beta1/serverless/imp"
"go.uber.org/zap"
)

func TestGcsImport(t *testing.T) {
ctx := context.Background()
logger := log.L().With(zap.String("test", "e2eGcsImport"))
_, err := db.Exec("DROP TABLE IF EXISTS `test`.`a`")
if err != nil {
logger.Fatal("failed to drop table -> ", zap.Error(err))
t.Fatalf("failed to drop table, err: %s", err.Error())
}

logger.Info("start import")
t.Log("start import")
startImportContext, cancel := context.WithTimeout(ctx, 1*time.Minute)
defer cancel()

Expand Down Expand Up @@ -53,20 +50,19 @@ func TestGcsImport(t *testing.T) {

err = waitImport(ctx, *i.ImportId)
if err != nil {
t.Fatal("import failed -> ", err)
t.Fatalf("import failed, importId: %s, error: %s", *i.ImportId, err.Error())
}
logger.Info("import finished")
t.Log("import finished")
}

func TestGcsNoPrivilegeImport(t *testing.T) {
ctx := context.Background()
logger := log.L().With(zap.String("test", "e2eGcsNoPrivilegeImport"))
_, err := db.Exec("DROP TABLE IF EXISTS `test`.`a`")
if err != nil {
logger.Fatal("failed to drop table -> ", zap.Error(err))
t.Fatalf("failed to drop table, err: %s", err.Error())
}

logger.Info("start import")
t.Log("start import")
startImportContext, cancel := context.WithTimeout(ctx, 1*time.Minute)
defer cancel()

Expand Down Expand Up @@ -96,5 +92,10 @@ func TestGcsNoPrivilegeImport(t *testing.T) {
t.Fatal(err)
}
err = waitImport(ctx, *i.ImportId)
expectFail(err, "Permission 'storage.objects.list' denied on resource", logger, t)
err = expectFail(err, "Permission 'storage.objects.list' denied on resource")
if err != nil {
t.Fatalf("test failed, importId: %s, err: %s", *i.ImportId, err.Error())
} else {
t.Log("import failed as expected")
}
}
13 changes: 5 additions & 8 deletions sceneTest/import/import_local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ import (
"time"

"github.com/AlekSi/pointer"
"github.com/pingcap/log"
"github.com/tidbcloud/serverless-test/util"
"github.com/tidbcloud/tidbcloud-cli/pkg/tidbcloud/v1beta1/serverless/imp"
"go.uber.org/zap"
)

const (
Expand All @@ -22,13 +20,12 @@ const (

func TestLocalImport(t *testing.T) {
ctx := context.Background()
logger := log.L().With(zap.String("test", "e2eLocalImport"))
_, err := db.Exec("DROP TABLE IF EXISTS `test`.`a`")
if err != nil {
logger.Fatal("failed to drop table -> ", zap.Error(err))
t.Fatalf("failed to drop table, err: %s", err.Error())
}

logger.Info("start upload")
t.Log("start upload")
targetDatabase := "test"
targetTable := "a"
startUploadContext, cancel := context.WithTimeout(ctx, 1*time.Minute)
Expand All @@ -54,7 +51,7 @@ func TestLocalImport(t *testing.T) {
if err != nil {
t.Fatal(err)
}
logger.Info("start import")
t.Log("start import")
startImportContext, cancel := context.WithTimeout(ctx, 1*time.Minute)
defer cancel()
body := &imp.ImportServiceCreateImportBody{
Expand Down Expand Up @@ -84,9 +81,9 @@ func TestLocalImport(t *testing.T) {
}
err = waitImport(ctx, *i.ImportId)
if err != nil {
logger.Fatal("import failed -> ", zap.Error(err))
t.Fatalf("import failed, importId: %s, error: %s", *i.ImportId, err.Error())
}
logger.Info("import finished")
t.Log("import finished")
}

func uploadFile(filePath string, url string) error {
Expand Down
56 changes: 32 additions & 24 deletions sceneTest/import/import_s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,19 @@ import (
"time"

"github.com/AlekSi/pointer"
"github.com/pingcap/log"
"github.com/tidbcloud/serverless-test/config"
"github.com/tidbcloud/serverless-test/util"
"github.com/tidbcloud/tidbcloud-cli/pkg/tidbcloud/v1beta1/serverless/imp"
"go.uber.org/zap"
)

func TestS3ArnNoPrivilegeImport(t *testing.T) {
ctx := context.Background()
logger := log.L().With(zap.String("test", "e2eS3ArnNoPrivilegeImport"))
_, err := db.Exec("DROP TABLE IF EXISTS `test`.`a`")
if err != nil {
logger.Fatal("failed to drop table -> ", zap.Error(err))
t.Fatalf("failed to drop table, err: %s", err.Error())
}

logger.Info("start import")
t.Log("start import")
startImportContext, cancel := context.WithTimeout(ctx, 1*time.Minute)
defer cancel()

Expand Down Expand Up @@ -51,18 +48,22 @@ func TestS3ArnNoPrivilegeImport(t *testing.T) {
t.Fatal(err)
}
err = waitImport(ctx, *i.ImportId)
expectFail(err, "is not authorized to perform: s3:ListBucket", logger, t)
err = expectFail(err, "is not authorized to perform: s3:ListBucket")
if err != nil {
t.Fatalf("test failed, importId: %s, err: %s", *i.ImportId, err.Error())
} else {
t.Log("import failed as expected")
}
}

func TestS3ArnDiffExternalIDImport(t *testing.T) {
ctx := context.Background()
logger := log.L().With(zap.String("test", "e2eS3ArnDiffExternalIDImport"))
_, err := db.Exec("DROP TABLE IF EXISTS `test`.`a`")
if err != nil {
logger.Fatal("failed to drop table -> ", zap.Error(err))
t.Fatalf("failed to drop table, err: %s", err.Error())
}

logger.Info("start import")
t.Log("start import")
startImportContext, cancel := context.WithTimeout(ctx, 1*time.Minute)
defer cancel()

Expand Down Expand Up @@ -92,18 +93,22 @@ func TestS3ArnDiffExternalIDImport(t *testing.T) {
t.Fatal(err)
}
err = waitImport(ctx, *i.ImportId)
expectFail(err, "is not authorized to perform: sts:AssumeRole on resource", logger, t)
err = expectFail(err, "is not authorized to perform: sts:AssumeRole on resource")
if err != nil {
t.Fatalf("test failed, importId: %s, err: %s", *i.ImportId, err.Error())
} else {
t.Log("import failed as expected")
}
}

func TestS3AccessKeyNoPrivilegeImport(t *testing.T) {
ctx := context.Background()
logger := log.L().With(zap.String("test", "e2eS3AccessKeyNoPrivilegeImport"))
_, err := db.Exec("DROP TABLE IF EXISTS `test`.`a`")
if err != nil {
logger.Fatal("failed to drop table -> ", zap.Error(err))
t.Fatalf("failed to drop table, err: %s", err.Error())
}

logger.Info("start import")
t.Log("start import")
startImportContext, cancel := context.WithTimeout(ctx, 1*time.Minute)
defer cancel()

Expand Down Expand Up @@ -136,18 +141,22 @@ func TestS3AccessKeyNoPrivilegeImport(t *testing.T) {
t.Fatal(err)
}
err = waitImport(ctx, *i.ImportId)
expectFail(err, "AccessDenied", logger, t)
err = expectFail(err, "AccessDenied")
if err != nil {
t.Fatalf("test failed, importId: %s, err: %s", *i.ImportId, err.Error())
} else {
t.Log("import failed as expected")
}
}

func TestS3AccessKeyImport(t *testing.T) {
ctx := context.Background()
logger := log.L().With(zap.String("test", "e2eS3AccessKeyImport"))
_, err := db.Exec("DROP TABLE IF EXISTS `test`.`a`")
if err != nil {
logger.Fatal("failed to drop table -> ", zap.Error(err))
t.Fatalf("failed to drop table, err: %s", err.Error())
}

logger.Info("start import")
t.Log("start import")
startImportContext, cancel := context.WithTimeout(ctx, 1*time.Minute)
defer cancel()

Expand Down Expand Up @@ -181,20 +190,19 @@ func TestS3AccessKeyImport(t *testing.T) {
}
err = waitImport(ctx, *i.ImportId)
if err != nil {
logger.Fatal("import failed -> ", zap.Error(err))
t.Fatalf("import failed, importId: %s, error: %s", *i.ImportId, err.Error())
}
logger.Info("import finished")
t.Log("import finished")
}

func TestS3ArnImport(t *testing.T) {
ctx := context.Background()
logger := log.L().With(zap.String("test", "e2eS3ArnImport"))
_, err := db.Exec("DROP TABLE IF EXISTS `test`.`a`")
if err != nil {
logger.Fatal("failed to drop table -> ", zap.Error(err))
t.Fatalf("failed to drop table, err: %s", err.Error())
}

logger.Info("start import")
t.Log("start import")
startImportContext, cancel := context.WithTimeout(ctx, 1*time.Minute)
defer cancel()

Expand Down Expand Up @@ -225,7 +233,7 @@ func TestS3ArnImport(t *testing.T) {
}
err = waitImport(ctx, *i.ImportId)
if err != nil {
logger.Fatal("import failed -> ", zap.Error(err))
t.Fatalf("import failed, importId: %s, error: %s", *i.ImportId, err.Error())
}
logger.Info("import finished")
t.Log("import finished")
}
Loading

0 comments on commit de15f56

Please sign in to comment.