Skip to content

Commit

Permalink
add TestRecursiveUnmarshaling
Browse files Browse the repository at this point in the history
  • Loading branch information
atoulme committed Apr 3, 2024
1 parent bf7bb60 commit 8637f2f
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions confmap/confmap_test.go
Expand Up @@ -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)
}

0 comments on commit 8637f2f

Please sign in to comment.