MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / TestGetStruct

Function TestGetStruct

internal/utils/get_test.go:5–49  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

3import "testing"
4
5func TestGetStruct(t *testing.T) {
6 object := struct {
7 Name string
8 Age int
9 Books []string
10 Extend struct {
11 Location struct {
12 City string
13 }
14 }
15 }{
16 Name: "lu",
17 Age: 20,
18 Books: []string{"Golang"},
19 Extend: struct {
20 Location struct {
21 City string
22 }
23 }{
24 Location: struct {
25 City string
26 }{
27 City: "Beijing",
28 },
29 },
30 }
31
32 if Get(object, []string{"Name"}) != "lu" {
33 t.Fatal("[ERROR]Name != lu")
34 }
35
36 if Get(object, []string{"Age"}) != 20 {
37 t.Fatal("[ERROR]Age != 20")
38 }
39
40 if Get(object, []string{"Books", "0"}) != "Golang" {
41 t.Fatal("[ERROR]books.0 != Golang")
42 }
43
44 t.Log("Extend.Location:", Get(object, []string{"Extend", "Location"}))
45
46 if Get(object, []string{"Extend", "Location", "City"}) != "Beijing" {
47 t.Fatal("[ERROR]Extend.Location.City != Beijing")
48 }
49}
50
51func TestGetMap(t *testing.T) {
52 object := map[string]interface{}{

Callers

nothing calls this directly

Calls 2

GetFunction · 0.85
LogMethod · 0.80

Tested by

no test coverage detected