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

Function TestDecodeFrom_EmbeddedSquashConfig

mapstructure_test.go:857–911  ·  mapstructure_test.go::TestDecodeFrom_EmbeddedSquashConfig
(t *testing.T)

Source from the content-addressed store, hash-verified

855}
856
857func TestDecodeFrom_EmbeddedSquashConfig(t *testing.T) {
858 t.Parallel()
859
860 input := EmbeddedAndNamed{
861 Basic: Basic{Vstring: "foo"},
862 Named: Basic{Vstring: "baz"},
863 Vunique: "bar",
864 }
865
866 result := map[string]interface{}{}
867 config := &DecoderConfig{
868 Squash: true,
869 Result: &result,
870 }
871 decoder, err := NewDecoder(config)
872 if err != nil {
873 t.Fatalf("got an err: %s", err.Error())
874 }
875
876 err = decoder.Decode(input)
877 if err != nil {
878 t.Fatalf("got an err: %s", err.Error())
879 }
880
881 if _, ok := result["Basic"]; ok {
882 t.Error("basic should not be present in map")
883 }
884
885 v, ok := result["Vstring"]
886 if !ok {
887 t.Error("vstring should be present in map")
888 } else if !reflect.DeepEqual(v, "foo") {
889 t.Errorf("vstring value should be 'foo': %#v", v)
890 }
891
892 v, ok = result["Vunique"]
893 if !ok {
894 t.Error("vunique should be present in map")
895 } else if !reflect.DeepEqual(v, "bar") {
896 t.Errorf("vunique value should be 'bar': %#v", v)
897 }
898
899 v, ok = result["Named"]
900 if !ok {
901 t.Error("Named should be present in map")
902 } else {
903 named := v.(map[string]interface{})
904 v, ok := named["Vstring"]
905 if !ok {
906 t.Error("Named: vstring should be present in map")
907 } else if !reflect.DeepEqual(v, "baz") {
908 t.Errorf("Named: vstring should be 'baz': %#v", v)
909 }
910 }
911}
912
913func TestDecodeFrom_EmbeddedSquashConfig_WithTags(t *testing.T) {
914 t.Parallel()

Callers

nothing calls this directly

Calls 3

DecodeMethod · 0.95
NewDecoderFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected