mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-17 19:00:25 +08:00
实现WAF
This commit is contained in:
79
internal/utils/get_test.go
Normal file
79
internal/utils/get_test.go
Normal file
@@ -0,0 +1,79 @@
|
||||
package utils
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestGetStruct(t *testing.T) {
|
||||
object := struct {
|
||||
Name string
|
||||
Age int
|
||||
Books []string
|
||||
Extend struct {
|
||||
Location struct {
|
||||
City string
|
||||
}
|
||||
}
|
||||
}{
|
||||
Name: "lu",
|
||||
Age: 20,
|
||||
Books: []string{"Golang"},
|
||||
Extend: struct {
|
||||
Location struct {
|
||||
City string
|
||||
}
|
||||
}{
|
||||
Location: struct {
|
||||
City string
|
||||
}{
|
||||
City: "Beijing",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
if Get(object, []string{"Name"}) != "lu" {
|
||||
t.Fatal("[ERROR]Name != lu")
|
||||
}
|
||||
|
||||
if Get(object, []string{"Age"}) != 20 {
|
||||
t.Fatal("[ERROR]Age != 20")
|
||||
}
|
||||
|
||||
if Get(object, []string{"Books", "0"}) != "Golang" {
|
||||
t.Fatal("[ERROR]books.0 != Golang")
|
||||
}
|
||||
|
||||
t.Log("Extend.Location:", Get(object, []string{"Extend", "Location"}))
|
||||
|
||||
if Get(object, []string{"Extend", "Location", "City"}) != "Beijing" {
|
||||
t.Fatal("[ERROR]Extend.Location.City != Beijing")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetMap(t *testing.T) {
|
||||
object := map[string]interface{}{
|
||||
"Name": "lu",
|
||||
"Age": 20,
|
||||
"Extend": map[string]interface{}{
|
||||
"Location": map[string]interface{}{
|
||||
"City": "Beijing",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
if Get(object, []string{"Name"}) != "lu" {
|
||||
t.Fatal("[ERROR]Name != lu")
|
||||
}
|
||||
|
||||
if Get(object, []string{"Age"}) != 20 {
|
||||
t.Fatal("[ERROR]Age != 20")
|
||||
}
|
||||
|
||||
if Get(object, []string{"Books", "0"}) != nil {
|
||||
t.Fatal("[ERROR]books.0 != nil")
|
||||
}
|
||||
|
||||
t.Log(Get(object, []string{"Extend", "Location"}))
|
||||
|
||||
if Get(object, []string{"Extend", "Location", "City"}) != "Beijing" {
|
||||
t.Fatal("[ERROR]Extend.Location.City != Beijing")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user