github.com/jaylevin/jenkins-library@v1.230.4/pkg/config/interpolation/interpolation_test.go (about) 1 package interpolation 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func TestResolveMap(t *testing.T) { 10 t.Parallel() 11 12 t.Run("That lookup works", func(t *testing.T) { 13 testMap := map[string]interface{}{ 14 "prop1": "val1", 15 "prop2": "val2", 16 "prop3": "$(prop1)/$(prop2)", 17 } 18 19 ok := ResolveMap(testMap) 20 assert.True(t, ok) 21 22 assert.Equal(t, "val1/val2", testMap["prop3"]) 23 }) 24 25 t.Run("That lookups fails when property is not found", func(t *testing.T) { 26 testMap := map[string]interface{}{ 27 "prop1": "val1", 28 "prop2": "val2", 29 "prop3": "$(prop1)/$(prop2)/$(prop5)", 30 } 31 32 ok := ResolveMap(testMap) 33 assert.False(t, ok) 34 }) 35 36 t.Run("That resolve loops are aborted", func(t *testing.T) { 37 testMap := map[string]interface{}{ 38 "prop1": "$(prop2)", 39 "prop2": "$(prop1)", 40 } 41 ok := ResolveMap(testMap) 42 assert.False(t, ok) 43 }) 44 45 }