2020-09-16 14:50:09 +02:00
|
|
|
package interpolation
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestResolveMap(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
2020-10-13 14:14:47 +02:00
|
|
|
t.Run("That lookup works", func(t *testing.T) {
|
2020-09-16 14:50:09 +02:00
|
|
|
testMap := map[string]interface{}{
|
|
|
|
"prop1": "val1",
|
|
|
|
"prop2": "val2",
|
|
|
|
"prop3": "$(prop1)/$(prop2)",
|
|
|
|
}
|
|
|
|
|
2020-10-13 14:14:47 +02:00
|
|
|
ok := ResolveMap(testMap)
|
|
|
|
assert.True(t, ok)
|
2020-09-16 14:50:09 +02:00
|
|
|
|
|
|
|
assert.Equal(t, "val1/val2", testMap["prop3"])
|
|
|
|
})
|
|
|
|
|
2020-10-13 14:14:47 +02:00
|
|
|
t.Run("That lookups fails when property is not found", func(t *testing.T) {
|
|
|
|
testMap := map[string]interface{}{
|
|
|
|
"prop1": "val1",
|
|
|
|
"prop2": "val2",
|
|
|
|
"prop3": "$(prop1)/$(prop2)/$(prop5)",
|
|
|
|
}
|
|
|
|
|
|
|
|
ok := ResolveMap(testMap)
|
|
|
|
assert.False(t, ok)
|
|
|
|
})
|
|
|
|
|
2020-09-16 14:50:09 +02:00
|
|
|
t.Run("That resolve loops are aborted", func(t *testing.T) {
|
|
|
|
testMap := map[string]interface{}{
|
|
|
|
"prop1": "$(prop2)",
|
|
|
|
"prop2": "$(prop1)",
|
|
|
|
}
|
2020-10-13 14:14:47 +02:00
|
|
|
ok := ResolveMap(testMap)
|
|
|
|
assert.False(t, ok)
|
2020-09-16 14:50:09 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
}
|