80 lines
1.5 KiB
Go
80 lines
1.5 KiB
Go
|
// Package filter ...
|
||
|
//
|
||
|
// Description : filter ...
|
||
|
//
|
||
|
// Author : go_developer@163.com<白茶清欢>
|
||
|
//
|
||
|
// Date : 2023-01-01 17:00
|
||
|
package filter
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"github.com/smartystreets/goconvey/convey"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
// TestNewFilter ...
|
||
|
//
|
||
|
// Author : go_developer@163.com<白茶清欢>
|
||
|
//
|
||
|
// Date : 17:00 2023/1/1
|
||
|
func TestNewFilter(t *testing.T) {
|
||
|
var (
|
||
|
err error
|
||
|
)
|
||
|
testData := `{
|
||
|
"base":{
|
||
|
"name":"go_developer",
|
||
|
"age":18,
|
||
|
"height":180
|
||
|
},
|
||
|
"company":{
|
||
|
"name":"wajijiwa",
|
||
|
"start":"2023-01-01"
|
||
|
}
|
||
|
}`
|
||
|
filterRuleList := []MapRule{
|
||
|
{
|
||
|
SourcePath: "base.name",
|
||
|
MapPath: "user_name",
|
||
|
Required: true,
|
||
|
DataType: "string",
|
||
|
DefaultValue: "",
|
||
|
},
|
||
|
{
|
||
|
SourcePath: "base.age",
|
||
|
MapPath: "user_age",
|
||
|
Required: true,
|
||
|
DataType: "int",
|
||
|
DefaultValue: "",
|
||
|
},
|
||
|
{
|
||
|
SourcePath: "base.height",
|
||
|
MapPath: "user_height",
|
||
|
Required: true,
|
||
|
DataType: "string",
|
||
|
DefaultValue: "",
|
||
|
},
|
||
|
{
|
||
|
SourcePath: "company.name",
|
||
|
MapPath: "company_name",
|
||
|
Required: true,
|
||
|
DataType: "string",
|
||
|
DefaultValue: "",
|
||
|
},
|
||
|
{
|
||
|
SourcePath: "company.start",
|
||
|
MapPath: "company_start",
|
||
|
Required: true,
|
||
|
DataType: "string",
|
||
|
DefaultValue: "",
|
||
|
},
|
||
|
}
|
||
|
f := NewFilter(testData, filterRuleList)
|
||
|
convey.Convey("基础对象重写", t, func() {
|
||
|
err = f.Deal()
|
||
|
convey.So(err, convey.ShouldEqual, nil)
|
||
|
fmt.Println(f.String())
|
||
|
})
|
||
|
}
|