diff --git a/docs/contributor/04-10-testing-strategy.md b/docs/contributor/04-10-testing-strategy.md index daa26a8c6..5b5c6fd35 100644 --- a/docs/contributor/04-10-testing-strategy.md +++ b/docs/contributor/04-10-testing-strategy.md @@ -16,7 +16,7 @@ Each pull request to the repository triggers the following CI/CD jobs that verif - `markdown / documentation-link-check` - Checks if there are no broken links in `.md` files. For the configuration, see the [mlc.config.json](https://github.com/kyma-project/serverless/blob/main/.mlc.config.json) and the [markdown.yaml](https://github.com/kyma-project/serverless/blob/main/.github/workflows/markdown.yaml) files. - `integration tests (push) / operator-integration-test` - Runs the create/update/delete Serverless integration tests in k3d cluster. For the configuration, see the [integration-tests-push.yaml](https://github.com/kyma-project/serverless/blob/main/.github/workflows/integration-tests-push.yaml) file. -- `integration tests (push) / serverless-integration-test` - Runs the basic functionality integration and the `tracing`, `api-gateway`, and `cloud-event` contract compatibility integration test suite for Serverless in a k3d cluster. For the configuration, see the [integration-tests-push.yaml](https://github.com/kyma-project/serverless/blob/main/.github/workflows/integration-tests-push.yaml) file. +- `integration tests (push) / serverless-integration-test` - Runs the basic functionality integration and the `tracing`, `api-gateway`, `cloud-event` and `hana-client` contract compatibility integration test suite for Serverless in a k3d cluster. For the configuration, see the [integration-tests-push.yaml](https://github.com/kyma-project/serverless/blob/main/.github/workflows/integration-tests-push.yaml) file. - `integration tests (push) / git-auth-integration-test` - Runs the `GitHub` and `Azure DevOps` API and authentication integration test suite for Serverless. For the configuration, see the [integration-tests-push.yaml](https://github.com/kyma-project/serverless/blob/main/.github/workflows/integration-tests-push.yaml) file. - `integration tests (push) / gardener-integration-test` - Checks the installation of the Serverless module in the Gardener shoot cluster and runs basic integration tests of Serverless. For the configuration, see the [integration-tests-push.yaml](https://github.com/kyma-project/serverless/blob/main/.github/workflows/integration-tests-push.yaml) file. - `upgrade tests / operator-upgrade-test` - Runs the upgrade integration test suite and verifies if the latest release can be successfully upgraded to the new (`main`) revision. For the configuration, see the [upgrade-tests.yaml](https://github.com/kyma-project/serverless/blob/main/.github/workflows/upgrade-tests.yaml) file. diff --git a/tests/serverless/cmd/main.go b/tests/serverless/cmd/main.go index 011256c71..d30553b97 100644 --- a/tests/serverless/cmd/main.go +++ b/tests/serverless/cmd/main.go @@ -69,6 +69,7 @@ var availableScenarios = map[string][]testSuite{ {name: "tracing", test: testsuite.FunctionTracingTest}, {name: "api-gateway", test: testsuite.FunctionAPIGatewayTest}, {name: "cloud-events", test: testsuite.FunctionCloudEventsTest}, + {name: "hana-client", test: testsuite.HanaClientTest}, }, } diff --git a/tests/serverless/internal/resources/runtimes/nodejs.go b/tests/serverless/internal/resources/runtimes/nodejs.go index 817ce9d71..d4ce2d593 100644 --- a/tests/serverless/internal/resources/runtimes/nodejs.go +++ b/tests/serverless/internal/resources/runtimes/nodejs.go @@ -255,3 +255,47 @@ async function handleGet(req) { }, } } + +func NodeJSFunctionUsingHanaClient(rtm serverlessv1alpha2.Runtime) serverlessv1alpha2.FunctionSpec { + src := `var hana = require('@sap/hana-client'); + + module.exports = { + main: async function (event, context) { + //this is fake + var conn_params = { + serverNode: "62e223c1-7de9-4c8a-bab6-411f70fdf925.hana.canary-eu10.hanacloud.ondemand.com:443", + uid: "DBADMIN", + pwd: "foo", + }; + + var conn = hana.createConnection(); + + try { + await conn.connect(conn_params) + let result = await conn.exec('SELECT 1 AS "One" FROM DUMMY') + return result; + } catch(err) { + // it is expected to leave here + return err; + } + } + } +` + return serverlessv1alpha2.FunctionSpec{ + Runtime: rtm, + Source: serverlessv1alpha2.Source{ + Inline: &serverlessv1alpha2.InlineSource{ + Source: src, + Dependencies: `{"name": "hana-client","version": "0.0.1","dependencies": { "@sap/hana-client": "^2.21.26"} }`, + }, + }, + ResourceConfiguration: &serverlessv1alpha2.ResourceConfiguration{ + Function: &serverlessv1alpha2.ResourceRequirements{ + Profile: "M", + }, + Build: &serverlessv1alpha2.ResourceRequirements{ + Profile: "fast", + }, + }, + } +} diff --git a/tests/serverless/internal/testsuite/hana_client.go b/tests/serverless/internal/testsuite/hana_client.go new file mode 100644 index 000000000..ed0bea09a --- /dev/null +++ b/tests/serverless/internal/testsuite/hana_client.go @@ -0,0 +1,73 @@ +package testsuite + +import ( + "fmt" + "time" + + "github.com/kyma-project/serverless/tests/serverless/internal" + "github.com/kyma-project/serverless/tests/serverless/internal/assertion" + "github.com/kyma-project/serverless/tests/serverless/internal/executor" + "github.com/kyma-project/serverless/tests/serverless/internal/resources/function" + "github.com/kyma-project/serverless/tests/serverless/internal/resources/namespace" + "github.com/kyma-project/serverless/tests/serverless/internal/resources/runtimes" + "github.com/kyma-project/serverless/tests/serverless/internal/utils" + "github.com/pkg/errors" + + serverlessv1alpha2 "github.com/kyma-project/serverless/components/serverless/pkg/apis/serverless/v1alpha2" + "github.com/sirupsen/logrus" + "k8s.io/client-go/dynamic" + typedcorev1 "k8s.io/client-go/kubernetes/typed/core/v1" + "k8s.io/client-go/rest" +) + +func HanaClientTest(restConfig *rest.Config, cfg internal.Config, logf *logrus.Entry) (executor.Step, error) { + now := time.Now() + cfg.Namespace = fmt.Sprintf("%s-%02dh%02dm%02ds", "test-hana-client", now.Hour(), now.Minute(), now.Second()) + + dynamicCli, err := dynamic.NewForConfig(restConfig) + if err != nil { + return nil, errors.Wrapf(err, "while creating dynamic client") + } + + coreCli, err := typedcorev1.NewForConfig(restConfig) + if err != nil { + return nil, errors.Wrap(err, "while creating k8s CoreV1Client") + } + + nodejs18Logger := logf.WithField(runtimeKey, "nodejs18") + nodejs20Logger := logf.WithField(runtimeKey, "nodejs20") + + genericContainer := utils.Container{ + DynamicCli: dynamicCli, + Namespace: cfg.Namespace, + WaitTimeout: cfg.WaitTimeout, + Verbose: cfg.Verbose, + Log: logf, + } + + nodejs18Fn := function.NewFunction("hana-nodejs18", genericContainer.Namespace, cfg.KubectlProxyEnabled, genericContainer.WithLogger(nodejs18Logger)) + + nodejs20Fn := function.NewFunction("hana-nodejs20", genericContainer.Namespace, cfg.KubectlProxyEnabled, genericContainer.WithLogger(nodejs20Logger)) + + logf.Infof("Testing function in namespace: %s", cfg.Namespace) + + poll := utils.Poller{ + MaxPollingTime: cfg.MaxPollingTime, + InsecureSkipVerify: cfg.InsecureSkipVerify, + DataKey: internal.TestDataKey, + } + + return executor.NewSerialTestRunner(logf, "Runtime test", + namespace.NewNamespaceStep(logf, fmt.Sprintf("Create %s namespace", genericContainer.Namespace), genericContainer.Namespace, coreCli), + 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\"}"), + ), + 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\"}"), + ), + ), + ), nil +}