diff --git a/funcs/aws.go b/funcs/aws.go index a251ced24..94bcc38f9 100644 --- a/funcs/aws.go +++ b/funcs/aws.go @@ -11,7 +11,7 @@ import ( var mapStringString = cel.MapType(cel.StringType, cel.StringType) -var arnToMap = cel.Function("arnToMap", +var arnToMap = cel.Function("aws.arnToMap", cel.Overload("arnToMap", []*cel.Type{ cel.StringType, @@ -31,7 +31,7 @@ var arnToMap = cel.Function("arnToMap", ), ) -var fromAwsMap = cel.Function("fromAWSMap", +var fromAwsMap = cel.Function("aws.fromAWSMap", cel.Overload("fromAWSMap_list_map", []*cel.Type{ cel.ListType(cel.MapType(cel.StringType, cel.StringType)), diff --git a/funcs/cel_exports.go b/funcs/cel_exports.go index af22a45e3..e0ba30ce6 100644 --- a/funcs/cel_exports.go +++ b/funcs/cel_exports.go @@ -60,12 +60,9 @@ var CelEnvOption = []cel.EnvOption{ cryptoSHA512_256BytesGen, // JSON - dataJSONGen, dataJSONMemberGen, - dataToJSONGen2, - dataJSONArrayGen, - dataJSONArrayMemberGen, dataToJSONGen, + dataJSONArrayMemberGen, dataToJSONPrettyGen, // YAML @@ -133,11 +130,10 @@ var CelEnvOption = []cel.EnvOption{ stringsHumanDurationGen, stringsHumanSizeGen, - stringsHumanDurationGen2, - stringsHumanSizeGen2, stringsSemverGen, stringsSemverCompareGen, - stringsAbbrevGen, + stringsAbbrevWidthGen, + stringsAbbrevWidthAndOffsetGen, stringsReplaceAllGen, stringsContainsGen, stringsRepeatGen, @@ -151,6 +147,7 @@ var CelEnvOption = []cel.EnvOption{ stringsTrimSpaceGen, stringsTruncGen, stringsIndentGen, + stringsIndentWithWidthGen, stringsSlugGen, stringsQuoteGen, stringsShellQuoteGen, @@ -159,6 +156,7 @@ var CelEnvOption = []cel.EnvOption{ stringsCamelCaseGen, stringsKebabCaseGen, stringsWordWrapGen, + stringsWordWrapSeqAndWidthGen, stringsRuneCountGen, testAssertGen, diff --git a/funcs/data_gen.go b/funcs/data_gen.go index cdd810789..7b70fb629 100644 --- a/funcs/data_gen.go +++ b/funcs/data_gen.go @@ -12,27 +12,6 @@ import ( "github.com/flanksource/gomplate/v3/data" ) -var dataJSONGen = cel.Function("JSON", - cel.Overload("JSON_interface{}", - - []*cel.Type{ - cel.DynType, - }, - cel.DynType, - cel.FunctionBinding(func(args ...ref.Val) ref.Val { - - var x DataFuncs - - result, err := x.JSON(args[0]) - if err != nil { - return types.WrapErr(err) - } - return types.DefaultTypeAdapter.NativeToValue(result) - - }), - ), -) - var dataJSONMemberGen = cel.Function("JSON", cel.MemberOverload(".string.JSON()", []*cel.Type{ @@ -50,23 +29,6 @@ var dataJSONMemberGen = cel.Function("JSON", ), ) -var dataJSONArrayGen = cel.Function("JSONArray", - cel.Overload("JSONArray_interface{}", - []*cel.Type{ - cel.DynType, - }, - cel.DynType, - cel.FunctionBinding(func(args ...ref.Val) ref.Val { - var x DataFuncs - result, err := x.JSONArray(args[0]) - if err != nil { - return types.WrapErr(err) - } - return types.DefaultTypeAdapter.NativeToValue(result) - }), - ), -) - var dataJSONArrayMemberGen = cel.Function("JSONArray", cel.MemberOverload(".string.JSONArray()", []*cel.Type{ @@ -274,17 +236,6 @@ func toJson(val ref.Val) ref.Val { } var dataToJSONGen = cel.Function("toJSON", - cel.Overload("toJSON_string", - - []*cel.Type{ - cel.DynType, - }, - cel.StringType, - cel.UnaryBinding(toJson), - ), -) - -var dataToJSONGen2 = cel.Function("toJSON", cel.MemberOverload("dyn_toJSON", []*cel.Type{ cel.DynType, @@ -295,18 +246,17 @@ var dataToJSONGen2 = cel.Function("toJSON", ) var dataToJSONPrettyGen = cel.Function("toJSONPretty", - cel.Overload("toJSONPretty_interface{}", + cel.MemberOverload("toJSONPretty_interface{}", []*cel.Type{ - cel.StringType, cel.DynType, + cel.DynType, cel.StringType, }, cel.StringType, cel.FunctionBinding(func(args ...ref.Val) ref.Val { - result, err := data.ToJSONPretty(args[0].Value().(string), args[1].Value()) + result, err := data.ToJSONPretty(args[1].Value().(string), args[0].Value()) if err != nil { return types.WrapErr(err) } return types.String(result) - }), ), ) diff --git a/funcs/strings_gen.go b/funcs/strings_gen.go index e839a6e66..15a119a51 100644 --- a/funcs/strings_gen.go +++ b/funcs/strings_gen.go @@ -3,6 +3,8 @@ package funcs import ( + "sort" + "github.com/google/cel-go/cel" "github.com/google/cel-go/common/types" "github.com/google/cel-go/common/types/ref" @@ -10,36 +12,12 @@ import ( var stringsHumanDurationGen = cel.Function("HumanDuration", cel.Overload("HumanDuration_interface{}", - - []*cel.Type{ - cel.DynType, - }, - cel.StringType, - cel.FunctionBinding(func(args ...ref.Val) ref.Val { - - var x StringFuncs - - result, err := x.HumanDuration(args[0]) - if err != nil { - return types.WrapErr(err) - } - return types.String(result) - - }), - ), -) - -var stringsHumanDurationGen2 = cel.Function("humanDuration", - cel.Overload("humanDuration_interface{}", - []*cel.Type{ cel.DynType, }, cel.StringType, cel.FunctionBinding(func(args ...ref.Val) ref.Val { - var x StringFuncs - result, err := x.HumanDuration(args[0]) if err != nil { return types.WrapErr(err) @@ -50,8 +28,6 @@ var stringsHumanDurationGen2 = cel.Function("humanDuration", ), ) - - var stringsHumanSizeGen = cel.Function("HumanSize", cel.Overload("HumanSize_interface{}", []*cel.Type{ @@ -59,29 +35,7 @@ var stringsHumanSizeGen = cel.Function("HumanSize", }, cel.StringType, cel.FunctionBinding(func(args ...ref.Val) ref.Val { - var x StringFuncs - - result, err := x.HumanSize(args[0].Value()) - if err != nil { - return types.WrapErr(err) - } - return types.String(result) - - }), - ), -) - -var stringsHumanSizeGen2 = cel.Function("humanSize", - cel.Overload("humanSize_interface{}", - []*cel.Type{ - cel.DynType, - }, - cel.StringType, - cel.FunctionBinding(func(args ...ref.Val) ref.Val { - - var x StringFuncs - result, err := x.HumanSize(args[0].Value()) if err != nil { return types.WrapErr(err) @@ -132,27 +86,38 @@ var stringsSemverCompareGen = cel.Function("SemverCompare", ), ) -var stringsAbbrevGen = cel.Function("Abbrev", - cel.Overload("Abbrev_interface{}", - +var stringsAbbrevWidthGen = cel.Function("abbrev", + cel.MemberOverload("stringsAbbrevWidthGen", []*cel.Type{ - cel.DynType, + cel.StringType, cel.IntType, }, cel.StringType, cel.FunctionBinding(func(args ...ref.Val) ref.Val { - var x StringFuncs - list, err := sliceToNative[interface{}](args[0].(ref.Val)) + list := []any{int(args[1].Value().(int64)), args[0].Value().(string)} + result, err := x.Abbrev(list...) if err != nil { return types.WrapErr(err) } + return types.String(result) + }), + ), +) +var stringsAbbrevWidthAndOffsetGen = cel.Function("abbrev", + cel.MemberOverload("stringsAbbrevWidthAndOffsetGen", + []*cel.Type{ + cel.StringType, cel.IntType, cel.IntType, + }, + cel.StringType, + cel.FunctionBinding(func(args ...ref.Val) ref.Val { + var x StringFuncs + list := []any{int(args[1].Value().(int64)), int(args[2].Value().(int64)), args[0].Value().(string)} result, err := x.Abbrev(list...) if err != nil { return types.WrapErr(err) } return types.String(result) - }), ), ) @@ -206,26 +171,19 @@ var stringsRepeatGen = cel.Function("repeat", ), ) -var stringsSortGen = cel.Function("Sort", - cel.Overload("Sort_interface{}", - +var stringsSortGen = cel.Function("sort", + cel.MemberOverload("Sort_interface{}", []*cel.Type{ - cel.DynType, + cel.StringType, }, - cel.DynType, - cel.FunctionBinding(func(args ...ref.Val) ref.Val { - list, err := sliceToNative[interface{}](args[0].(ref.Val)) - if err != nil { - return types.WrapErr(err) - } - - var x StringFuncs - result, err := x.Sort(list) - if err != nil { - return types.WrapErr(err) - } + cel.StringType, + cel.UnaryBinding(func(arg ref.Val) ref.Val { + slice := []byte(arg.Value().(string)) + sort.Slice(slice, func(i, j int) bool { + return slice[i] < slice[j] + }) - return types.DefaultTypeAdapter.NativeToValue(result) + return types.DefaultTypeAdapter.NativeToValue(string(slice)) }), ), ) @@ -371,17 +329,30 @@ var stringsTruncGen = cel.Function("trunc", var stringsIndentGen = cel.Function("indent", cel.MemberOverload("string_indent", []*cel.Type{ - cel.StringType, + cel.StringType, cel.StringType, }, cel.StringType, cel.FunctionBinding(func(args ...ref.Val) ref.Val { - var x StringFuncs - list, err := sliceToNative[interface{}](args[0].(ref.Val)) + list := []any{ args[1].Value().(string), args[0].Value().(string)} + result, err := x.Indent(list...) if err != nil { return types.WrapErr(err) } + return types.String(result) + }), + ), +) +var stringsIndentWithWidthGen = cel.Function("indent", + cel.MemberOverload("string_indent_with_width", + []*cel.Type{ + cel.StringType, cel.IntType, cel.StringType, + }, + cel.StringType, + cel.FunctionBinding(func(args ...ref.Val) ref.Val { + var x StringFuncs + list := []any{int(args[1].Value().(int64)), args[2].Value().(string), args[0].Value().(string)} result, err := x.Indent(list...) if err != nil { return types.WrapErr(err) @@ -522,27 +493,38 @@ var stringsKebabCaseGen = cel.Function("kebabCase", ), ) -var stringsWordWrapGen = cel.Function("WordWrap", - cel.Overload("WordWrap_interface{}", - +var stringsWordWrapGen = cel.Function("wordWrap", + cel.MemberOverload("WordWrap_interface{}", []*cel.Type{ - cel.DynType, + cel.StringType, cel.IntType, }, cel.StringType, cel.FunctionBinding(func(args ...ref.Val) ref.Val { - var x StringFuncs - list, err := sliceToNative[interface{}](args[0].(ref.Val)) + list := []any{args[1].Value().(int64), args[0].Value().(string)} + result, err := x.WordWrap(list...) if err != nil { return types.WrapErr(err) } + return types.String(result) + }), + ), +) +var stringsWordWrapSeqAndWidthGen = cel.Function("wordWrap", + cel.MemberOverload("stringsWordWrapSeqAndWidthGen", + []*cel.Type{ + cel.StringType, cel.IntType, cel.StringType, + }, + cel.StringType, + cel.FunctionBinding(func(args ...ref.Val) ref.Val { + var x StringFuncs + list := []any{int(args[1].Value().(int64)), args[2].Value().(string), args[0].Value().(string)} result, err := x.WordWrap(list...) if err != nil { return types.WrapErr(err) } return types.String(result) - }), ), ) diff --git a/kubernetes/cel_export.go b/kubernetes/cel_export.go index 69cb1428e..b12e4c272 100644 --- a/kubernetes/cel_export.go +++ b/kubernetes/cel_export.go @@ -7,11 +7,9 @@ func Library() []cel.EnvOption { Lists(), URLs(), Regex(), - k8sIsHealthy(), k8sGetHealth(), k8sGetStatus(), - k8sIsHealthy2(), - k8sHealth(), + k8sIsHealthy(), k8sCPUAsMillicores(), k8sMemoryAsBytes(), } diff --git a/kubernetes/health.go b/kubernetes/health.go index 77425bf65..6699c3efc 100644 --- a/kubernetes/health.go +++ b/kubernetes/health.go @@ -104,21 +104,8 @@ func GetHealth(in interface{}) HealthStatus { } } -func k8sHealth() cel.EnvOption { - return cel.Function("k8s.health", - cel.Overload("k8s.health_any", - []*cel.Type{cel.AnyType}, - cel.AnyType, - cel.UnaryBinding(func(obj ref.Val) ref.Val { - jsonObj, _ := conv.AnyToMapStringAny(GetHealth(obj.Value())) - return types.NewDynamicMap(types.DefaultTypeAdapter, jsonObj) - }), - ), - ) -} - func k8sGetHealth() cel.EnvOption { - return cel.Function("GetHealth", + return cel.Function("k8s.getHealth", cel.Overload("GetHealth_any", []*cel.Type{cel.AnyType}, cel.AnyType, @@ -131,7 +118,7 @@ func k8sGetHealth() cel.EnvOption { } func k8sGetStatus() cel.EnvOption { - return cel.Function("GetStatus", + return cel.Function("k8s.getStatus", cel.Overload("GetStatus", []*cel.Type{cel.AnyType}, cel.AnyType, @@ -143,19 +130,7 @@ func k8sGetStatus() cel.EnvOption { } func k8sIsHealthy() cel.EnvOption { - return cel.Function("k8s.is_healthy", - cel.Overload("k8s.is_healthy_any", - []*cel.Type{cel.AnyType}, - cel.StringType, - cel.UnaryBinding(func(obj ref.Val) ref.Val { - return types.Bool(GetHealth(obj.Value()).OK) - }), - ), - ) -} - -func k8sIsHealthy2() cel.EnvOption { - return cel.Function("IsHealthy", + return cel.Function("k8s.isHealthy", cel.Overload("IsHealthy_interface{}", []*cel.Type{cel.AnyType}, cel.StringType, diff --git a/tests/cel_test.go b/tests/cel_test.go index b344c2821..719c94e64 100644 --- a/tests/cel_test.go +++ b/tests/cel_test.go @@ -35,6 +35,7 @@ func runTests(t *testing.T, tests []Test) { out, err := gomplate.RunTemplate(tc.env, gomplate.Template{ Expression: tc.expression, }) + assert.ErrorIs(t, nil, err) assert.Equal(t, tc.out, out) }) @@ -75,14 +76,14 @@ func unstructure(o any) interface{} { func TestCelAws(t *testing.T) { runTests(t, []Test{ - {nil, "arnToMap('arn:aws:sns:eu-west-1:123:MMS-Topic').account", "123"}, + {nil, "aws.arnToMap('arn:aws:sns:eu-west-1:123:MMS-Topic').account", "123"}, {map[string]interface{}{ "x": []map[string]string{ {"Name": "hello", "Value": "world"}, {"Name": "John", "Value": "Doe"}, }, }, - "fromAWSMap(x).hello", "world"}, + "aws.fromAWSMap(x).hello", "world"}, }) } @@ -161,22 +162,18 @@ func TestCelJSON(t *testing.T) { {nil, `[{'name': 'John'}].toJSON()`, `[{"name":"John"}]`}, {nil, `dyn({'name': 'John'}).toJSON()`, `{"name":"John"}`}, {nil, `{'name': 'John'}.toJSON()`, `{"name":"John"}`}, - {nil, `toJSON({'name': 'John'})`, `{"name":"John"}`}, {nil, `1.toJSON()`, `1`}, + {map[string]interface{}{"i": person}, "i.toJSON().JSON().name", "Aditya"}, + {map[string]interface{}{"i": person}, `'["1", "2"]'.JSONArray()[0]`, "1"}, + {map[string]interface{}{"i": map[string]string{"name": "aditya"}}, `i.toJSON()`, `{"name":"aditya"}`}, + {nil, `'{"name": "John"}'.JSON().name`, `John`}, {nil, `'{"name": "Alice", "age": 30}'.JSON().name`, `Alice`}, {nil, `'[1, 2, 3, 4, 5]'.JSONArray()[0]`, `1`}, {map[string]interface{}{"i": person}, "jq('.Address.city_name', i)", "Kathmandu"}, - {map[string]interface{}{"i": person}, "toJSONPretty('\t', i)", "{\n\t\"Address\": {\n\t\t\"city_name\": \"Kathmandu\"\n\t},\n\t\"name\": \"Aditya\"\n}"}, - {map[string]interface{}{"i": person}, "toJSONPretty('\t', [\"Alice\", 30])", "[\n\t\"Alice\",\n\t30\n]"}, - {map[string]interface{}{"i": person}, "toJSONPretty('\t', {'name': 'aditya'})", - `{ - "name": "aditya" -}`}, - {map[string]interface{}{"i": person}, "JSON(toJSON(i)).name", "Aditya"}, - {map[string]interface{}{"i": person}, "JSON(i.toJSON()).name", "Aditya"}, - {map[string]interface{}{"i": person}, `JSONArray('["1", "2"]')[0]`, "1"}, - {map[string]interface{}{"i": map[string]string{"name": "aditya"}}, `toJSON(i)`, `{"name":"aditya"}`}, + {map[string]interface{}{"i": person}, "i.toJSONPretty('\t')", "{\n\t\"Address\": {\n\t\t\"city_name\": \"Kathmandu\"\n\t},\n\t\"name\": \"Aditya\"\n}"}, + {nil, "[\"Alice\", 30].toJSONPretty('\t')", "[\n\t\"Alice\",\n\t30\n]"}, + {nil, "{'name': 'aditya'}.toJSONPretty('\t')", "{\n\t\"name\": \"aditya\"\n}"}, }) } @@ -317,16 +314,17 @@ func TestCelRegex(t *testing.T) { func TestCelStrings(t *testing.T) { tests := []Test{ - {nil, "Abbrev([1, 5, 'KubernetesPod'])", "Ku..."}, - {nil, "Abbrev([6, 'KubernetesPod'])", "Kub..."}, - {nil, "Abbrev([5, 20, 'Now is the time for all good men'])", "...s the time for..."}, - + // Methods + {nil, "'KubernetesPod'.abbrev(1, 5)", "Ku..."}, + {nil, "'KubernetesPod'.abbrev(6)", "Kub..."}, + {nil, "'Now is the time for all good men'.abbrev(5, 20)", "...s the time for..."}, {nil, "'the quick brown fox'.camelCase()", "theQuickBrownFox"}, {nil, "'the quick brown fox'.charAt(2)", "e"}, {nil, "'the quick brown fox'.contains('brown')", "true"}, {nil, "'the quick brown fox'.endsWith('fox')", "true"}, - {map[string]interface{}{"size": 123456}, "humanSize(size)", "120.6K"}, - // {nil, "'the\nquick'.indent('a')", "true"}, // TODO: + {nil, "'the quick brown fox'.indent('\t\t\t')", "\t\t\tthe quick brown fox"}, + {nil, "'hello world'.indent('==')", "==hello world"}, + {nil, "'hello world'.indent(4, '-')", "----hello world"}, {nil, "'the quick brown fox'.indexOf('quick')", "4"}, {nil, "['hello', 'mellow'].join()", "hellomellow"}, {nil, "'hello mellow'.kebabCase()", "hello-mellow"}, @@ -344,15 +342,8 @@ func TestCelStrings(t *testing.T) { {nil, `"hello".size()`, `5`}, {nil, `"hello there".slug()`, `hello-there`}, {map[string]interface{}{"s": "hello world"}, "s.snakeCase()", "hello_world"}, - - // SemVer - {nil, "Semver('1.2.3').major", "1"}, - {map[string]interface{}{"v": "1.2.3-beta.1+c0ff33"}, "Semver(v).prerelease", "beta.1"}, - {map[string]interface{}{"old": "1.2.3", "new": "1.2.3"}, "SemverCompare(new, old)", "true"}, - {map[string]interface{}{"old": "1.2.3", "new": "1.2.4"}, "SemverCompare(new, old)", "false"}, - {map[string]interface{}{"s": "hello world"}, "s.shellQuote()", "'hello world'"}, - {nil, `Sort(["b", "a", "c"])`, `[a b c]`}, + {nil, `"hello".sort()`, `ehllo`}, {map[string]interface{}{"s": "hello world"}, "s.split(' ')", "[hello world]"}, {map[string]interface{}{"s": "hello world"}, "s.squote()", "'hello world'"}, {nil, `"hello".startsWith("he")`, "true"}, @@ -360,8 +351,18 @@ func TestCelStrings(t *testing.T) { {map[string]interface{}{"s": " hello world\t\t\n"}, "s.trim()", "hello world"}, {map[string]interface{}{"s": "hello world"}, "s.trimSuffix(' world')", "hello"}, {map[string]interface{}{"s": "hello world"}, "s.slug()", "hello-world"}, - {map[string]interface{}{"s": "testing this line from here"}, "WordWrap([4, s])", "testing\nthis\nline\nfrom\nhere"}, - {nil, `WordWrap([9, "Hello Beautiful World"])`, "Hello\nBeautiful\nWorld"}, + {map[string]interface{}{"s": "testing this line from here"}, "s.wordWrap(2)", "testing\nthis\nline\nfrom\nhere"}, + {map[string]interface{}{"s": "testing this line from here"}, "s.wordWrap(10)", "testing\nthis line\nfrom here"}, + {map[string]interface{}{"s": "Hello$World"}, "s.wordWrap(5)", "Hello$World"}, + {nil, `"Hello Beautiful World".wordWrap(16, '===')`, "Hello Beautiful===World"}, + {nil, `"Hello Beautiful World".wordWrap(25, '')`, "Hello Beautiful World"}, // no need to wrap + + // Functions + {nil, "HumanSize(123456)", "120.6K"}, + {nil, "Semver('1.2.3').major", "1"}, + {map[string]interface{}{"v": "1.2.3-beta.1+c0ff33"}, "Semver(v).prerelease", "beta.1"}, + {map[string]interface{}{"old": "1.2.3", "new": "1.2.3"}, "SemverCompare(new, old)", "true"}, + {map[string]interface{}{"old": "1.2.3", "new": "1.2.4"}, "SemverCompare(new, old)", "false"}, // Basic {map[string]interface{}{"hello": "world"}, "hello", "world"}, @@ -381,7 +382,6 @@ func TestCelDates(t *testing.T) { // Durations {map[string]interface{}{"age": 75 * time.Second}, "age", "1m15s"}, {nil, `HumanDuration(duration("1008h"))`, "6w0d0h"}, - {nil, `humanDuration(duration("1008h"))`, "6w0d0h"}, {nil, `Duration("7d").getHours()`, "168"}, {nil, `duration("1h") > duration("2h")`, "false"}, {map[string]interface{}{"t": "2020-01-01T00:00:00Z"}, `Age(t) > duration('1h')`, "true"}, @@ -399,21 +399,6 @@ func TestCelDates(t *testing.T) { runTests(t, tests) } -func TestCelMultipleReturns(t *testing.T) { - testData := []struct { - Input string - Outputs []any - }{ - // {Input: `base64.Encode("flanksource")`, Outputs: []any{"Zmxhbmtzb3VyY2U=", nil}}, - // {Input: `base64.Decode("Zmxhbmtzb3VyY2U=")`, Outputs: []any{"flanksource", nil}}, - {Input: `JSONArray("[\"name\",\"flanksource\"]")`, Outputs: []any{"name", "flanksource"}}, - } - - for i, td := range testData { - executeTemplate(t, i, td.Input, td.Outputs, nil) - } -} - func TestCelVariadic(t *testing.T) { testData := []struct { Input string @@ -443,9 +428,9 @@ func TestCelSliceReturn(t *testing.T) { func TestCelK8sResources(t *testing.T) { runTests(t, []Test{ - {map[string]interface{}{"healthySvc": kubernetes.GetUnstructuredMap(kubernetes.TestHealthy)}, "IsHealthy(healthySvc)", "true"}, - {map[string]interface{}{"healthySvc": kubernetes.GetUnstructuredMap(kubernetes.TestLuaStatus)}, "GetStatus(healthySvc)", "Degraded: found less than two generators, Merge requires two or more"}, - {map[string]interface{}{"healthySvc": kubernetes.GetUnstructuredMap(kubernetes.TestHealthy)}, "GetHealth(healthySvc).status", "Healthy"}, + {map[string]interface{}{"healthySvc": kubernetes.GetUnstructuredMap(kubernetes.TestHealthy)}, "k8s.isHealthy(healthySvc)", "true"}, + {map[string]interface{}{"healthySvc": kubernetes.GetUnstructuredMap(kubernetes.TestLuaStatus)}, "k8s.getStatus(healthySvc)", "Degraded: found less than two generators, Merge requires two or more"}, + {map[string]interface{}{"healthySvc": kubernetes.GetUnstructuredMap(kubernetes.TestHealthy)}, "k8s.getHealth(healthySvc).status", "Healthy"}, }) } @@ -455,12 +440,12 @@ func TestCelK8s(t *testing.T) { Output any }{ - {Input: `k8s.is_healthy(healthy_obj)`, Output: true}, - {Input: `k8s.is_healthy(unhealthy_obj)`, Output: false}, - {Input: `k8s.health(healthy_obj).status`, Output: "Healthy"}, - {Input: `k8s.health(unhealthy_obj).message`, Output: "Back-off 40s restarting failed container=main pod=my-pod_argocd(63674389-f613-11e8-a057-fe5f49266390)"}, - {Input: `k8s.health(unhealthy_obj).ok`, Output: false}, - {Input: `k8s.health(healthy_obj).message`, Output: ""}, + {Input: `k8s.isHealthy(healthy_obj)`, Output: true}, + {Input: `k8s.isHealthy(unhealthy_obj)`, Output: false}, + {Input: `k8s.getHealth(healthy_obj).status`, Output: "Healthy"}, + {Input: `k8s.getHealth(unhealthy_obj).message`, Output: "Back-off 40s restarting failed container=main pod=my-pod_argocd(63674389-f613-11e8-a057-fe5f49266390)"}, + {Input: `k8s.getHealth(unhealthy_obj).ok`, Output: false}, + {Input: `k8s.getHealth(healthy_obj).message`, Output: ""}, } environment := map[string]any{