Skip to content

Commit

Permalink
fix lint err
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlesCheung96 committed Oct 17, 2022
1 parent 8328f42 commit 22a04e9
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 17 deletions.
9 changes: 4 additions & 5 deletions engine/pkg/externalresource/broker/storage_handle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/pingcap/tiflow/engine/pkg/externalresource/internal/local"
"github.com/pingcap/tiflow/engine/pkg/externalresource/manager"
resModel "github.com/pingcap/tiflow/engine/pkg/externalresource/model"
"github.com/pingcap/tiflow/engine/pkg/externalresource/model"
"github.com/pingcap/tiflow/engine/pkg/tenant"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
Expand All @@ -33,7 +32,7 @@ func newResourceIdentForTesting(executor, workerID, resourceName string) interna
Name: resModel.EncodeResourceName(resourceName),
ResourceScope: internal.ResourceScope{
ProjectInfo: tenant.NewProjectInfo("fakeTenant", "fakeProject"),
Executor: model.ExecutorID(executor),
Executor: resModel.ExecutorID(executor),
WorkerID: workerID,
},
}
Expand All @@ -43,9 +42,9 @@ func TestStorageHandlePersistAndDiscard(t *testing.T) {
t.Parallel()
dir := t.TempDir()

executor := model.ExecutorID("executor-1")
executor := resModel.ExecutorID("executor-1")
ident := newResourceIdentForTesting(string(executor), "worker-1", "test-resource")
fm := local.NewLocalFileManager(executor, model.LocalFileConfig{BaseDir: dir})
fm := local.NewLocalFileManager(executor, resModel.LocalFileConfig{BaseDir: dir})
cli := manager.NewMockClient()

ctx := context.Background()
Expand Down Expand Up @@ -109,7 +108,7 @@ func TestStorageHandlePersistAndDiscard(t *testing.T) {
func TestStorageHandleDiscardTemporaryResource(t *testing.T) {
t.Parallel()
dir := t.TempDir()
fm := local.NewLocalFileManager("", model.LocalFileConfig{BaseDir: dir})
fm := local.NewLocalFileManager("", resModel.LocalFileConfig{BaseDir: dir})
cli := manager.NewMockClient()

ctx := context.Background()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func GetDummyJobID(executorID model.ExecutorID) model.JobID {
return fmt.Sprintf(dummyJobID, executorID)
}

// GetDummyResPath returns a file path located in dummy resource for s3 storage.
func GetDummyResPath(filename string) string {
return path.Join(DummyWorkerID, dummyResourceName, filename)
}
4 changes: 2 additions & 2 deletions engine/pkg/externalresource/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ package model
import (
"encoding/hex"
"fmt"
"log"
"path"
"strings"

"github.com/pingcap/log"
pb "github.com/pingcap/tiflow/engine/enginepb"
"github.com/pingcap/tiflow/engine/model"
ormModel "github.com/pingcap/tiflow/engine/pkg/orm/model"
Expand Down Expand Up @@ -183,7 +183,7 @@ func BuildResourceID(rtype ResourceType, resName ResourceName) ResourceID {
// EncodeResourceName encodes raw resource name to a valid resource name.
func EncodeResourceName(rawResName string) ResourceName {
resName := hex.EncodeToString([]byte(rawResName))
return ResourceName(resName)
return resName
}

// DecodeResourceName decodes resource name to raw resource name.
Expand Down
10 changes: 0 additions & 10 deletions engine/pkg/externalresource/model/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ func TestParseResource(t *testing.T) {
rawResName, err := DecodeResourceName(suffix)
require.NoError(t, err)
require.Equal(t, "my-local-resource/a/b/c", rawResName)

require.Equal(t, "/local/my-local-resource/a/b/c", BuildResourceID(tp, suffix))

tp, suffix, err = ParseResourceID("/s3/my-local-resource/a/b/c")
Expand All @@ -35,18 +34,9 @@ func TestParseResource(t *testing.T) {
rawResName, err = DecodeResourceName(suffix)
require.NoError(t, err)
require.Equal(t, "my-local-resource/a/b/c", rawResName)

require.Equal(t, "/s3/my-local-resource/a/b/c", BuildResourceID(tp, suffix))
}

func TestResourceName(t *testing.T) {
name := "resource-1"
resName := EncodeResourceName(name)
parsedName, err := DecodeResourceName(resName)
require.NoError(t, err)
require.Equal(t, name, parsedName)
}

func FuzzEncodeResourceName(f *testing.F) {
testcases := []string{"resource-1", "resource-1/inner", "!resource-1+-%/*inner"}
for _, tc := range testcases {
Expand Down

0 comments on commit 22a04e9

Please sign in to comment.