@@ -34,7 +34,7 @@ func TestDeepGetSimpleDotPrefix(t *testing.T) {
3434 item := context.RuntimeContainer {
3535 ID : "expected" ,
3636 }
37- value := deepGet (item , "... ID" )
37+ value := deepGet (item , ".ID" )
3838 assert .IsType (t , "" , value )
3939
4040 assert .Equal (t , "expected" , value )
@@ -51,3 +51,45 @@ func TestDeepGetMap(t *testing.T) {
5151
5252 assert .Equal (t , "value" , value )
5353}
54+
55+ func TestDeepGet (t * testing.T ) {
56+ s := struct { X string }{"foo" }
57+ sp := & s
58+
59+ for _ , tc := range []struct {
60+ desc string
61+ item interface {}
62+ path string
63+ want interface {}
64+ }{
65+ {
66+ "map key empty string" ,
67+ map [string ]map [string ]map [string ]string {
68+ "" : map [string ]map [string ]string {
69+ "" : map [string ]string {
70+ "" : "foo" ,
71+ },
72+ },
73+ },
74+ "..." ,
75+ "foo" ,
76+ },
77+ {"struct" , s , "X" , "foo" },
78+ {"pointer to struct" , sp , "X" , "foo" },
79+ {"double pointer to struct" , & sp , ".X" , nil },
80+ {"slice index" , []string {"foo" , "bar" }, "1" , "bar" },
81+ {"slice index out of bounds" , []string {}, "0" , nil },
82+ {"slice index negative" , []string {}, "-1" , nil },
83+ {"slice index nonnumber" , []string {}, "foo" , nil },
84+ {"array index" , [2 ]string {"foo" , "bar" }, "1" , "bar" },
85+ {"array index out of bounds" , [1 ]string {"foo" }, "1" , nil },
86+ {"array index negative" , [1 ]string {"foo" }, "-1" , nil },
87+ {"array index nonnumber" , [1 ]string {"foo" }, "foo" , nil },
88+ } {
89+ t .Run (tc .desc , func (t * testing.T ) {
90+ got := deepGet (tc .item , tc .path )
91+ assert .IsType (t , tc .want , got )
92+ assert .Equal (t , tc .want , got )
93+ })
94+ }
95+ }
0 commit comments