deps: Update call sites of hil.Eval from update

hil.Eval() now returns (hil.EvaluationResult, error) instead of (value,
type, error). This commit updates the call sites, but retains all
previous behaviour. Tests are also updated.
This commit is contained in:
James Nugent 2016-04-08 20:23:36 -05:00
parent dc69eced0f
commit a0cc7115b3
4 changed files with 17 additions and 18 deletions

View File

@ -160,15 +160,15 @@ func execute(s string, vars map[string]interface{}) (string, error) {
},
}
out, typ, err := hil.Eval(root, &cfg)
result, err := hil.Eval(root, &cfg)
if err != nil {
return "", err
}
if typ != ast.TypeString {
return "", fmt.Errorf("unexpected output ast.Type: %v", typ)
if result.Type != hil.TypeString {
return "", fmt.Errorf("unexpected output hil.Type: %v", result.Type)
}
return out.(string), nil
return result.Value.(string), nil
}
func hash(s string) string {

View File

@ -450,7 +450,7 @@ func (c *Config) Validate() error {
r.RawCount.interpolate(func(root ast.Node) (string, error) {
// Execute the node but transform the AST so that it returns
// a fixed value of "5" for all interpolations.
out, _, err := hil.Eval(
result, err := hil.Eval(
hil.FixedValueTransform(
root, &ast.LiteralNode{Value: "5", Typex: ast.TypeString}),
nil)
@ -458,7 +458,7 @@ func (c *Config) Validate() error {
return "", err
}
return out.(string), nil
return result.Value.(string), nil
})
_, err := strconv.ParseInt(r.RawCount.Value().(string), 0, 0)
if err != nil {
@ -680,7 +680,7 @@ func (c *Config) validateVarContextFn(
node = node.Accept(func(n ast.Node) ast.Node {
// If it is a concat or variable access, we allow it.
switch n.(type) {
case *ast.Concat:
case *ast.Output:
return n
case *ast.VariableAccess:
return n

View File

@ -1004,16 +1004,16 @@ func TestInterpolateFuncUUID(t *testing.T) {
t.Fatalf("err: %s", err)
}
out, _, err := hil.Eval(ast, langEvalConfig(nil))
result, err := hil.Eval(ast, langEvalConfig(nil))
if err != nil {
t.Fatalf("err: %s", err)
}
if results[out.(string)] {
t.Fatalf("Got unexpected duplicate uuid: %s", out)
if results[result.Value.(string)] {
t.Fatalf("Got unexpected duplicate uuid: %s", result.Value)
}
results[out.(string)] = true
results[result.Value.(string)] = true
}
}
@ -1035,15 +1035,14 @@ func testFunction(t *testing.T, config testFunctionConfig) {
t.Fatalf("Case #%d: input: %#v\nerr: %s", i, tc.Input, err)
}
out, _, err := hil.Eval(ast, langEvalConfig(config.Vars))
result, err := hil.Eval(ast, langEvalConfig(config.Vars))
if err != nil != tc.Error {
t.Fatalf("Case #%d:\ninput: %#v\nerr: %s", i, tc.Input, err)
}
if !reflect.DeepEqual(out, tc.Result) {
t.Fatalf(
"%d: bad output for input: %s\n\nOutput: %#v\nExpected: %#v",
i, tc.Input, out, tc.Result)
if !reflect.DeepEqual(result.Value, tc.Result) {
t.Fatalf("%d: bad output for input: %s\n\nOutput: %#v\nExpected: %#v",
i, tc.Input, result.Value, tc.Result)
}
}
}

View File

@ -132,12 +132,12 @@ func (r *RawConfig) Interpolate(vs map[string]ast.Variable) error {
// None of the variables we need are computed, meaning we should
// be able to properly evaluate.
out, _, err := hil.Eval(root, config)
result, err := hil.Eval(root, config)
if err != nil {
return "", err
}
return out.(string), nil
return result.Value.(string), nil
})
}