util/reflect: import own path based interface lookup
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
34
util/reflect/path_test.go
Normal file
34
util/reflect/path_test.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package reflect
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPath(t *testing.T) {
|
||||
|
||||
type Nested2 struct {
|
||||
Name string
|
||||
}
|
||||
type Nested1 struct {
|
||||
Nested2 Nested2
|
||||
}
|
||||
type Config struct {
|
||||
Nested1 Nested1
|
||||
}
|
||||
|
||||
cfg := &Config{
|
||||
Nested1: Nested1{
|
||||
Nested2: Nested2{
|
||||
Name: "NAME",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
v, err := Lookup(cfg, "$.Nested1.Nested2.Name")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if v.String() != "NAME" {
|
||||
t.Fatalf("lookup returns invalid value: %v", v)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user