config: error if variable interpolation can't find variable

This commit is contained in:
Mitchell Hashimoto 2014-07-22 06:51:02 -07:00
parent 7578fb8bdc
commit aeb085c5f0
2 changed files with 22 additions and 1 deletions

View File

@ -193,7 +193,13 @@ func (i *VariableInterpolation) FullString() string {
func (i *VariableInterpolation) Interpolate(
vs map[string]string) (string, error) {
return vs[i.key], nil
v, ok := vs[i.key]
if !ok {
return "", fmt.Errorf(
"%s: value for variable '%s' not found", v)
}
return v, nil
}
func (i *VariableInterpolation) Variables() map[string]InterpolatedVariable {

View File

@ -273,3 +273,18 @@ func TestVariableInterpolation(t *testing.T) {
t.Fatalf("bad: %#v", actual)
}
}
func TestVariableInterpolation_missing(t *testing.T) {
uv, err := NewUserVariable("var.foo")
if err != nil {
t.Fatalf("err: %s", err)
}
i := &VariableInterpolation{Variable: uv, key: "var.foo"}
_, err = i.Interpolate(map[string]string{
"var.bar": "bar",
})
if err == nil {
t.Fatal("should error")
}
}