Small Refactoring
This commit is contained in:
1 parent
9ccc1c1728
commit
24d35e0505
9 files changed
+66
-71
No files matched your search
@@ -49,7 +49,7 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
func getCustomData(data map[string]interface{}, id string, version int64) map[string]interface{} {
|
||||
func GetCustomData(data map[string]interface{}, id string, version int64) map[string]interface{} {
|
||||
jq := jsonq.NewQuery(data)
|
||||
|
||||
m := make(map[string]interface{}, 6)
|
||||
@@ -94,6 +94,7 @@ func expandArrayWithMapping(
|
||||
) {
|
||||
docs, err := src.ArrayOfObjects(arrayPath)
|
||||
l := len(docs)
|
||||
//nolint
|
||||
if err == nil && l > 0 {
|
||||
documents := make(map[string][]interface{}, l)
|
||||
for _, d := range docs {
|
||||
|
||||
+14
-13
@@ -1,8 +1,14 @@
|
||||
package adapter
|
||||
package adapter_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"isp-script-service/adapter"
|
||||
"isp-script-service/conf"
|
||||
"isp-script-service/controller"
|
||||
"isp-script-service/domain"
|
||||
"isp-script-service/script"
|
||||
"isp-script-service/service"
|
||||
"log"
|
||||
"os"
|
||||
"testing"
|
||||
@@ -10,11 +16,6 @@ import (
|
||||
"github.com/integration-system/isp-lib/v2/config"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"isp-script-service/conf"
|
||||
"isp-script-service/controller"
|
||||
"isp-script-service/domain"
|
||||
"isp-script-service/script"
|
||||
"isp-script-service/service"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -29,8 +30,10 @@ const (
|
||||
scriptFile = "custom_date.js"
|
||||
)
|
||||
|
||||
var data map[string]interface{}
|
||||
var request = domain.ExecuteRequest{}
|
||||
var (
|
||||
data map[string]interface{}
|
||||
request = domain.ExecuteRequest{}
|
||||
)
|
||||
|
||||
func init() {
|
||||
config.InitRemoteConfig(&conf.RemoteConfig{}, []byte(remoteConf))
|
||||
@@ -68,7 +71,7 @@ func TestCustomDate(t *testing.T) {
|
||||
}
|
||||
executeResult, _ := json.Marshal(execute.Result)
|
||||
|
||||
customDate := getCustomData(data, id, version)
|
||||
customDate := adapter.GetCustomData(data, id, version)
|
||||
customDateResult, _ := json.Marshal(customDate)
|
||||
|
||||
if !a.Equal(string(customDateResult), string(executeResult)) {
|
||||
@@ -78,9 +81,7 @@ func TestCustomDate(t *testing.T) {
|
||||
|
||||
func BenchmarkGoCustomData(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = getCustomData(data, id, version)
|
||||
//json.Marshal(customDate)
|
||||
|
||||
_ = adapter.GetCustomData(data, id, version)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,7 +135,6 @@ func BenchmarkJsoniterJson(b *testing.B) {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func readFile(name string) ([]byte, error) {
|
||||
@@ -148,5 +148,6 @@ func readFile(name string) ([]byte, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return obj, nil
|
||||
}
|
||||
Reference in new issue
Block a user