From f2b31c17db147c3afbe6089a077bbd0699d2d5c0 Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 3 Feb 2023 11:17:05 +0800 Subject: [PATCH] [add] migrate helper & utils --- Makefile | 2 +- helper/hex_test.go | 39 --------------------------------------- helper/process.go | 2 +- utils/process.go | 1 + utils/str_test.go | 15 +++++++++++++++ 5 files changed, 18 insertions(+), 41 deletions(-) diff --git a/Makefile b/Makefile index 539c346f..b8adc7c7 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ COMMIT := $(shell git log | head -n 1 | awk '{print substr($$2, 0, 12)}') NOW := $(shell date +"%FT%T%z") # ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) -TESTFOLDER := $(shell $(GO) list ./... | grep -E 'api|model|flow|script|fs|i18n|connector|query|plugin|cert|crypto|task|schedule|runtime' | grep -vE 'examples|tests*|config|widgets') +TESTFOLDER := $(shell $(GO) list ./... | grep -E 'api|model|flow|script|fs|i18n|connector|query|plugin|cert|crypto|task|schedule|runtime|helper|utils' | grep -vE 'examples|tests*|config|widgets') TESTTAGS ?= "" # TESTWIDGETS := $(shell $(GO) list ./widgets/...) diff --git a/helper/hex_test.go b/helper/hex_test.go index 1838c365..4af4cfd5 100644 --- a/helper/hex_test.go +++ b/helper/hex_test.go @@ -1,13 +1,10 @@ package helper import ( - "os" - "path" "testing" "github.com/stretchr/testify/assert" "github.com/yaoapp/gou/process" - "github.com/yaoapp/yao/share" ) func TestProcessHexToString(t *testing.T) { @@ -23,39 +20,3 @@ func TestProcessHexToString(t *testing.T) { assert.Nil(t, err) assert.Nil(t, res) } - -func TestProcessHexToStringInFlow(t *testing.T) { - // testflow := path.Join(os.Getenv("YAO_DEV"), "tests", "flows", "helper") - // flow.Load(testflow, "helper.") - - res, err := process.New("flows.helper.HexToString").Exec() - assert.Nil(t, err) - assert.Equal(t, "6162", res) // ab -} - -func TestProcessHexToStringInScript(t *testing.T) { - - testscirpt := path.Join(os.Getenv("YAO_DEV"), "tests", "scripts") - share.LoadFrom(testscirpt) - - res, err := process.New("scripts.helper.HexToStringString").Exec() - assert.Nil(t, err) - assert.Equal(t, "6162", res) // ab - - res, err = process.New("scripts.helper.HexToStringBytes", []byte{0x0, 0x1}).Exec() - assert.Nil(t, err) - assert.Equal(t, "0001", res) // []byte{0x0, 0x1} -} - -func TestProcessBufferInScript(t *testing.T) { - testscirpt := path.Join(os.Getenv("YAO_DEV"), "tests", "scripts") - share.LoadFrom(testscirpt) - - res, err := process.New("scripts.helper.Buffer").Exec() - assert.Nil(t, err) - - str, ok := res.(string) - assert.True(t, ok) - assert.Equal(t, []byte{0x0, 0x1}, []byte(str)) - -} diff --git a/helper/process.go b/helper/process.go index ed14310f..2faca28b 100644 --- a/helper/process.go +++ b/helper/process.go @@ -27,7 +27,7 @@ func init() { process.Register("xiang.helper.MapDel", ProcessMapDel) // deprecated → utils.map.Del @/utils/process.go process.Register("xiang.helper.MapMultiDel", ProcessMapMultiDel) // deprecated → utils.map.DelMany @/utils/process.go - process.Register("xiang.helper.HexToString", ProcessHexToString) // deprecated + process.Register("xiang.helper.HexToString", ProcessHexToString) // deprecated → utils.str.Hex @/utils/process.go new 2022.2.3 process.Register("xiang.helper.StrConcat", ProcessStrConcat) // deprecated → utils.str.Concat @/utils/process.go diff --git a/utils/process.go b/utils/process.go index f40d1e8a..e0f05b12 100644 --- a/utils/process.go +++ b/utils/process.go @@ -50,6 +50,7 @@ func init() { // String process.Alias("xiang.helper.StrConcat", "utils.str.Concat") + process.Alias("xiang.helper.HexToString", "utils.str.Hex") process.Register("utils.str.Join", str.ProcessJoin) process.Register("utils.str.JoinPath", str.ProcessJoinPath) diff --git a/utils/str_test.go b/utils/str_test.go index a3644b35..124cbfe8 100644 --- a/utils/str_test.go +++ b/utils/str_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/yaoapp/gou/process" + _ "github.com/yaoapp/yao/helper" ) func TestProcessStrJoin(t *testing.T) { @@ -19,3 +20,17 @@ func TestProcessStrJoinPath(t *testing.T) { shouldBe := fmt.Sprintf("data%s20%sapp", string(os.PathSeparator), string(os.PathSeparator)) assert.Equal(t, shouldBe, res) } + +func TestProcessStrHex(t *testing.T) { + res, err := process.New("utils.str.Hex", []byte{0x0, 0x1}).Exec() + assert.Nil(t, err) + assert.Equal(t, "0001", res) + + res, err = process.New("utils.str.Hex", string([]byte{0x0, 0x1})).Exec() + assert.Nil(t, err) + assert.Equal(t, "0001", res) + + res, err = process.New("utils.str.Hex", 1024).Exec() + assert.Nil(t, err) + assert.Nil(t, res) +}