From 8637f2f715a45c389524a832a6a52aca710fbdce Mon Sep 17 00:00:00 2001 From: Antoine Toulme Date: Tue, 2 Apr 2024 17:14:20 -0700 Subject: [PATCH] add TestRecursiveUnmarshaling --- confmap/confmap_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/confmap/confmap_test.go b/confmap/confmap_test.go index 03662af4171..fe5c5db0123 100644 --- a/confmap/confmap_test.go +++ b/confmap/confmap_test.go @@ -614,3 +614,27 @@ func TestZeroSliceHookFunc(t *testing.T) { }) } } + +type Recursive struct { + Foo string `mapstructure:"foo"` +} + +func (r *Recursive) Unmarshal(conf *Conf) error { + newR := &Recursive{} + if err := conf.Unmarshal(newR); err != nil { + return err + } + *r = *newR + return nil +} + +// Tests that a struct can unmarshal itself by creating a new copy of itself, unmarshaling itself, and setting its value. +func TestRecursiveUnmarshaling(t *testing.T) { + t.Skip("this test fails to run because it engages in recursive unmarshaling") + conf := NewFromStringMap(map[string]any{ + "foo": "something", + }) + r := &Recursive{} + require.NoError(t, conf.Unmarshal(r)) + require.Equal(t, "something", r.Foo) +}