valuer_test.go 669 B

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