Skip to content

Commit

Permalink
Hana client contract test hardening (#1074)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwiatekus authored Jul 22, 2024
1 parent 389a03a commit 11adaa2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions tests/serverless/internal/resources/runtimes/nodejs.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,12 @@ 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
// 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";
}
}
}
Expand All @@ -286,7 +290,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{
Expand Down
4 changes: 2 additions & 2 deletions tests/serverless/internal/testsuite/hana_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 11adaa2

Please sign in to comment.