github.com/ouraigua/jenkins-library@v0.0.0-20231028010029-fbeaf2f3aa9b/pkg/config/interpolation/interpolation_test.go (about)

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