mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-08 03:00:27 +08:00
WAF增加多个动作
This commit is contained in:
46
internal/utils/jsonutils/map_test.go
Normal file
46
internal/utils/jsonutils/map_test.go
Normal file
@@ -0,0 +1,46 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package jsonutils
|
||||
|
||||
import (
|
||||
"github.com/iwind/TeaGo/assert"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestMapToObject(t *testing.T) {
|
||||
a := assert.NewAssertion(t)
|
||||
|
||||
type typeA struct {
|
||||
B int `json:"b"`
|
||||
C bool `json:"c"`
|
||||
}
|
||||
|
||||
{
|
||||
var obj = &typeA{B: 1, C: true}
|
||||
m, err := ObjectToMap(obj)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
PrintT(m, t)
|
||||
a.IsTrue(m.GetInt("b") == 1)
|
||||
a.IsTrue(m.GetBool("c") == true)
|
||||
}
|
||||
|
||||
{
|
||||
var obj = &typeA{}
|
||||
err := MapToObject(maps.Map{
|
||||
"b": 1024,
|
||||
"c": true,
|
||||
}, obj)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if obj == nil {
|
||||
t.Fatal("obj should not be nil")
|
||||
}
|
||||
a.IsTrue(obj.B == 1024)
|
||||
a.IsTrue(obj.C == true)
|
||||
PrintT(obj, t)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user