github.com/lingyao2333/mo-zero@v1.4.1/core/mapping/valuer_test.go (about)

     1  package mapping
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestMapValuerWithInherit_Value(t *testing.T) {
    10  	input := map[string]interface{}{
    11  		"discovery": map[string]interface{}{
    12  			"host": "localhost",
    13  			"port": 8080,
    14  		},
    15  		"component": map[string]interface{}{
    16  			"name": "test",
    17  		},
    18  	}
    19  	valuer := recursiveValuer{
    20  		current: mapValuer(input["component"].(map[string]interface{})),
    21  		parent: simpleValuer{
    22  			current: mapValuer(input),
    23  		},
    24  	}
    25  
    26  	val, ok := valuer.Value("discovery")
    27  	assert.True(t, ok)
    28  
    29  	m, ok := val.(map[string]interface{})
    30  	assert.True(t, ok)
    31  	assert.Equal(t, "localhost", m["host"])
    32  	assert.Equal(t, 8080, m["port"])
    33  }