From a0cc7115b372891a72bdcf802f70f72c20c1ab72 Mon Sep 17 00:00:00 2001 From: James Nugent Date: Fri, 8 Apr 2016 20:23:36 -0500 Subject: [PATCH] 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. --- .../template/resource_template_file.go | 8 ++++---- config/config.go | 6 +++--- config/interpolate_funcs_test.go | 17 ++++++++--------- config/raw_config.go | 4 ++-- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/builtin/providers/template/resource_template_file.go b/builtin/providers/template/resource_template_file.go index 78fdf8326..c5b3b3b09 100644 --- a/builtin/providers/template/resource_template_file.go +++ b/builtin/providers/template/resource_template_file.go @@ -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 { diff --git a/config/config.go b/config/config.go index 6b8d1f807..38578ae49 100644 --- a/config/config.go +++ b/config/config.go @@ -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 diff --git a/config/interpolate_funcs_test.go b/config/interpolate_funcs_test.go index 123ee39f3..774a7bf45 100644 --- a/config/interpolate_funcs_test.go +++ b/config/interpolate_funcs_test.go @@ -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) } } } diff --git a/config/raw_config.go b/config/raw_config.go index c897ed387..6fc15ebd5 100644 --- a/config/raw_config.go +++ b/config/raw_config.go @@ -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 }) }