From 7704b838cf02742399b9ee4e76b89cbc82dadefd Mon Sep 17 00:00:00 2001 From: "Kwiatosz, Krzysztof" Date: Fri, 19 Jul 2024 10:48:36 +0200 Subject: [PATCH 1/2] Hana client contract test hardening --- tests/serverless/internal/resources/runtimes/nodejs.go | 9 ++++++--- tests/serverless/internal/testsuite/hana_client.go | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/serverless/internal/resources/runtimes/nodejs.go b/tests/serverless/internal/resources/runtimes/nodejs.go index d4ce2d593..607c47644 100644 --- a/tests/serverless/internal/resources/runtimes/nodejs.go +++ b/tests/serverless/internal/resources/runtimes/nodejs.go @@ -275,8 +275,11 @@ func NodeJSFunctionUsingHanaClient(rtm serverlessv1alpha2.Runtime) serverlessv1a let result = await conn.exec('SELECT 1 AS "One" FROM DUMMY') return result; } catch(err) { - // it is expected to leave here - return err; + // it is expected to leave here. The purpose is to check if hana client returns a known error instead of crashing the whole container with SIGSEGV + if(err.sqlState && err.sqlState.startsWith("HY")){ + return "OK"; + } + return "NOK"; } } } @@ -286,7 +289,7 @@ func NodeJSFunctionUsingHanaClient(rtm serverlessv1alpha2.Runtime) serverlessv1a Source: serverlessv1alpha2.Source{ Inline: &serverlessv1alpha2.InlineSource{ Source: src, - Dependencies: `{"name": "hana-client","version": "0.0.1","dependencies": { "@sap/hana-client": "^2.21.26"} }`, + Dependencies: `{"name": "hana-client","version": "0.0.1","dependencies": { "@sap/hana-client": "latest"} }`, }, }, ResourceConfiguration: &serverlessv1alpha2.ResourceConfiguration{ diff --git a/tests/serverless/internal/testsuite/hana_client.go b/tests/serverless/internal/testsuite/hana_client.go index ed0bea09a..affc286cd 100644 --- a/tests/serverless/internal/testsuite/hana_client.go +++ b/tests/serverless/internal/testsuite/hana_client.go @@ -62,11 +62,11 @@ func HanaClientTest(restConfig *rest.Config, cfg internal.Config, logf *logrus.E executor.NewParallelRunner(logf, "Fn tests", executor.NewSerialTestRunner(nodejs18Logger, "NodeJS18 test", function.CreateFunction(nodejs18Logger, nodejs18Fn, "Create NodeJS18 Function", runtimes.NodeJSFunctionUsingHanaClient(serverlessv1alpha2.NodeJs18)), - assertion.NewHTTPCheck(nodejs18Logger, "Testing hana-client in nodejs18 function", nodejs18Fn.FunctionURL, poll, "{\"code\":10,\"sqlState\":\"28000\"}"), + assertion.NewHTTPCheck(nodejs18Logger, "Testing hana-client in nodejs18 function", nodejs18Fn.FunctionURL, poll, "OK"), ), executor.NewSerialTestRunner(nodejs20Logger, "NodeJS20 test", function.CreateFunction(nodejs20Logger, nodejs20Fn, "Create NodeJS20 Function", runtimes.NodeJSFunctionUsingHanaClient(serverlessv1alpha2.NodeJs20)), - assertion.NewHTTPCheck(nodejs18Logger, "Testing hana-client in nodejs20 function", nodejs20Fn.FunctionURL, poll, "{\"code\":10,\"sqlState\":\"28000\"}"), + assertion.NewHTTPCheck(nodejs18Logger, "Testing hana-client in nodejs20 function", nodejs20Fn.FunctionURL, poll, "OK"), ), ), ), nil From 6841f7d6ffa0fab1a3318d6d6beea4a5cb03d86c Mon Sep 17 00:00:00 2001 From: "Kwiatosz, Krzysztof" Date: Fri, 19 Jul 2024 15:24:31 +0200 Subject: [PATCH 2/2] Hana client contract test hardening - code review --- tests/serverless/internal/resources/runtimes/nodejs.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/serverless/internal/resources/runtimes/nodejs.go b/tests/serverless/internal/resources/runtimes/nodejs.go index 607c47644..f1315a133 100644 --- a/tests/serverless/internal/resources/runtimes/nodejs.go +++ b/tests/serverless/internal/resources/runtimes/nodejs.go @@ -276,7 +276,8 @@ func NodeJSFunctionUsingHanaClient(rtm serverlessv1alpha2.Runtime) serverlessv1a return result; } catch(err) { // it is expected to leave here. The purpose is to check if hana client returns a known error instead of crashing the whole container with SIGSEGV - if(err.sqlState && err.sqlState.startsWith("HY")){ + // HY000 means general error - https://stackoverflow.com/questions/7472884/what-is-sql-error-5-sqlstate-hy000-and-what-can-cause-this-error + if(err.sqlState && err.sqlState=="HY000"){ return "OK"; } return "NOK";