util/filter_test.go

58 lines
1.0 KiB
Go
Raw Normal View History

2022-07-04 13:37:16 +08:00
// Package util ...
//
// Description : util ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2022-07-04 12:44
package util
import (
"fmt"
"testing"
)
func Test_filter_Deal(t *testing.T) {
sourceData := `{
"name":"zhangsan",
"age":"18",
"extension":{
"sex":"man",
"height":"180"
}
}`
ruleList := []MapRule{
{
SourcePath: "name",
MapPath: "user_name",
Required: true,
DataType: "string",
DefaultValue: "lalala",
},
{
SourcePath: "age",
MapPath: "user_age",
Required: true,
DataType: "int",
DefaultValue: "280",
},
{
SourcePath: "extension.height",
MapPath: "user_height",
Required: true,
DataType: "int",
DefaultValue: "359",
},
{
SourcePath: "extension.sex",
MapPath: "user_sex",
Required: true,
DataType: "string",
DefaultValue: "lalala",
},
}
instance := NewFilter(sourceData, ruleList)
result, err := instance.Deal()
fmt.Println(string(result), err)
}