From 4e14ab755758c312c8b4664722c0ac4aefcbb005 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Tue, 15 Jan 2019 11:54:51 -0800 Subject: [PATCH] config: Remove "setproduct" function, which is now in lang/funcs --- config/interpolate_funcs.go | 53 -------------------------------- config/interpolate_funcs_test.go | 52 ------------------------------- 2 files changed, 105 deletions(-) diff --git a/config/interpolate_funcs.go b/config/interpolate_funcs.go index 5ce7dc33a2..faa077ee30 100644 --- a/config/interpolate_funcs.go +++ b/config/interpolate_funcs.go @@ -118,7 +118,6 @@ func Funcs() map[string]ast.Function { "min": interpolationFuncMin(), "pathexpand": interpolationFuncPathExpand(), "pow": interpolationFuncPow(), - "setproduct": interpolationFuncSetProduct(), "uuid": interpolationFuncUUID(), "replace": interpolationFuncReplace(), "rsadecrypt": interpolationFuncRsaDecrypt(), @@ -1740,55 +1739,3 @@ func interpolationFuncRsaDecrypt() ast.Function { }, } } - -// interpolationFuncSetProduct implements the "setproduct" function -// that returns the cartesian product of two or more lists or sets -func interpolationFuncSetProduct() ast.Function { - return ast.Function{ - ArgTypes: []ast.Type{ast.TypeList}, - ReturnType: ast.TypeList, - Variadic: true, - VariadicType: ast.TypeList, - Callback: func(args []interface{}) (interface{}, error) { - if len(args) < 2 { - return nil, fmt.Errorf("must provide at least two arguments") - } - - total := 1 - for _, arg := range args { - total *= len(arg.([]ast.Variable)) - } - - if total == 0 { - return nil, fmt.Errorf("empty list provided") - } - - product := make([][]ast.Variable, total) - - b := make([]ast.Variable, total*len(args)) - n := make([]int, len(args)) - s := 0 - - for i := range product { - e := s + len(args) - pi := b[s:e] - product[i] = pi - s = e - - for j, n := range n { - pi[j] = args[j].([]ast.Variable)[n] - } - - for j := len(n) - 1; j >= 0; j-- { - n[j]++ - if n[j] < len(args[j].([]ast.Variable)) { - break - } - n[j] = 0 - } - } - - return listVariableSliceToVariableValue(product), nil - }, - } -} diff --git a/config/interpolate_funcs_test.go b/config/interpolate_funcs_test.go index dc3be5787a..f63d81c30b 100644 --- a/config/interpolate_funcs_test.go +++ b/config/interpolate_funcs_test.go @@ -2960,55 +2960,3 @@ H7CurtMwALQ/n/6LUKFmjRZjqbKX9SO2QSaC3grd6sY9Tu+bZjLe }, }) } - -func TestInterpolateFuncSetProduct(t *testing.T) { - testFunction(t, testFunctionConfig{ - Cases: []testFunctionCase{ - { - `${setproduct(list("dev", "qas", "prd"), list("applicationA", "applicationB", "applicationC"))}`, - []interface{}{ - []interface{}{"dev", "applicationA"}, - []interface{}{"dev", "applicationB"}, - []interface{}{"dev", "applicationC"}, - []interface{}{"qas", "applicationA"}, - []interface{}{"qas", "applicationB"}, - []interface{}{"qas", "applicationC"}, - []interface{}{"prd", "applicationA"}, - []interface{}{"prd", "applicationB"}, - []interface{}{"prd", "applicationC"}}, - false, - }, - { - `${setproduct(list("A", "B"), list("C", "D"), list("E", "F"))}`, - []interface{}{ - []interface{}{"A", "C", "E"}, - []interface{}{"A", "C", "F"}, - []interface{}{"A", "D", "E"}, - []interface{}{"A", "D", "F"}, - []interface{}{"B", "C", "E"}, - []interface{}{"B", "C", "F"}, - []interface{}{"B", "D", "E"}, - []interface{}{"B", "D", "F"}, - }, - false, - }, - { - `${setproduct(list(), list(), list())}`, - nil, - true, - }, - { - `${setproduct(list("foo"),list("bar"))}`, - []interface{}{ - []interface{}{"foo", "bar"}, - }, - false, - }, - { - `${setproduct(list("foo"))}`, - nil, - true, - }, - }, - }) -}