From 90788d6667d0616ca6ef0c0afa81302ccc9f7dd7 Mon Sep 17 00:00:00 2001 From: Norwin Schnyder Date: Fri, 12 Jun 2026 14:39:37 +0200 Subject: [PATCH] fix(health): treat nil return from Lua health status script as n/a instead of unknown Signed-off-by: Norwin Schnyder --- util/lua/health_test.go | 6 +++--- util/lua/lua.go | 2 +- util/lua/lua_test.go | 6 ++---- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/util/lua/health_test.go b/util/lua/health_test.go index 064e852857407..70de4065a4b2a 100644 --- a/util/lua/health_test.go +++ b/util/lua/health_test.go @@ -18,8 +18,8 @@ type TestStructure struct { } type IndividualTest struct { - InputPath string `yaml:"inputPath"` - HealthStatus health.HealthStatus `yaml:"healthStatus"` + InputPath string `yaml:"inputPath"` + HealthStatus *health.HealthStatus `yaml:"healthStatus"` } func getObj(t *testing.T, path string) *unstructured.Unstructured { @@ -56,7 +56,7 @@ func TestLuaHealthScript(t *testing.T) { require.NoError(t, err) result, err := vm.ExecuteHealthLua(obj, script) require.NoError(t, err) - assert.Equal(t, &test.HealthStatus, result) + assert.Equal(t, test.HealthStatus, result) }) } return nil diff --git a/util/lua/lua.go b/util/lua/lua.go index 92dbc83005cd2..25751a342eadc 100644 --- a/util/lua/lua.go +++ b/util/lua/lua.go @@ -159,7 +159,7 @@ func (vm VM) ExecuteHealthLua(obj *unstructured.Unstructured, script string) (*h return healthStatus, nil } else if returnValue.Type() == lua.LTNil { - return &health.HealthStatus{}, nil + return nil, nil } return nil, fmt.Errorf(incorrectReturnType, "table", returnValue.Type().String()) } diff --git a/util/lua/lua_test.go b/util/lua/lua_test.go index fdc3e36921112..da7f761821eb2 100644 --- a/util/lua/lua_test.go +++ b/util/lua/lua_test.go @@ -154,8 +154,7 @@ func TestNoReturnHealthStatusStatus(t *testing.T) { vm := VM{} status, err := vm.ExecuteHealthLua(testObj, validReturnNothingHealthStatusStatus) require.NoError(t, err) - expectedStatus := &health.HealthStatus{} - assert.Equal(t, expectedStatus, status) + assert.Nil(t, status) } const validNilHealthStatusStatus = `local healthStatus = {} @@ -168,8 +167,7 @@ func TestNilHealthStatusStatus(t *testing.T) { vm := VM{} status, err := vm.ExecuteHealthLua(testObj, validNilHealthStatusStatus) require.NoError(t, err) - expectedStatus := &health.HealthStatus{} - assert.Equal(t, expectedStatus, status) + assert.Nil(t, status) } const validEmptyArrayHealthStatusStatus = `local healthStatus = {}