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 0d64121 commit 5ad613b
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions confmap/confmap_test.go
Expand Up @@ -759,3 +759,27 @@ func TestUnmarshalOwnThroughEmbeddedSquashedStruct(t *testing.T) {
require.Equal(t, "success", cfg.Cfg.EmbeddedStructWithUnmarshal.success)
require.Equal(t, "bar", cfg.Cfg.EmbeddedStructWithUnmarshal.Foo)
}

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 5ad613b

Please sign in to comment.