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

Function TestDecodeFrom_EmbeddedSquash

mapstructure_test.go:661–697  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

659}
660
661func TestDecodeFrom_EmbeddedSquash(t *testing.T) {
662 t.Parallel()
663
664 var v interface{}
665 var ok bool
666
667 input := EmbeddedSquash{
668 Basic: Basic{
669 Vstring: "foo",
670 },
671 Vunique: "bar",
672 }
673
674 var result map[string]interface{}
675 err := Decode(input, &result)
676 if err != nil {
677 t.Fatalf("got an err: %s", err.Error())
678 }
679
680 if _, ok = result["Basic"]; ok {
681 t.Error("basic should not be present in map")
682 }
683
684 v, ok = result["Vstring"]
685 if !ok {
686 t.Error("vstring should be present in map")
687 } else if !reflect.DeepEqual(v, "foo") {
688 t.Errorf("vstring value should be 'foo': %#v", v)
689 }
690
691 v, ok = result["Vunique"]
692 if !ok {
693 t.Error("vunique should be present in map")
694 } else if !reflect.DeepEqual(v, "bar") {
695 t.Errorf("vunique value should be 'bar': %#v", v)
696 }
697}
698
699func TestDecode_EmbeddedPointerSquash_FromStructToMap(t *testing.T) {
700 t.Parallel()

Callers

nothing calls this directly

Calls 2

DecodeFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected