util/reflect: import own path based interface lookup

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2021-02-14 23:33:01 +03:00
parent c2333a9f35
commit 67748a2132
2 changed files with 291 additions and 0 deletions

34
util/reflect/path_test.go Normal file
View 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)
}
}