MCPcopy
hub / github.com/mitchellh/mapstructure / TestDecode_EmbeddedSquashConfig

Function TestDecode_EmbeddedSquashConfig

mapstructure_test.go:817–855  ·  mapstructure_test.go::TestDecode_EmbeddedSquashConfig
(t *testing.T)

Source from the content-addressed store, hash-verified

815}
816
817func TestDecode_EmbeddedSquashConfig(t *testing.T) {
818 t.Parallel()
819
820 input := map[string]interface{}{
821 "vstring": "foo",
822 "vunique": "bar",
823 "Named": map[string]interface{}{
824 "vstring": "baz",
825 },
826 }
827
828 var result EmbeddedAndNamed
829 config := &DecoderConfig{
830 Squash: true,
831 Result: &result,
832 }
833
834 decoder, err := NewDecoder(config)
835 if err != nil {
836 t.Fatalf("err: %s", err)
837 }
838
839 err = decoder.Decode(input)
840 if err != nil {
841 t.Fatalf("got an err: %s", err)
842 }
843
844 if result.Vstring != "foo" {
845 t.Errorf("vstring value should be 'foo': %#v", result.Vstring)
846 }
847
848 if result.Vunique != "bar" {
849 t.Errorf("vunique value should be 'bar': %#v", result.Vunique)
850 }
851
852 if result.Named.Vstring != "baz" {
853 t.Errorf("Named.vstring value should be 'baz': %#v", result.Named.Vstring)
854 }
855}
856
857func TestDecodeFrom_EmbeddedSquashConfig(t *testing.T) {
858 t.Parallel()

Callers

nothing calls this directly

Calls 2

DecodeMethod · 0.95
NewDecoderFunction · 0.85

Tested by

no test coverage detected