2022-12-01 21:38:49 +00:00
|
|
|
package interpolation
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2022-12-12 09:30:17 +00:00
|
|
|
type interpolationFixture struct {
|
|
|
|
A map[string]string `json:"a"`
|
|
|
|
B map[string]string `json:"b"`
|
|
|
|
C map[string]string `json:"c"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func fixture() interpolationFixture {
|
|
|
|
return interpolationFixture{
|
2022-12-01 21:38:49 +00:00
|
|
|
A: map[string]string{
|
|
|
|
"x": "1",
|
|
|
|
},
|
|
|
|
B: map[string]string{
|
|
|
|
"x": "2",
|
|
|
|
},
|
|
|
|
C: map[string]string{
|
|
|
|
"ax": "${a.x}",
|
|
|
|
"bx": "${b.x}",
|
|
|
|
},
|
|
|
|
}
|
2022-12-12 09:30:17 +00:00
|
|
|
}
|
2022-12-01 21:38:49 +00:00
|
|
|
|
2022-12-12 09:30:17 +00:00
|
|
|
func TestExcludePath(t *testing.T) {
|
|
|
|
tmp := fixture()
|
2022-12-01 21:38:49 +00:00
|
|
|
m := interpolate{
|
2022-12-12 09:48:52 +00:00
|
|
|
fns: []LookupFunction{
|
|
|
|
ExcludeLookupsInPath("a"),
|
|
|
|
},
|
2022-12-01 21:38:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err := m.expand(&tmp)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
assert.Equal(t, "1", tmp.A["x"])
|
|
|
|
assert.Equal(t, "2", tmp.B["x"])
|
|
|
|
assert.Equal(t, "${a.x}", tmp.C["ax"])
|
|
|
|
assert.Equal(t, "2", tmp.C["bx"])
|
|
|
|
}
|
2022-12-12 09:30:17 +00:00
|
|
|
|
|
|
|
func TestIncludePath(t *testing.T) {
|
|
|
|
tmp := fixture()
|
|
|
|
m := interpolate{
|
2022-12-12 09:48:52 +00:00
|
|
|
fns: []LookupFunction{
|
|
|
|
IncludeLookupsInPath("a"),
|
|
|
|
},
|
2022-12-12 09:30:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err := m.expand(&tmp)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
assert.Equal(t, "1", tmp.A["x"])
|
|
|
|
assert.Equal(t, "2", tmp.B["x"])
|
|
|
|
assert.Equal(t, "1", tmp.C["ax"])
|
|
|
|
assert.Equal(t, "${b.x}", tmp.C["bx"])
|
|
|
|
}
|
2022-12-12 09:48:52 +00:00
|
|
|
|
|
|
|
func TestIncludePathMultiple(t *testing.T) {
|
|
|
|
tmp := fixture()
|
|
|
|
m := interpolate{
|
|
|
|
fns: []LookupFunction{
|
|
|
|
IncludeLookupsInPath("a"),
|
|
|
|
IncludeLookupsInPath("b"),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
err := m.expand(&tmp)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
assert.Equal(t, "1", tmp.A["x"])
|
|
|
|
assert.Equal(t, "2", tmp.B["x"])
|
|
|
|
assert.Equal(t, "1", tmp.C["ax"])
|
|
|
|
assert.Equal(t, "2", tmp.C["bx"])
|
|
|
|
}
|