File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -181,4 +181,35 @@ func TestDync(t *testing.T) {
181181 assert .ThatError (t , err ).Matches ("strconv.ParseInt: parsing \\ \" xyz\\ \" : invalid syntax" )
182182 assert .That (t , p .ObjectsCount ()).Equal (4 )
183183 })
184+
185+ t .Run ("refresh struct" , func (t * testing.T ) {
186+ p := New (conf .Map (map [string ]interface {}{
187+ "config.s1.value" : "99" ,
188+ }))
189+
190+ v := & Value [struct {
191+ S1 struct {
192+ Value int `value:"${value}"`
193+ } `value:"${s1}"`
194+ }]{}
195+
196+ var param conf.BindParam
197+ err := param .BindTag ("${config}" , "" )
198+ assert .Nil (t , err )
199+
200+ err = p .RefreshField (reflect .ValueOf (v ), param )
201+ assert .Nil (t , err )
202+ assert .That (t , v .Value ().S1 .Value ).Equal (99 )
203+
204+ err = p .Refresh (conf .Map (map [string ]interface {}{
205+ "config.s1.value" : "xyz" ,
206+ }))
207+ assert .ThatError (t , err ).Matches ("strconv.ParseInt: parsing \" xyz\" : invalid syntax" )
208+
209+ err = p .Refresh (conf .Map (map [string ]interface {}{
210+ "config.s1.value" : "10" ,
211+ }))
212+ assert .Nil (t , err )
213+ assert .That (t , v .Value ().S1 .Value ).Equal (10 )
214+ })
184215}
You can’t perform that action at this time.
0 commit comments