github.com/databricks/cli@v0.203.0/bundle/config/interpolation/lookup_test.go (about)

     1  package interpolation
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  	"github.com/stretchr/testify/require"
     8  )
     9  
    10  type interpolationFixture struct {
    11  	A map[string]string `json:"a"`
    12  	B map[string]string `json:"b"`
    13  	C map[string]string `json:"c"`
    14  }
    15  
    16  func fixture() interpolationFixture {
    17  	return interpolationFixture{
    18  		A: map[string]string{
    19  			"x": "1",
    20  		},
    21  		B: map[string]string{
    22  			"x": "2",
    23  		},
    24  		C: map[string]string{
    25  			"ax": "${a.x}",
    26  			"bx": "${b.x}",
    27  		},
    28  	}
    29  }
    30  
    31  func TestExcludePath(t *testing.T) {
    32  	tmp := fixture()
    33  	m := interpolate{
    34  		fns: []LookupFunction{
    35  			ExcludeLookupsInPath("a"),
    36  		},
    37  	}
    38  
    39  	err := m.expand(&tmp)
    40  	require.NoError(t, err)
    41  
    42  	assert.Equal(t, "1", tmp.A["x"])
    43  	assert.Equal(t, "2", tmp.B["x"])
    44  	assert.Equal(t, "${a.x}", tmp.C["ax"])
    45  	assert.Equal(t, "2", tmp.C["bx"])
    46  }
    47  
    48  func TestIncludePath(t *testing.T) {
    49  	tmp := fixture()
    50  	m := interpolate{
    51  		fns: []LookupFunction{
    52  			IncludeLookupsInPath("a"),
    53  		},
    54  	}
    55  
    56  	err := m.expand(&tmp)
    57  	require.NoError(t, err)
    58  
    59  	assert.Equal(t, "1", tmp.A["x"])
    60  	assert.Equal(t, "2", tmp.B["x"])
    61  	assert.Equal(t, "1", tmp.C["ax"])
    62  	assert.Equal(t, "${b.x}", tmp.C["bx"])
    63  }
    64  
    65  func TestIncludePathMultiple(t *testing.T) {
    66  	tmp := fixture()
    67  	m := interpolate{
    68  		fns: []LookupFunction{
    69  			IncludeLookupsInPath("a"),
    70  			IncludeLookupsInPath("b"),
    71  		},
    72  	}
    73  
    74  	err := m.expand(&tmp)
    75  	require.NoError(t, err)
    76  
    77  	assert.Equal(t, "1", tmp.A["x"])
    78  	assert.Equal(t, "2", tmp.B["x"])
    79  	assert.Equal(t, "1", tmp.C["ax"])
    80  	assert.Equal(t, "2", tmp.C["bx"])
    81  }